草庐IT

Duck-typing

全部标签

swift - NSFetchRequest as entityName 给出错误 "use of undeclared type"

我在Swift2.1和Xcode7.2中使用核心数据此代码给我一个无法找到实体名称的错误。这因为[Company]不起作用。我有一个具有此名称的实体。letfetchRequest=NSFetchRequest(entityName:"Company")do{varresult=tryself.moc.executeFetchRequest(fetchRequest)as![Company]if(result.count>0){companyName?.stringValue=result[0].valueForKeyPath("name")as!String//success...}

swift - "Cannot call value of non-function type ' HTTPURL 响应? '"(Alamofire 4.0) [Swift 3.0]

我收到此错误:"Cannotcallvalueofnon-functiontype'HTTPURLResponse?'"关于部分:.response{(request,response,data,error)我想知道是否有人可以帮助我。Alamofire.download(urlToCall,method:.get){temporaryURL,responseinifFileManager.default.fileExists(atPath:finalPath!.path!){do{tryFileManager.default.removeItem(atPath:finalPath!.

swift 4 : pattern match an object against a tuple (Tuple pattern cannot match values of the non-tuple type)

我有一个包含几个字段的自定义结构,我想在快速switch语句中对其进行模式匹配,这样我就可以通过将其中一个字段与另一个字段进行比较来自定义匹配正则表达式。例如鉴于这种结构:structMyStruct{letheader:Stringlettext:String}我喜欢像这样进行模式匹配:switch(someInstance){case("h1","[a-z]+"):...case("h1","0-9+"):...}我尝试使用如下模式匹配函数让它工作:func~=(pattern:(String,String),value:MyStruct)->Bool{returnvalue.he

ios - Xcode 10 beta2 : Cannot invoke initializer for type 'UIView' with no arguments

我已经下载了Xcode10beta2并重建了我的项目,代码如下:letsomeView=UIView()出现以下错误:无法调用不带参数的“UIView”类型的初始值设定项很奇怪。有人在使用Xcode10beta2时遇到过这些构建错误吗? 最佳答案 对我来说,这是通过扩展NSObjectProtocol来推断的:extensionNSObjectProtocolwhereSelf:UIView我通过将NSObjectProtocol替换为UIView符合的任何其他协议(protocol)来修复它。在我的例子中是UIAppearance

带有 Protocol.Type 的 Swift 泛型

我对Swift中的泛型有疑问(3):我从服务器获取实现相同协议(protocol)的不同类的不同数据,我需要将它们放入具有泛型的类中(例如数组)。我不知道数据是哪个类,所以我需要使用协议(protocol)。所以我有以下结构:我的协议(protocol):protocolMyProtocol{//someprotocolstuff}一些实现协议(protocol)的类classMyProtocolImpl1:MyProtocol{//someclassstuff}classMyProtocolImpl2:MyProtocol{//someclassstuff}....泛型类:final

swift 2.0 : infer closure type error

我得到错误Unabletoinferclosuretypeinthecurrentcontext在Swift1.2中运行的代码privatelazyvar_messagesVC={returnMessagesViewController(nibName:"MessagesViewController",bundle:nil)}()出现此错误的整个ViewControllerimportUIKitclassFriendsViewController:UIViewController{@IBOutletweakvarcontainerView:UIView!@IBOutletweakvar

ios - 以编程方式将自定义 UIViewcontroller 添加到 subview 但收到错误消息 "Cannot convert value of type..."

我正在尝试在Swift中以编程方式将自定义UIViewController类(UIPickerView)添加到我的主ViewController(不使用Storyboard)但我收到以下错误消息..."Cannotconvertvalueoftype'HabitViewViewController'toexpectedargumenttype'UIView'自定义UIPicker类:importUIKitclassHabitViewController:UIViewController,UIPickerViewDataSource,UIPickerViewDelegate{@IBOut

swift - "Cannot call value of non-function type"

我刚刚下载了Xcode8Beta,以便可以在我的应用程序中包含一些新的iOS10框架。然而,在将我的代码从Swift2转换为Swift3的过程中,我遇到了几个错误。除了一个super烦人的,我都修好了。我收到错误:Cannotcallvalueofnon-functiontype'JSQMessagesCollectionView!'atthefollowinglineofcode:letcell=super.collectionView(collectionView,cellForItemAtIndexPath:indexPath)as!JSQMessagesCollectionVi

iphone - 为什么在将 Float 转换为 CGFloat 时 Xcode 给我一个警告 "Cannot convert value of type ' CGFloat' to expected argument type 'UnsafeMutablePointer"?

我正在尝试将Float值转换为CGFloat值,这里是我的代码:letmyFloatForR=0letr=CGFloat(myFloatForR)letmyFloatForG=0letg=CGFloat(myFloatForG)letmyFloatForB=0letb=CGFloat(myFloatForB)letmyFloatForA=0leta=CGFloat(myFloatForA)tintColor.getRed(r,green:&g,blue:&b,alpha:&a)但Xcode突然给我一个警告说:“无法将类型'CGFloat'的值转换为“tintColor”行上的预期参数类

ios - Swift 中的 NSDictionary :Cannot subscript a value of type 'AnyObject?' with a index of type 'Int'

所以我正在尝试使用swift解析JSON中的一些数据。下面是我的代码varjsonResult:NSDictionary!=NSJSONSerialization.JSONObjectWithData(data,options:NSJSONReadingOptions.MutableContainers,error:nil)as!NSDictionaryprintln(jsonResult)上面的代码会返回这样的东西{count=100subjects=({alt="....."name="....."},{alt="....."name="....."},......)}然后我尝试使