草庐IT

Duck-typing

全部标签

iOS Swift 可解码 : Error: Cannot invoke initializer for type with no arguments

我在初始化结构时遇到错误,请参阅下面的屏幕截图。调试后我发现在结构中包含review变量会产生问题。我不知道我做错了什么。谁能帮帮我?发送我正在复制代码以防你需要尝试一下importUIKitstructRootValue:Decodable{privateenumCodingKeys:String,CodingKey{casesuccess="success"casecontent="data"caseerrors="errors"}letsuccess:Boolletcontent:[ProfileValue]leterrors:[String]}structProfileValu

json - Swift 结构 : handling multiple types for a single property

我正在使用Swift4并尝试解析一些JSON数据,这些数据显然在某些情况下可能对同一键具有不同的类型值,例如:{"type":0.0}和{"type":"12.44591406"}我实际上坚持定义我的struct因为我不知道如何处理这种情况,因为structItemRaw:Codable{letparentType:StringenumCodingKeys:String,CodingKey{caseparentType="type"}}抛出“预期解码String但发现了一个数字。”,自然地,structItemRaw:Codable{letparentType:FloatenumCod

ios - target 指定产品类型 'com.apple.product-type.bundle.ui-testing' ,但是 'iphonesimulator' 平台没有这样的产品类型

当我运行我的swift项目时,我得到了这个错误。targetspecifiesproducttype'com.apple.product-type.bundle.ui-testing',butthere'snosuchproducttypeforthe'iphonesimulator'platform我在SO上发现了一些类似的问题,但是this答案没有解决我的问题。我googled它也是,里面没有这个产品类型的项目。我正在使用xcode6.4和swift1.2 最佳答案 在使用Xcode7Beta添加用于UI测试的产品并不断在Xco

swift - swift 中的 T.Type 是什么

当我使用JSONDecoder().decode()时,谁能告诉我什么是T.Type?我认为它是解码我编码的数据的类型。很多例子都是这样使用上面的方法:JSONEncoder().decode([People].self,from:data)如果我检查该方法的定义,我可以看到T.Type。我知道泛型,但什么是T.Type?T和T.Type有什么区别?当我们声明一些变量时,我们这样分配它们的类型varsomeValue:Int,不是varsomeValue:Int.selfT.Type和Type.self到底是什么? 最佳答案 T.T

ios - 看看为什么在 Xcode 中是 "type does not conform to protocol"(swift)

我经常使用具有关联类型约束的相对复杂的协议(protocol),这些协议(protocol)被用于泛型,被CoreData类型扩展等使用。因此我相对经常收到错误:Type..doesnotconformtoprotocol...。我通常可以在一段时间后解决这个问题,但错误消息确实没有帮助——通常,如果问题是方法签名中的一个小错字或其他东西,则需要一些时间才能找到错误。对于Java接口(interface),IDE通常会报告类似method...notimplemented之类的信息,因此我知道应该更详细地查看哪个方法。有没有办法让Xcode报告有关协议(protocol)成员的详细信息

ios - 使用数组指针和 swift 1.2 进行 PFSubclassing - fatal error : NSArray element failed to match the Swift Array Element type

使用swift1.2,我无法再使用解析子类检索指针数组并将其向下转换为另一个解析子类。我总是发现错误:fatalerror:NSArrayelementfailedtomatchtheSwiftArrayElementtype你有想法还是可能会出现?代码:importFoundationclassShotModel:PFObject,PFSubclassing{/***MARK:Properties*/@NSManagedvarname:String@NSManagedvarpics:[PicModel]overrideclassfuncinitialize(){varonceToke

Xcode 7.1 : Property with retain or strong attribute must be of object type

我在一个swift文件中有这个变量:varadbk:ABAddressBook!一直很好,直到Xcode7.1。现在它提示“具有保留或强属性的属性必须是对象类型。”错误在-Swift.h文件中。知道发生了什么变化会导致这种情况以及如何解决它吗? 最佳答案 如果Swift类声明了一些AdressBook属性并且此类是混合Swift/ObjC项目的一部分,则会发生此错误。Xcode然后生成Swift桥接header,其中此属性变为(nonatomic,strong),它仅适用于对象,不适用于结构。当我需要将ABRecordRef从Obj

ios - swift JSON 错误 : Could not cast value of type '__NSDictionaryM' to 'NSArray'

从web服务(API)解码JSON时出现错误:Couldnotcastvalueoftype'__NSDictionaryM'(0x1037ad8a8)to'NSArray'(0x1037ad470).我的代码:varkGetURL="http://bitnami.local/cscart_demo/api/users"//varkGetURL="http://localhost/fendy/getjson.php"varjson:Array=[]overridefuncviewDidLoad(){super.viewDidLoad()start()}funcgetData(data:

swift 2 : Value of type 'Set<UITouch>' has no member 'anyObject'

这个问题在这里已经有了答案:Overridingmethodwithselector'touchesBegan:withEvent:'hasincompatibletype'(NSSet,UIEvent)->()'(9个回答)关闭6年前。我检查了我的旧游戏,我想在Swift2.0中更新它。当我试图修复它时,Xcode发现了一个错误。错误是Valueoftype'Set'hasnomember'anyObject'在这行代码中:vartouch:UITouch=touches.anyObject()as!UITouch功能:overridefunctouchesEnded(touches

ios - 错误 :Use of undeclared type 'NSObject' in Xcode

我构建了一个名为“CheckItem”的新数据结构(我正在做一个Todo项目)我让CheckItem类继承NSObject和NSCoding但是Xcode在第1行警告编译时错误:classCheckItem:NSObject,NSCoding{thehintis:Useofundeclaredtype'NSObject'(and'NSCoding')全类如下:classCheckItem:NSObject,NSCoding{vartext:StringvarisDone:BoolvarimageName:Stringinit(text:String,isDone:Bool,imageN