pod 'HandyJSON', '~> 5.0.1'
struct UserInfoModel: HandyJSON {
var avatar: String!
var nick: String!
var username: String!
}
//主要问题在这里instance对应上面结构题的属性成了可选的
` static func _transform(dict: [String: Any]) -> _ExtendCustomModelType? {
var instance: Self
if let _nsType = Self.self as? NSObject.Type {
instance = _nsType.createInstance() as! Self
} else {
instance = Self.init()
}
instance.willStartMapping()
_transform(dict: dict, to: &instance)
instance.didFinishMapping()
return instance
}`
1条答案
按热度按时间e1xvtsh31#
Swift 5.0+ 里面 ! 和 ? 内部实现是一样的,本质上都是可选,你想要不可选要把那个 ! 去掉