简体   繁体   English

如果存储在Realm中,则无法转换Int64

[英]Int64 can't be converted if store in Realm

I need to save 11 digits number in Realm, for that am using Int64 . 我需要在Realm中保存11位数字,因为这是使用Int64 When am reading it I need to convert it's datatype to String 在阅读时,我需要将其数据类型转换为String

let icnStr = employeeObj["icn"] as! String

but it is showing following error. 但它显示以下错误。

Could not cast value of type '__NSCFNumber' (0x186d21c) to 'NSString' (0xefd5e4).

尝试使用String(employeeObj["icn"]) ,希望对您有所帮助,不要向下转换,而是创建一个Int值的String实例。

You need to do following otherwise you'll be not able to unwrap it. 您需要执行以下操作,否则将无法解开包装。

Use following code. 使用以下代码。

let icnStr = String(describing: employeeObj["icn"]!)

It'll unwrap Optional value, because when it becomes String you can't unwrap it. 它会解开可选值,因为当它变成String时,您将无法解开它。 It'll give the following error. 它会给出以下错误。

cannot force unwrap value of non-optional type string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM