草庐IT

delete_self

全部标签

ios - Swift 类 : Property not initialized at super. init 调用中的错误 - 如何初始化需要在其初始化参数中使用 self 的属性

我正在快速覆盖UITableViewController,其中我有两个必需的变量,它们是通过使用self的weak引用初始化的,因为这些用于实现UITableViewDataSource协议(protocol),需要self引用才能使用其tableView属性classVideosListViewController:UITableViewController{requiredinit(coderaDecoder:NSCoder){super.init(coder:aDecoder)self.datasourceOfflineVideos=ASDataSource(tableViewC

ios - Swift - 将 self.navigationController 调用到自定义单元类中

swift:我有UICollectionViewController和另一个文件/类UICollectionViewCell目标是从我的自定义单元格类中推送UIViewController。像这样:self.navigationController?.pushViewController(vc,animated:true)我在UICollectionViewController中从didSelectItemAtIndexPath实现推送没有问题,但我想从注册到我的UICollectionViewController中的自定义单元格类执行此操作。不幸的是,当我尝试从自定义单元格类推送Vi

swift - 为什么要在依赖 self 的 block 中指定 [unowned self]?

我希望self不为nil,并且我确信它会在block执行期间。那么为什么要明确指定[unownedself]呢?object.executeBlock{date=self.lastModified}对比object.executeBlock{[unownedself]indate=self.lastModified}编辑:好吧,我的票数越来越低,所以让我们再试一次。问:假设我有问题。那个问题是我想阻止引用循环。我有两个选择。我可以使用[unownedself]或者我可以使用[weakself]。因此,我的问题是:从这两个选项中,我为什么要选择[unownedself]?为什么不每次都选

swift - swift 中的变异结构函数是否会创建一个新的 self 副本?

我喜欢swift中的值语义,但我担心变异函数的性能。假设我们有以下structstructPoint{varx=0.0mutatingfuncadd(_t:Double){x+=t}}现在假设我们创建了一个Point并像这样改变它:varp=Point()p.add(1)现在内存中的现有struct是否发生了变异,或者self是否被新实例替换为self=Point(x:self.x+1) 最佳答案 Nowdoestheexistingstructinmemorygetmutated,orisselfreplacedwithanewi

ios - 闭包语法中的 Swift weak Self

我有这段代码来获取JSON:Alamofire.request(.GET,worlds).responseJSON{(request,response,JSON,error)inprintln(JSON)//weakSelf.serverList=JSON}如何在这里声明weakSelf?我知道在我的情况下它应该是无主的,但我找不到正确的语法。当我尝试使用[unownedself].serverList而不是注释行时,编译器显示错误“使用未解析的标识符‘unowned’”。我也试过像这样在block之前声明常量:unownedletuSelf=self它就像一个魅力,但我想了解如何在我

swift - 在异步网络请求中捕获 self weak 或 unowned

每当我执行异步网络请求时,可能是在请求到达时self已经为nil(例如,ViewController已经被关闭)。为了防止这种情况,我通常将自己描述为软弱的:future.onSuccess(context:Queue.main.context,callback:{[weakself]resultinifletstrongSelf=self{//Dosomestuffwithself,whichisnowguaranteedtobenotnil//strongSelf.someMethod()}})或者我可以将self捕捉为无主:future.onSuccess(context:Que

ios - xcode 7.3 : Could not insert new outlet connection and deleting DerivedData doesnt work

themostcommonanswerforthisquestionSO上已有3年历史,普遍同意的解决方案(删除DerivedData)对我不起作用,所以我不得不重新问这个问题。我正在尝试通过拖动为我的tableview创建一个outlet。如前所述,删除DerivedData对我没有任何作用(但我可以看到它正在重新编制索引)。第二个最常见的答案是Removing(removingreference,notdeleting)andthenaddingtheappropriatefile(thefileofclassyouwanttoaddtheoutletto)isactuallyen

ios - self.view?.presentScene : unexpectedly found nil while unwrapping an Optional value (Swift)

我正在尝试切换场景,但我的应用程序崩溃并出现此错误:crashcrashfatalerror:unexpectedlyfoundnilwhileunwrappinganOptionalvalue(lldb)这是我切换场景的代码:funcswitchscenes(){ifdisplay>=2{Player.removeFromParent()PlayerRight.removeFromParent()PlayerLeft.removeFromParent()fireHair.removeFromParent()fireHairRight.removeFromParent()fireHai

ios - SWIFT 的核心数据 : How to delete object from Relationship entity?

我很困惑,无法找到任何关于如何最好地做到这一点的教程或文档。问题:我有两个实体,Person和Location。人可以有很多位置。我已正确设置所有内容,可以从表格View中添加/删除人员,没问题。我遇到的问题是在创建第一个位置后尝试添加和删除位置——当第一次插入此人时,它还会添加一个位置。为此,PersonModel(PersonEntity)类有:classPersonModel:NSManagedObject{@NSManagedvarName:String@NSManagedvarAge:String@NSManagedvarLocation:NSOrderedSet}Locat

swift - 当不在闭包中时,传递属于 self 的函数是否会导致保留循环?

如果您需要在闭包中引用self,最好将其作为weak或unowned传递以防止保留循环。如果我直接传递属于self的函数,会不会造成retaincycle?或者它是否需要嵌套在闭包中以削弱self?直接传递UIView.animateWithDuration(0.3,delay:0.0,usingSpringWithDamping:0.7,initialSpringVelocity:0.1,options:.CurveEaseOut,animations:self.view.layoutIfNeeded,//doesthiscauseretaincycle?completion:nil