[英]View Controller Doesn't Conform To Protocol AVCaptureFileOutputRecordingDelegate
[英]Glossy iOS doesn't conform to protocol
我正在尝试将Gloss集成到json解析中,但出现很多非意义错误。
我通过pod install安装了它,并且遇到了以下问题:
首先,当我导入它时,我得到了以下信息: Cannot import underlying modules glossy
,我不知道如何,但是在github回购中从GlossExample项目复制示例粘贴后,它消失了。
其次,如果我使用: struct Repo: Glossy
我收到错误消息,说Repo doesn't conform to protocols Decodable and Encodable
但是代码粘贴在示例中,并且存在方法init?(json: JSON)
和func toJSON() -> JSON?
然后,我尝试使用struct Repo: Decodable
并将此函数用于解码器:
init?(json: JSON) { let repoId: Int = "id" <~~ json
我收到以下错误: 35: Binary operator '<~~' cannot be applied to operands of type 'String' and 'JSON'
最后我说好,我不会使用重载运算符,而是使用普通的Decoder
类:
init?(json: JSON) { self.repoId = Decoder.decodeURL("id")(json) }
我得到: Cannot convert value of type 'JSON' to expected argument type 'JSON' (aka 'Dictionary<String, AnyObject>')
欢迎您的帮助和解答!
- 首先,当我导入它时,我得到了以下信息:
Cannot import underlying modules glossy
,我不知道如何,但是在github回购中从GlossExample项目复制示例粘贴后,它消失了。
这是在具有一些框架的Xcode中发生的问题,但是仅清除代码或直接运行它通常会摆脱警告。 否则,可能与使用较旧版本的Xcode有关。
其次,如果我使用:
struct Repo: Glossy
我收到错误消息,说Repo doesn't conform to protocols Decodable and Encodable
但是代码粘贴在示例中,并且存在方法init?(json: JSON)
和func toJSON() -> JSON?
这意味着您的struct
不符合这两个协议。 从光泽声明中 :
/**
Convenience protocol for objects that can be
translated from and to JSON
*/
public protocol Glossy: Decodable, Encodable { }
因此,Glossy协议继承了Decodable和Encodable,这意味着您需要为这两个协议实现协议功能,而不仅仅是toJSON() -> JSON?
。
然后我尝试使用
struct Repo: Decodable
并将此函数用于解码器:...
您需要首先在struct中声明常量,然后在init中反序列化JSON并将值设置为常量:
struct Repo: Decodable {
let repoId: Int
init?(json: JSON) {
guard let repoId: Int = "id" <~~ json { else return nil }
self.repoId = repoId
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.