gpt4 book ai didi

ios - 如何在地幔中将字符串转换为原始类型?

转载 作者:搜寻专家 更新时间:2023-11-01 05:37:53 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com