2015-07-10 6 views
14

मैं एक आवेदन मैं एक साथ डाल रहा हूँ में एक कस्टम प्रवास नीति का उपयोग करने की कोशिश कर रहा हूँ। मैपिंग मॉडल का उपयोग करते समय अब ​​तक माइग्रेशन v1 -> v2 से काम कर चुके हैं। हालांकि, जब भी मैं किसी इकाई मैपिंग में कस्टम नीति जोड़ता हूं, तो माइग्रेशन v2 -> v3 के लिए काम करने से इंकार कर देता है।मानचित्रण नीति नहीं बनाई जा सकी - आईओएस कोर डाटा

कस्टम प्रवासन नीति:

import Foundation 
import CoreData 

class ObjectCustomV2V3Migration: NSEntityMigrationPolicy { 

override func createDestinationInstancesForSourceInstance(sInstance: NSManagedObject, entityMapping mapping: NSEntityMapping, manager: NSMigrationManager, error: NSErrorPointer) -> Bool { 

    var newObject:NSManagedObject? = NSEntityDescription.insertNewObjectForEntityForName(mapping.destinationEntityName!, inManagedObjectContext: manager.destinationContext) as? NSManagedObject 

    // Sets attr31 - string attribute 
    var str:String = sInstance.valueForKey("attr21") as String 
    if str == "" { 
     str = "BlanketyBlank" 
    } 
    newObject?.setValue(str, forKey: "attr31") 

    // Sets attr32 (int16 attribute) as double of value in previous version 
    // ignore the dodgy type casting. 
    var num:Int = sInstance.valueForKey("attr22") as Int 
    num *= 2 
    var num16 = NSNumber(integer: num) 

    newObject?.setValue(num16, forKey: "attr32") 



    if newObject != nil { 
     manager.associateSourceInstance(sInstance, withDestinationInstance: newObject!, forEntityMapping: mapping) 
     return true 
    } 


    return false 


    } 
} 

और जब मैं अनुप्रयोग चलाने, निम्नलिखित त्रुटि है:

NSUnderlyingException=Couldn't create mapping policy for class named (ObjectCustomV2V3Migration) 

मैं:

2015-07-10 14:32:42.952 SingleDBMigration[2153:739674] CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/6C142EC2-02DB-4BD6-8428-5739C57C7795/Documents/SingleDBMigration.sqlite options:{ 
    NSInferMappingModelAutomaticallyOption = 0; 
    NSMigratePersistentStoresAutomaticallyOption = 1; 
} ... returned error Error Domain=NSCocoaErrorDomain Code=134110 "The operation couldn’t be completed. (Cocoa error 134110.)" UserInfo=0x17ecad70 {NSUnderlyingException=Couldn't create mapping policy for class named (ObjectCustomV2V3Migration)} with userInfo dictionary { 
    NSUnderlyingException = "Couldn't create mapping policy for class named (ObjectCustomV2V3Migration)"; 
} 
2015-07-10 14:32:42.965 SingleDBMigration[2153:739674] Unresolved error Optional(Error Domain=YOUR_ERROR_DOMAIN Code=9999 "Failed to initialize the application's saved data" UserInfo=0x17eaf880 {NSLocalizedDescription=Failed to initialize the application's saved data, NSUnderlyingError=0x17ecad90 "The operation couldn’t be completed. (Cocoa error 134110.)", NSLocalizedFailureReason=There was an error creating or loading the application's saved data.}), Optional([NSLocalizedDescription: Failed to initialize the application's saved data, NSUnderlyingError: Error Domain=NSCocoaErrorDomain Code=134110 "The operation couldn’t be completed. (Cocoa error 134110.)" UserInfo=0x17ecad70 {NSUnderlyingException=Couldn't create mapping policy for class named (ObjectCustomV2V3Migration)}, NSLocalizedFailureReason: There was an error creating or loading the application's saved data.]) 
महत्वपूर्ण हिस्सा बनने के साथ

मैंने इस समस्या पर पाया कुछ प्रश्नों की कोशिश की है, और उनमें से कोई भी कोई संतोषजनक समाधान प्रदान नहीं किया है। अगर मैं इस मुद्दे पर कोई प्रकाश डाल सकता हूं तो मैं बहुत आभारी हूं!

धन्यवाद!

उत्तर

27

मैंने अंततः एक समान प्रश्न के उत्तर को समझने के बाद इसे हल किया। मैं परियोजना नाम स्थान जोड़ने के लिए भूल गया था, इसलिए बल्कि मानचित्रण मॉडल में ObjectCustomV2V3Migration के रूप में कस्टम नीति नाम की स्थापना की तुलना में, मैं ProjectModuleName.ObjectCustomV2V3Migration इस्तेमाल किया जाना चाहिए था।

+0

मैं भी हल, लेकिन मैं अपने कार्यान्वयन बदल दिया है। मेरे मामले में मैं कस्टम नीति के बजाय 'फ़िल्टर पूर्वानुमान' विकल्प का उपयोग कर सकता था। त्रुटि आप – gfpacheco

+1

खुशी मिल रहे थे समझने के लिए ऊपर आप इसे हल :) काश XCode अधिक उपयोगी त्रुटि संदेश था, या कम से कम और अधिक विस्तृत व्याख्या! – MadAsAHatter

+0

आपको बहुत बहुत धन्यवाद :) 4-5 घंटे से संघर्ष कर रहा था। – Srikanth

0

मेरा मुद्दा यह था कि मेरे प्रोजेक्ट नाम में रिक्त स्थान थे, इसलिए मानचित्रण मॉडल संपादक में कस्टम नीति को स्विफ्ट मॉड्यूल नाम निर्दिष्ट करते समय रिक्त स्थान के बजाय अंडरस्कोर का उपयोग करके निर्दिष्ट किया जाना चाहिए।

उदाहरण के लिए, मेरे एप्लिकेशन का नाम नामित परियोजना में MyCustomMigrationPolicy वर्ग निर्दिष्ट करने के लिए, मैं संपादक में निम्नलिखित कस्टम नीति का प्रयोग किया:

My_App_Name.MyCustomMigrationPolicy

संबंधित मुद्दे