草庐IT

pthread_self

全部标签

ios - Swift – self.navigationController 在过渡后变为 nil

我在我的应用程序中遇到了一个非常奇怪的错误,在两个View之间,self.navigationController正在变为nil我有几个ViewController:MainViewController、SecondViewControllerPastSessionsViewController、JournalViewController。我使用JournalViewController有两个目的,将新条目保存到CoreData或编辑旧条目。详细信息与此错误并不相关。当我尝试从堆栈中弹出JournalViewController并返回到MainViewController时发生错误,但

swift - 检查 UITableViewDelegate 是否等于 self

我怎样才能编译它?assert(self.tableView.delegate==self)其中self是一个包含tableview的UIViewController我明白了WjateverViewController.swift:56:44:Binaryoperator'=='cannotbeappliedtooperandsoftype'UITableViewDelegate?'and'WjateverViewController'你可能会认为断言(myTableView.delegate==selfasUITableViewDelegate?)会起作用。但它不会:OffersVi

ios - Swift:当我们对 Int 进行扩展时,属性 getter 中的 "self"应该是什么?

这似乎是一个错误并在Xcode7中用Swift(2b3)解决了为了方便观察,我们把代码贴到playground上,结果会在评论中指出。extensionInt{varsq:Int{mutatingget{self//5self=self*self//25returnself//25Here25ismade}}}varn:Int=5//5n.sq//25n//5Whyisn't25?我的问题是,如果属性sq的getter中的self指的是整数本身,为什么n在之后保留5>n.sq做了?让我们看看如果我们只添加一个setter会发生什么:extensionInt{varsq:Int{muta

ios - 返回一个 Self 类型的数组

我无法找到一种在运行时在Swift中返回特定动态类类型实例数组的方法。我成功地编译并测试了这个返回类的单个实例的版本:classGeneric{classfuncall()->Self{returnself.init()}requiredinit(){}}classA:Generic{}leta=A.all()//isoftypeA这里的挑战是编译允许all函数原型(prototype)如下:classfuncall()->[Self](即返回一个实例数组,使用子类,没有任何转换)。classGeneric{classfuncall()->[Self]{return[self.init

ios - `Protocol can only be used as a generic constraint because it has Self or associated type requirements` 问题

我正在尝试生成一个符合协议(protocol)Protocoling的ViewModel,该协议(protocol)是通用的,并且具有关联的类型。有几个ViewModel符合协议(protocol),所以我正在尝试为viewModel创建一个工厂。我在Swift中遇到了以下错误:Protocol只能用作泛型约束,因为它有Self或关联类型要求示例代码:protocolProtocoling{associatedtypemodulingTypevardata:modulingType{get}}enumMyTypes{casemyNamecasemyAddress}classNameVi

ios - 关闭键盘后如何恢复 UIInputViewController self.view?

我正在开发一个具有键盘扩展的应用程序,在键盘扩展的某些用途中(例如:当我使用切换键盘按钮时)扩展正在经历viewDidDisappear并在在这种情况下,我知道我可以清理键盘,它的所有View都将被解除分配,内存也将被释放。在其他用途​​中(例如:当使用Notes应用程序并按下Done/Back按钮时)扩展将通过viewWillDisappear而不是通过viewDidDisappear,所以在这个如果我没有清洁键盘,因为它没有达到我的清洁方法,因此它没有被释放。在这一点上,我希望当我通过回到笔记返回到键盘时,例如我会收到之前的UIInputViewController以及我已经构建的

swift - 闭包中的无主 self

如果我在另一个闭包中有一个闭包,是否足以在外部闭包中使用unowned/weakonce来避免保留循环?例子:foo.aClosure({[unownedself](allowed:Bool)inifallowed{self.doStuff()self.something.anotherClosure({(s:String)->(Void)inself.doSomethingElse(s)})}}) 最佳答案 如果您没有在外部闭包中创建对self的强引用(例如通过这样做:guardletstrongSelf=selfelse{返回}

arrays - 警告 "Simultaneous accesses to parameter ' self' ..."真的适用于此吗?

我为Array写了一个扩展,允许我弹出最后一个元素并立即将它添加到另一个数组:extensionArray{mutatingfuncpopLast(tootherArray:inout[Element])->Element?{guardself.count>0else{returnnil}returnotherArray.appendAndReturn(self.popLast()!)}mutatingfuncappendAndReturn(_element:Element)->Element{self.append(element)returnelement}}playground中

objective-c - 在我的 Swift 应用程序中使用来 self 的 XPC 服务的 Objective-C 协议(protocol)

我有一个用Swift编写的应用程序,完全用Swift编写,从来没有Obj-C类,没有Obj-C文件或桥接header。为了在不影响我的应用程序权利的情况下添加一些功能,我尝试添加一个XPC服务——我在Xcode中创建了它,Xcode中的XPC服务模板仅为Obj-C。很好,我在Obj-C中编写了我的服务,但现在当我想通过NSXPCConnection调用我的服务时,我必须设置它的接口(interface),然后执行此操作我需要在我的Swift应用程序代码中引用我为XPC目标编写的Obj-C协议(protocol)。我该怎么做?我不能只将“Protocol.h”添加到我的应用程序目标,它没

swift - 协议(protocol)扩展初始化程序强制调用 self.init

我刚刚阅读了有关协议(protocol)初始化程序要求的AppleSwift4文档,并在协议(protocol)扩展中提供了默认实现。importUIKitprotocolProtocol{init()}extensionProtocol{init(){print("SDf")self.init()//Line1//Compilererroroccuredifthisisomitted//"'self.init'isn'tcalledonallpathsbeforereturningfrominitializer"}}structStructure:Protocol{init(stri