草庐IT

不符合

全部标签

json - 如何以自定义方式对已经符合 Codable 的基础类型(例如 TimeInterval)进行编码?

在Swift4中以自定义方式将自定义类型编码为JSON很容易,并且有很好的文档可用。但是我在以自定义方式编码Foundation类型时遇到了问题。我的具有类型TimeInterval属性的自定义类型需要是Codable并使用JSON格式显示分钟和秒,如下所示://mytype:structMyType:Codable{lettime:TimeInterval=65.12}//requiredJSONrepresentation:"myType":{"time":{"minutes":1,"seconds":5.12}}如果我为我的每一个类型提供encode(to:)和init(deco

ios - 被发送到一个不符合 "com"属性的 KVC 的对象

我想观察存储在UserDefaults.standard键下的值:com.apple.configuration.managed,所以我这样做了:UserDefaults.standard.addObserver(self,forKeyPath:"com.apple.configuration.managed",options:[.new,.old],context:nil)然后我实现了这个:overridefuncobserveValue(forKeyPathkeyPath:String?,ofobject:Any?,change:[NSKeyValueChangeKey:Any]?

ios - Swift AppDeligate 不符合协议(protocol) 'MessagingDelegate'

使用Swift2.3和Xcode8我将Firebase升级到版本4我遵循了新版本中提到的所有更改https://firebase.google.com/docs/reference/ios/naming-migration-guide#changes_in_the_new_version我仍然得到一个错误提示Type'AppDelegate'doesnotconformtoprotocol'MessagingDelegate'我不知道这个方法改变了什么或者我需要添加哪个新方法。请帮助我classAppdelegate:UIResponder,UIApplicationDelegate,

swift - 符合通用协议(protocol)方法返回 PAT

我想声明类似于以下的通用协议(protocol):protocolFactory{funccreateWidget(_t:T)->TWidgetwhereTWidget:Widget,TWidget.T==T}protocolWidget{associatedtypeTfuncget()->T}我希望我可以实现Factory的具体变体,通过隐藏实现返回它们自己的具体和不透明的Widget。这是一个构建失败的示例实现:structConcreteFactory:Factory{funccreateWidget(_t:T)->TWidgetwhereTWidget:Widget,TWidg

Swift:类型不符合协议(protocol) 'ArrayLiteralConvertible'

在我的playground中不断出现错误,提示Set不符合协议(protocol)“ArrayLiteralConvertible”structSet:ArrayLiteralConvertible{typealiasElement=Tprivatevarcontents:[Element:Bool]init(){self.contents=[Element:Bool]()}//easierinitializationinit(_sequence:S){self.contents=[Element:Bool]()Swift.map(sequence){self.contents[$0]

ios - 仅在 DEBUG 配置上符合协议(protocol)

当设置了DEBUG标志时,我试图启用类协议(protocol):#ifDEBUGclassLoginViewController:UIViewController,UITextFieldDelegate{#elseclassLoginViewController:UIViewController{#endif//...}虽然它没有编译,#else行上的“Expecteddeclaration”。 最佳答案 swift中的预处理器指令与您可能习惯使用的不同。Appledocumentation关于这个主题,#if/#else/#end

swift - 引用符合协议(protocol)的类

假设我有一个如下所示的协议(protocol):protocolFoo{varbar:Bool{getset}}现在我有了符合Foo协议(protocol)的ViewController;classFooViewController:UIViewController,Foo{...}在另一个类中我想做这样的事情:classFooClass{varviewController:UIViewController?//thisshouldconformtoFooprotocolfuncsetViewController(viewController:UIViewController){ifl

ios - 类型 'Any' 不符合协议(protocol) 'Sequence'

我在我的代码中遇到了问题,在尝试解析JSON数据(数组的每个数据,比如它应该如何完成)并尝试设置forin循环时,错误出现了。这是我的代码ifletjsonDataArray=try?JSONSerialization.jsonObject(with:data!,options:[]){print(jsonDataArray)varallStops=[busStops]()foreachDatainjsonDataArray^//thisiswheretheerrorislocated{ifletjsonDataDictionary=eachDataas?[String:AnyObje

ios - 类型 'ProfilesTableViewController' 不符合 Xcode 6 GM 种子中的协议(protocol) 'UITableViewDataSource'

今天我迁移到Xcode6GM种子,现在我得到以下错误:Type'ProfilesTableViewController'doesnotconformtoprotocol'UITableViewDataSource'.我已经覆盖了numberOfRowsInSection、cellForRowAtIndexPath和numberOfSectionsInTableView。事实上,直到今天一切正常。我注意到,当我删除UITableViewDataSource时,一切正常,没有发生任何错误。那么..是否有必要再使用“UITableViewDataSource”,或者只是覆盖其中的函数?

swift - 类型不符合协议(protocol) CustomStringConvertible

我正在实现trycatch枚举:enumprocessError:Error,CustomStringConvertible{caseonevarlocalizedDescription:String{return"one"}casetwovarlocalizedDescription:String{return"two"}}但我收到以下错误:typeprocessErrordoesnotconformtoprotocolCustomStringConvertible但是如果我在第二种情况下更改变量的名称,我不会得到错误:enumprocessError:Error,CustomStr