2016-11-22 113 views
0

我需要在Realm中保存11位數字,因爲這是使用Int64。 當我讀它,我需要把它的數據類型轉換爲String如果在Realm中存儲Int64不能轉換

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

卻是露出下面的錯誤。

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

回答

2

嘗試String(employeeObj["icn"]),希望它能幫助,不要垂頭喪氣,但用的詮釋

+0

感謝讓icnStr = String(描述:employeeObj [「icn」])工作 但現在無法解包。 –

+0

你只是從該字符串重新創建回Int,它將工作 – Tj3n

+0

我需要使用String&它正在打印此值 可選(13421423231) 當試圖展開它時,它說 不能強制展開非值的值 - 任意類型字符串 –

0

你需要做以下,否則你將無法解開它價值創造String實例。

使用以下代碼。

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

這將解開可選值,因爲當它成爲String你不能解開它。它會給出以下錯誤。

cannot force unwrap value of non-optional type string