- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 Mantle 进行申请使用 iOS 9.1
class SKUser: MTLModel, MTLJSONSerializing {
var userId:NSNumber = -1
var firstName:String = ""
var lastName:String = ""
var country:String! = ""
var address:String! = ""
var company:String! = ""
var email:String! = ""
var mobileNumber:NSNumber = -1
static func JSONKeyPathsByPropertyKey() -> [NSObject : AnyObject]! {
return [
"userId": "user_id",
"firstName": "user_first_name",
"lastName": "user_last_name",
"country": "user_country",
"address": "user_address",
"company": "user_company",
"email": "user_email",
"mobileNumber": "user_mobile_number"
]
}
}
我无法将手机号码和userId字段转换为整数或NSNumber,我已经尝试了很多但找不到解决方案
请帮帮我
提前致谢...
最佳答案
尝试在您的代码中进行此更改。 ( swift 3)
class SKUser: MTLModel, MTLJSONSerializing {
var userId:NSNumber?
var firstName:String?
var lastName:String?
var country:String?
var address:String?
var company:String?
var email:String?
var mobileNumber:NSNumber?
public override static func jsonKeyPathsByPropertyKey() -> [AnyHashable : Any]! {
return [
"userId" as AnyHashable: "userId" as Any,
"firstName" as AnyHashable: "firstName" as Any,
"lastName" as AnyHashable: "lastName" as Any,
"country" as AnyHashable: "country" as Any,
"address" as AnyHashable: "address" as Any,
"company" as AnyHashable: "company" as Any,
"email" as AnyHashable: "email" as Any,
"mobileNumber" as AnyHashable: "mobileNumber" as Any
]
}
}
注意“jsonKeyPathsByPropertyKey”中的小写“json”而不是“JSONKeyPathsByPropertyKey”
关于ios - 如何在地幔中将字符串转换为原始类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34675069/
我使用 coco pod 安装了“Mantle”。但是当我尝试在我的模型中使用它时,它出现了此错误。 /Users/bgbb/Developer/experimental/MantleTest/Man
假设我们有一个 MTLModel 的子类,并且该类立即获得了 copyWithZone: 的实现。但我想知道框架是否使用深复制。例如,如果该类具有数组或对象属性,则他们复制了引用或新分配的对象。非常感
我正在使用 Mantle 框架,我似乎在将某些值序列化为 MTLModel 时遇到了一些问题。这是我从服务器收到的 JSON: { "id":50, "name":"UserName"
我有一个 JSON 字典,如下所示: { "111": {"dates" : [], "members" : []}, "112": {"dates" : [],
我有一个简单的场景,我想用 Mantle 从 Json 解析一个用户模型并将其保存到 Realm 数据库: 为了使用 Mantle 库,模型接口(interface)必须像这样扩展 MTLModel
我是一名优秀的程序员,十分优秀!