草庐IT

non-conforming

全部标签

ios - EXC_BAD_ACCESS 尝试编码 Codable-conformant 类的子类时

我一定是个白痴之类的,但我已经连续第三天摸不着头脑了,无法弄清楚我打算在我的Swift程序中编码一些JSON数据的意图出了什么问题......情况是这样的:我有两个类如下:classNode:Codable{//Nothinginhere}和classShape:Node{//Nocodeheretoo}然后,我尝试按如下方式对子类进行编码:do{letencodedData=tryJSONEncoder().encode(Shape())}catch{print(error)}这就是我添加到一个空的单View应用程序项目中的所有内容。当我运行它时,出现“Thread1:EXC_BAD

ios - 当我尝试在函数前添加 private 时,Xcode 报错 "attribute private can only be used in a non local scope"

当我尝试在函数前面添加private时,xcode提示“属性private只能在非本地范围内使用”。我认为“私有(private)”应该用于您想要保留本地权利的事情?有人可以告诉我如何处理错误消息吗?我仍然想将函数保密。 最佳答案 我是通过搜索这个错误attributeprivatecanonlybeusedinanonlocalscope到这里的。在我的例子中,这是由switch语句末尾缺少右括号引起的。希望这对某人有帮助。 关于ios-当我尝试在函数前添加private时,Xcode

swift - 条件一致性 : Using 'T' as a concrete type conformance to 'T' is not supported

这个问题在这里已经有了答案:Protocoldoesn'tconformtoitself?(3个答案)关闭3年前。我有一些非常基本的代码,因为我正在尝试了解条件一致性:protocolAnimal{varname:String{get}}protocolSocial{funcspeak()}classCat:Animal,Social{varname:Stringinit(name:String){self.name=name}funcspeak(){print("Meow")}}classDog:Animal,Social{varname:Stringinit(name:String

swift 2.0 : Creating a Collection Type of Objects that conform to a Generic Protocol

例如:protocolSomeProtocol{typealiasTfuncdoSomething(something:T)}leta=Array()我想要一个数组,它是一个符合SomeProtocol的对象数组。这在理论上似乎很好,但我收到以下错误消息:Cannotbeusedasagenericconstraintbecauseitcontainsassosciatedtyperequirements.我想这是有道理的,毕竟Array也是一个通用结构,因此编译器将无法确定SomeProtocol和的实际类型数组是通用的。所以我的问题是-我觉得我应该能够拥有一个符合SomeProto

swift - 输入 'Range<CGFloat> does not conform to protocol Sequence' (Swift 3)

这个问题在这里已经有了答案:Swift3:replacecstylefor-loopwithfloatincrement(1个回答)关闭5年前。我想在这里使用CGFloat做一个for循环,但我收到一个错误提示Type'RangedoesnotconformtoprotocolSequence'我尝试运行的代码如下。错误发生在代码末尾的“for”循环中。funcsetupBackgroundSea(){//puttingthebackground//lettexture=SKTexture(imageNamed:"background")texture.filteringMode=.n

swift - 字符串字典 :Any does not conform to protocol 'Decodable'

这个问题在这里已经有了答案:Fatalerror:DictionarydoesnotconformtoDecodablebecauseAnydoesnotconformtoDecodable(2个答案)关闭4年前。我正在尝试实现一个Decodable来解析json请求,但json请求在对象内部有一个字典。这是我的代码:structmyStruct:Decodable{letcontent:[String:Any]}enumCodingKeys:String,CodingKey{casecontent="content"}但是我收到了这个错误:类型“MyClass.myStruct”不符

xcode - Failable och non-failable initializers 阻止我扩展 NSView 和实现 NSCoding

我在实现NSView的子类时遇到问题,它实现了NSCoding。似乎init(coder:NSCoder)的声明在NSView和NSCoding中有冲突。NSView现在说它是可失败的,但是NSCoding仍然说它是不可失败的。当我尝试覆盖init(coder:NSCoder)并进行自定义初始化时,Xcode6.1给我一条错误消息:Anon-failableinitializercannotchaintofailableinitializer'init(coder:)'writtenwith'init?'我应该如何对我的类进行自定义初始化?这是一个愚蠢的例子,我扩展了一个View,我想

swift - #include 来自模块化项目头文件的系统头文件给出 "Include of non-modular header inside framework module..."错误

我正在尝试将libarchive嵌入到我正在构建的基于Swift的框架中。我创建了一个模块映射以私下包含archive.h(在模块libarchive中接近尾声)frameworkmoduleX{requiresobjc,blocks,objc_arcumbrellaheader"X.h"privateheader"XPrivate.h"privateheader"x.h"useDarwin.Cmodulelibarchive{privateheader"archive.h"export*}}在archive.h中,以下行导致错误:#include我不明白为什么这个包含没有被映射到我的

ios - Swift 2.2 语法错误 : Cannot call value of non-function type 'UITableView!'

我在UITableView单元格中使用Tab手势,但出现以下错误。“无法调用非函数类型‘UITableView!’的值!”我正在使用从我以前的ObjectiveC项目继承的以下代码:varp:CGPoint=sender.locationInView(self.tableView)varindexPath:NSIndexPath=self.tableView(forRowAtPoint:p)varbuttonTag:Int=indexPath.rowvarselectView=self.storyboard?.instantiateViewControllerWithIdentifie

Swift 泛型 : Non-nominal type does not support explicit initialization

所以我试图理解通用协议(protocol)和类:protocolListPresenterTypewhereView.PDO.SW==Dispatcher.SW{associatedtypeDispatcher:ListDispatcherTypeassociatedtypeView:ListViewTypeinit(dispatcher:Dispatcher,state:@escaping(_state:AppState)->(ListState))funcattachView(_view:View)...}我从另一个通用类启动它:classAbstractListViewContr