草庐IT

block_identifier

全部标签

objective-c - 当我不需要使用完成 block 时,如何在 swift 中声明 NULL/Void?

这是objective-c中的代码:[selfpresentViewController:logInViewControlleranimated:YEScompletion:NULL];到目前为止,我的代码在swift中:self.presentViewController(logInViewController,animated:true,completion:)认为它会像输入“Void”一样简单。不幸的是,还有更多内容。 最佳答案 Apple的预发布文档说:funcpresentViewController(_viewContr

Identifier ‘‘ has already been declared,变量重定义/重新声明/重复声明,chrome devtool console中的特殊的行为

console,一次性输入进去varxxxx=2;varxxxx=3;可以letyyyy=2;letyyyy=3;UncaughtSyntaxError:Identifier'yyyy'hasalreadybeendeclared分两次输入console,可以varmmmm=2;letmmmm=3;UncaughtSyntaxError:Identifier'mmmm'hasalreadybeendeclared分两次输入console,UncaughtSyntaxErrorlettttt=2;vartttt=3;UncaughtSyntaxError:Identifier'tttt'hasa

swift - 在 swift3 中使用方法而不是 block 来初始化惰性变量

在swift3文档中。推荐通过以下两种方式使用lazy:1。直接初始化`lazyvarsomeViews:UILabel=UILabel()`2。用block初始化lazyvaroverlayView:UILabel={[unownedself]inletoverlayView=UILabel()overlayView.backgroundColor=self.backgroundColor.withAlphaComponent(0.90)overlayView.font=UIFont.boldSystemFont(ofSize:YFCalendarOverlaySize)overla

swift - 如果我实际上没有在我的完成 block 中引用 self,我应该使用 [weak self] 吗?

当我有一个引用我的类对象属性的完成block时,我使用[weakself]。但是,有时我有一个不引用任何属性的完成block,但类对象可能会消失并取消初始化。我应该使用[weakself]吗?当我这样做时,它通常会发出警告Variable'self'waswrittento,butneverread...doSomeFunction(){[weakself]in//Noreferencestoselfhere} 最佳答案 捕获变量,只有当你在内部使用它时才会发生,默认情况下闭包永远不会捕获变量(不像Java内部类总是捕获this),

ios - 使 getNotificationSettings 返回而不是使用完成 block

我有一个方法用于我正在开发的应用程序的多个位置。这是一种检查远程推送通知是否启用的方法。该方法返回一个值,但您可能知道currentUserNotificationSettings已被弃用,所以现在我正在使用getNotificationSettings。问题是第一个返回一个值,而最新的使用一个block。我仍然希望能够返回一个值以避免重构所有内容,所以我写了以下内容,但它失败了,我不明白为什么......这样可以吗?!publicstaticvarisRemoteEnabled:Bool{varnotificationSettings:UNNotificationSettings?l

ios - 获取 UITableView 错误 "unable to dequeue a cell with identifier cell"

我正在创建一个带有UITableViewController的应用程序,但出现错误:'unabletodequeueacellwithidentifiercell-mustregisteraniboraclassfortheidentifierorconnectaprototypecellinastoryboard'我不明白如何找到解决方案并修复它。2018-09-1501:28:28.609848+0300Yemekler[6554:482441]***Assertionfailurein-[UITableView_dequeueReusableCellWithIdentifier:

swift - 没有 catch block 的 "do statement"是什么意思?

在阅读iOS12编程时,我遇到了几个示例代码,其中包含do语句,没有catchblock,像下面这样:do{letmars=UIImage(named:"Mars")!letsz=mars.sizeletr=UIGraphicsImageRenderer(size:CGSize(sz.width*2,sz.height),format:mars.imageRendererFormat)self.iv1.image=r.image{_inmars.draw(at:CGPoint(0,0))mars.draw(at:CGPoint(sz.width,0))}}//======do{letm

ios - block 是否保证局部变量将在 Swift 中被修改?

funcfoo()->Bool{varapiResult:Bool=falsemyAPI.bar(){(result:Bool)->Voidin//somelogicinblockandlocalvariableassignmentapiResult=result}returnapiResult}apiResult的值是否保证被传入的block更新?(本人是学习iOS的大学生,请大家多多指教) 最佳答案 您正在将闭包(block)传递给myAPI.bar函数。该函数可能会也可能不会调用闭包。如果调用闭包,则apiResult会发生变

string - Swift 是否支持字符串 block ?

Ruby、Python等语言都支持字符串block。如:a='''HelloWorld'''Swift支持字符串block吗? 最佳答案 没有。如Swift编程语言介绍的词法结构中所述,stringliterals包含在一对引号中,并且不得包含换行符。语法规定:string-literal→"quoted-text"quoted-text→quoted-text-itemquoted-textoptquoted-text-item→escaped-characterquoted-text-item→(expression)quote

ios - Xcode 6 测试版 4 : Use of Unresolved Identifier 'NSFetchedResultsChangeInsert'

刚刚安装了Xcode6Beta4,这个以前编译的代码现在在NSFetchedResultsChangeType的每个开关上都失败并显示“UnresolvedIdentifier”。我检查了发行说明,当然也浏览了这里,看看是否有其他人遇到过这种情况,但到目前为止还没有任何结果。任何信息表示赞赏!谢谢!funccontroller(controller:NSFetchedResultsController,didChangeSectionsectionInfo:NSFetchedResultsSectionInfo,atIndexsectionIndex:Int,forChangeType