我有一个带有for循环的函数:
func example() {
// create tasks
for link in links {
let currIndex = links.indexOf(link)
if let im = story_cache?.objectForKey(link) as? UIImage {
if ((currIndex != nil) && (currIndex < content.count)) {
if (content[currIndex!].resource_type == "image") {
content[currIndex!].image = im
return
}
}
} else {
if ((currIndex != nil) && (currIndex < content.count)) {
if (content[currIndex!].resource_type == "video") {
let paths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let documentsDirectory : NSString = paths[0]
let appFile = documentsDirectory.stringByAppendingPathComponent(content[currIndex!].id! + ".mov")
let …
Run Code Online (Sandbox Code Playgroud) 我有一个自定义类定义如下:
class DisplayMessage : NSObject {
var id : String?
var partner_image : UIImage?
var partner_name : String?
var last_message : String?
var date : NSDate?
}
Run Code Online (Sandbox Code Playgroud)
现在我有一个数组myChats = [DisplayMessage]?
.该id
字段对于每个DisplayMessage
对象都是唯一的.我需要检查我的数组并从中删除所有重复项,基本上确保数组中的所有对象都具有唯一性id
.我已经看到了一些使用的解决方案NSMutableArray
,Equatable
但是我不确定如何在这里进行调整; 我也知道,Array(Set(myChats))
这似乎不适用于自定义对象数组.
我有一个存储在我的在线服务器数据库中的日期GMT
.我使用以下代码加载日期并将其转换为用户的时区:
if let messagedate = oneitem["timestamp"] as? String {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let date = dateFormatter.dateFromString(messagedate)
let source_timezone = NSTimeZone(abbreviation: "GMT")
let local_timezone = NSTimeZone.systemTimeZone()
let source_EDT_offset = source_timezone?.secondsFromGMTForDate(date!)
let destination_EDT_offset = local_timezone.secondsFromGMTForDate(date!)
let time_interval : NSTimeInterval = Double(destination_EDT_offset - source_EDT_offset!)
let final_date = NSDate(timeInterval: time_interval, sinceDate: date!)
curr_item.date = final_date
}
Run Code Online (Sandbox Code Playgroud)
现在我需要将日期转换回来GMT
以便将它传递给服务器,但是我不知道如何将其转换回来GMT
.
我有一个CollectionView
向用户显示图像.我在后台下载这些,当下载完成后,我调用以下func来更新collectionViewCell
并显示图像.
func handlePhotoDownloadCompletion(notification : NSNotification) {
let userInfo:Dictionary<String,String!> = notification.userInfo as! Dictionary<String,String!>
let id = userInfo["id"]
let index = users_cities.indexOf({$0.id == id})
if index != nil {
let indexPath = NSIndexPath(forRow: index!, inSection: 0)
let cell = followedCollectionView.cellForItemAtIndexPath(indexPath) as! FeaturedCitiesCollectionViewCell
if (users_cities[index!].image != nil) {
cell.backgroundImageView.image = users_cities[index!].image!
}
}
}
Run Code Online (Sandbox Code Playgroud)
如果单元格当前在屏幕上可见,则此方法很有效,但如果不是
fatal error: unexpectedly found nil while unwrapping an Optional value
,则在以下行中出现错误:
let cell = followedCollectionView.cellForItemAtIndexPath(indexPath) as! FeaturedCitiesCollectionViewCell
Run Code Online (Sandbox Code Playgroud)
现在,如果collectionViewCell尚未可见,则甚至不需要调用此函数,因为在这种情况下,cellForItemAtIndexPath
无论如何都将在方法中设置图像.
因此我的问题是,如何更改此函数以检查我们正在处理的单元格当前是否可见.我知道collectionView.visibleCells()
但是,我不知道如何在这里应用它.
我正在尝试获取用户的位置.为此,我在info.plist中设置了以下属性:
我还在viewDidLoad方法中添加了以下代码以及下面的函数.问题是locationManager(manager, didUpdate....)
函数永远不会被调用,即使我已经删除并再次安装了应用程序,我也永远不会被提示访问位置.我在iPad上测试,而不是在模拟器上测试.didFailWithError函数永远不会被调用.
self.locationManager.delegate = self
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
self.locationManager.requestWhenInUseAuthorization()
self.locationManager.startUpdatingLocation()
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
print("UPDATING")
let locValue:CLLocationCoordinate2D = manager.location!.coordinate
let latitude = locValue.latitude
let longitude = locValue.longitude
latitudeText = "\(latitude)"
longitudeText = "\(longitude)"
if let a = latitudeText, b = longitudeText {
print(a)
print(b)
self.locationManager.stopUpdatingLocation()
if (userAlreadyExist()) {
dispatch_async(dispatch_get_main_queue(), {
//self.performSegueWithIdentifier("segueWhenLoggedIn", sender: self)
self.performSegueWithIdentifier("showCamera", sender: self)
// self.performSegueWithIdentifier("showTabBarController", sender: self)
})
}
else {
dispatch_async(dispatch_get_main_queue(), {
self.performSegueWithIdentifier("segueWhenLoggedOut", sender: self)
})
}
}
}
func …
Run Code Online (Sandbox Code Playgroud) 什么是目前最小的SDK recyclerview
.我已经看过一些关于这个的帖子,但它们都来自2014年,所以我正在寻找一些新的信息.另外,我的应用程序在很大程度上依赖于listviews
和asynctasks
,我想切换到recyclerview
添加一些动画等我最小的SDK是11的应用程序,我不知道这样做是否有可能还是会导致兼容性问题.此外,从listview转换到recyclerview的过程是否耗时?
我有一个ImageView
充满我的整体Activity
.我需要能够检测到4个触摸事件:
目前我能够使用以下代码检测前两个:
imageView.setOnTouchListener(new View.OnTouchListener() {
private Timer timerr = new Timer();
private long LONG_PRESS_TIMEOUT = 400; // TODO: your timeout here
private boolean wasLong = false;
@Override
public boolean onTouch(View v, MotionEvent event) {
Log.d(getClass().getName(), "touch event: " + event.toString());
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// HOLD DETECTED
timerr.schedule(new TimerTask() {
@Override
public void run() {
SlideShow.this.runOnUiThread(new Runnable() {
@Override
public void run() {
}, LONG_PRESS_TIMEOUT);
return true;
}
if (event.getAction() == …
Run Code Online (Sandbox Code Playgroud) 我在后台使用全屏ImageView进行全屏活动.我有一个EditText放在屏幕中间使用gravity:center
.当键盘打开时,我想让EditText向上移动,如下图所示,这样整个EditText始终可见.我试图使用 android:windowSoftInputMode="stateVisible|adjustResize"
但问题是我的背景图像也调整了大小,这是不可取的.此外,由于重力设置为中心,因此EditText与键盘之间存在间隙,因此它仍处于中心位置.我尝试过使用scrollView但是我不知道如何获得键盘结束的位置,以便我可以将EditText移动到该位置.我也尝试过adjustPan
这没有效果,因为EditText 200dp
处于高度并且重力设置为居中,所以用户总是在仍然可见的EditText中间开始输入.
XML
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:id="@+id/picturedisplay"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_gravity="center"
android:layout_height="200dp"
android:weightSum="100"
android:visibility="gone"
android:id="@+id/pic_layout"
android:orientation="vertical"
android:background="#9945D199"
>
<EditText
android:layout_width="fill_parent"
android:layout_height="0dp"
android:hint="Enter text here..."
android:textColor="#FFFFFF"
android:maxLength="250"
android:gravity="center"
android:imeOptions="flagNoExtractUi"
android:id="@+id/pic_textbox"
android:layout_weight="90"/>
<TextView
android:layout_width="40dp"
android:layout_height="0px"
android:text="200"
android:textColor="#FFFFFF"
android:textStyle="bold"
android:gravity="center_horizontal"
android:layout_weight="10"
android:id="@+id/char_rem_view"
android:layout_gravity="end"/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imgClose"
android:layout_gravity="right|bottom"
android:text="Flip Cam"
android:padding="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/snap"
android:text="Capture"
android:layout_gravity="center|bottom"
android:padding="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Flash"
android:visibility="visible"
android:id="@+id/imgOpen" …
Run Code Online (Sandbox Code Playgroud) 是否可以禁用 Stripe webhooks 的重试?我正在阅读本文档,但找不到有关该主题的任何内容:https ://stripe.com/docs/webhooks/best-practices
如果他们之前已经这样做并且失败了,我不希望他们对我的端点执行 ping 操作,因为交易仅在进行时有效,而不是 3 小时后有效。
I am attempting to carry out liveness analysis and in order to do so I need to obtain the def
and use
sets for all of my nodes, where they are defined as follows:
def[n] = set of all variables defined at node n
use[n] = set of all variables used at node n
So for example in the line:
a = b + c
def[n] = {a}
use[n] = {b,c}
Run Code Online (Sandbox Code Playgroud)
How can I do this?