2017-05-15 5 views
1

私はswift 3とnsoutlineviewで動作します。 コアデータレコードのobjectIDをテキストフィールドに保存したいと思います。 ので、私は、文字列に変換する必要があります。swift 3 stringをobjectIDに変換します

txtFied.stringValue = "\(CoreData[outlineView.selectedRow].objectID)" 

どのように私は戻ってNSManagedObjectIDにそれを変換することができますか?

答えて

0

下記のとおり、私は、永続ストアコーディネータのmanagedObjectID(forURIRepresentation:)メソッドを経由して、これをやった:

// Convert NSManagedObjectID to a string, via the uriRepresentation method. 
    let objectIDString = <your managed object ID>.uriRepresentation().absoluteString 
    ... 
    // Use the persistent store coordinator to transform the string back to an NSManagedObjectID. 
    if let objectIDURL = URL(string: objectIDString) { 
     let coordinator: NSPersistentStoreCoordinator = <reference to your persistent store coordinator> 
     let managedObjectID = coordinator.managedObjectID(forURIRepresentation: objectIDURL) 
    } 
+0

は答えてくれてありがとう。私の "永続的な店のコーディネーター"は何ですか? – Ghost108

+0

私のコメントを忘れる - ありがとう、私はそれを試します:) – Ghost108

+0

お手伝いをします! :) –

関連する問題