草庐IT

completion_func

全部标签

ios - 字符串文字作为 println 中 func 的参数?

在println语句中是否可以使用字符串文字作为函数的参数。funcgreetings(name:String)->String{return"Greetings\(name)!"}我想做的是:(我尝试转义Earthling周围的引号。)println("OUTPUT:\(greetings("Earthling"))")您也可以这样做:letname="Earthling"println("OUTPUT:\(greetings(name))")这也行:println(greetings("Earthling"))我尝试在第一个示例中转义引号,但没有成功,它不是非常重要,因为它只是一个

ios - swift 警告 : Application delegate received call to -application:performFetchWithCompletionHandler: but the completion handler was never called

我在下面的模拟器中调用这个函数来模拟后台获取。然后我在日志中收到这个警告:SwiftWarning:Applicationdelegatereceivedcallto-application:performFetchWithCompletionHandler:butthecompletionhandlerwasnevercalled.我看到其他StackIverflow回答说我只需要添加completionhandler()。我试过了,它说我需要添加一个参数,这就是我迷路的地方。funcapplication(_application:UIApplication,performFetc

ios - UIView.animateWithDuration :animations:completion: gets canceled in XCTest

我正在尝试对UIView上的扩展进行单元测试,它调用animateWithDuration:animations:completion:。不幸的是,测试用例中的所有动画都立即取消,因此完成block的isFinished参数始终为false。有没有人知道如何让动画在测试用例中工作?这是我的Playground代码:importUIKitimportXCTestextensionUIView{funcfadeOut(duration:TimeInterval,completion:((Bool)->Void)?){UIView.animate(withDuration:duration,

ios - Swift 中的 "func observeValueForKeyPath(keyPath : NSString, object : AnyObject, change : NSDictionary, context : Void)"问题

我已经为这样的AVPlayer添加了一个观察者self.audioPlayer.addObserver(self,forKeyPath:"currentItem.status",options:[NSKeyValueObservingOptions.New,NSKeyValueObservingOptions.Initial],context:nil)然后打电话funcobserveValueForKeyPath(keyPath:NSString,object:AnyObject,change:NSDictionary,context:Void){ifobjectas!AVPlayer

Swift - class 和 func 关键字

以这种方式定义函数究竟意味着什么:classFoo{privateclassfuncbar(){//dosomethingcool}}换句话说,第二个class关键字的目的是什么?使用Swift2.1。 最佳答案 class和static方法是通过类型调用的,而不是在实例上调用的。letx=NSString.pathWithComponents(["/","usr","local","bin","brew"])任何类型都可以有static方法,class方法只能出现在类中。子类可以覆盖class方法,但不能覆盖static方法。cl

swift - Swift playground 中 "S"中出现的 "T"、 "Pr"和 "auto completion box"图标是什么意思?

这个问题在这里已经有了答案:Xcodeintellisensemeaningoflettersincoloredboxeslikef,T,C,M,P,C,K,#etc(2个答案)关闭7年前。问题Swiftplayground中“自动完成框”中出现的“S”、“T”、“Pr”图标是什么意思?还有其他种类吗?谢谢!答案(用于搜索引擎索引)C:ClassesPr:Protocolsf:FunctionsS:StructsU:UnionsE:EnumsT:TypesV:Globals

ios - HealthKit - 请求授权(toShare :read:completion:) always succeeds

我正在使用Xcode8beta6,我正在请求访问健康应用程序。当完成处理程序返回时,请求授权的方法requestAuthorization(toShare:read:completion:)总是产生一个true-success在我的代码中以下。即使我拒绝了模拟器中的所有内容,我也会得到一个true。这是我处理授权的代码。是我的代码有问题还是Xcode错误?importFoundationimportHealthKitclassHealthManager{privatelethealthStore=HKHealthStore()classvarsharedInstance:HealthM

ios - func tableView(_ tableView : UITableView, canEditRowAt indexPath: IndexPath) 几乎符合可选要求

我有一个像这样的UIViewController:classViewController{overridefuncviewDidLoad(){super.viewDidLoad()self.tableView.dataSource=selfself.tableView.delegate=self}}extensionViewController:UITableViewDataSource{//datasourcemethods...}extensionViewController:UITableViewDelegate{functableView(_tableView:UITableV

ios - 当 func 中的归档对象编码时(使用 aCoder : NSCoder) method crashed with swift enum in real revice

在我的singleton类中,我有一个swift枚举:importUIKitenumUserType{caseterant//casenormalUser//casenormalUserFinancialer//}@objc(UserStaticSwift)classUserStaticSwift:NSObject,NSCoding{报告的错误:使用控制台日志:libc++abi.dylib:terminatingwithuncaughtexceptionoftypeNSException在编码中:funcencode(withaCoder:NSCoder){aCoder.encode

java - Android Studio : failed to complete gradle execution, 原因为空

当我尝试运行Android模拟器时,我收到以下错误屏幕。当我导出apk时也会发生同样的情况。当我转到将保存apk的目录时,apk文件不存在。谢谢你,克里斯托夫 最佳答案 我有同样的问题,这个问题将通过执行以下步骤来解决。前往File->Setting->Gradle->GradleVmOption适用于AndroidStudio1.2File->Setting->Build,Deployment&Execution->BuildTools->Gradle->GradleVmOption,现在将这个值-Xmx256m放入框中,然后点击