0
我試圖獲取「內容」的字符串,但是當我執行代碼時,應用程序崩潰...當我嘗試使用self.content.text = "\(theText)"
它可以工作,但我想編碼爲UTF8,因爲我使用cyrilic和我回來這種\U0421\U044a\U0434\U044a\U0440\U0436\U0430\U043d\U0438\U0435 \U043d\U0430 \U043f\U0438\U0449\U043e\U0432\U0430
誰能解決這個問題?Swift - 從核心數據獲取字符串並轉換爲UTF8
下面是代碼:
let appDel: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
let context: NSManagedObjectContext = appDel.managedObjectContext
let theReq = NSFetchRequest(entityName: "Entity1")
theReq.returnsObjectsAsFaults = false
let myPredicate = NSPredicate(format: "objectId == \"\(contentID)\"")
theReq.predicate = myPredicate
let executed:AnyObject = context.executeFetchRequest(theReq, error: nil) as Array
let theText : AnyObject = executed.valueForKey("content")
self.content.text = theText
謝謝你的工作:) –