2016-04-30 6 views
13

दुर्घटनाओं मैं एक InMemory स्टोर समन्वयक घोषित तो की तरह है:बैच हटाने अनुरोध एप्लिकेशन

lazy var ramStoreCoordinator: NSPersistentStoreCoordinator = { 
    // The persistent store coordinator for the application. This implementation creates and returns a coordinator, having added the store for the application to it. This property is optional since there are legitimate error conditions that could cause the creation of the store to fail. 
    // Create the coordinator and store 
    let coordinator = NSPersistentStoreCoordinator(managedObjectModel: self.managedObjectModel) 
    var failureReason = "There was an error creating or loading the application's saved data." 
    do { 
     try coordinator.addPersistentStoreWithType(NSInMemoryStoreType, configuration: nil, URL: nil, options: nil) 
    } catch { 
     // Report any error we got. 
     var dict = [String: AnyObject]() 
     dict[NSLocalizedDescriptionKey] = "Failed to initialize the application's saved data" 
     dict[NSLocalizedFailureReasonErrorKey] = failureReason 

     dict[NSUnderlyingErrorKey] = error as NSError 
     let wrappedError = NSError(domain: "YOUR_ERROR_DOMAIN", code: 9999, userInfo: dict) 
     // Replace this with code to handle the error appropriately. 
     // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development. 
     NSLog("Unresolved error \(wrappedError), \(wrappedError.userInfo)") 
     abort() 
    } 

    return coordinator 
}() 

के साथ-साथ एक संबद्ध ManagedObjectContext:

lazy var ramManagedObjectContext: NSManagedObjectContext = { 
    // Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.) This property is optional since there are legitimate error conditions that could cause the creation of the context to fail. 
    let coordinator = self.ramStoreCoordinator 
    var managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType) 
    managedObjectContext.persistentStoreCoordinator = coordinator 
    managedObjectContext.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy 
    return managedObjectContext 
}() 

मैं एक तो जैसे अनुरोध लाने निष्पादित करने के लिए कोशिश कर रहा हूँ :

let fetchRequest = NSFetchRequest(entityName: "Post") 
    let batchDelete = NSBatchDeleteRequest(fetchRequest: fetchRequest) 
    do { 
     // Execute Batch Request 
     try ramManagedObjectContext.executeRequest(batchDelete) 
    } catch { 
     let updateError = error as NSError 
     print("\(updateError), \(updateError.userInfo)") 
    } 

लाइन:

न आया हुआ अपवाद 'NSInternalInconsistencyException', कारण की वजह से * समाप्त एप्लिकेशन

2016-04-30 23:

try ramManagedObjectContext.executeRequest(batchDelete) 

निम्नलिखित उत्पादन के साथ अनुप्रयोग क्रैश हो 47: 40.271 गुप्त [1,047,869 2368]: ' अज्ञात कमांड प्रकार (इकाई: EntityName; भविष्यवाणी करें: ((शून्य)); सॉर्ट डिस्क्रिप्टर: ((शून्य)); टाइप करें: NSManagedObjectIDResultType;)> ' * पहले फेंक कॉल स्टैक: (0x18145ae38 0x180abff80 0x1833710b0 0x18338991c 0x183391d64 0x101121a3c 0x10112d5f0 0x1833845bc 0x1832c1d5c 0x183354e04 0x10011abc4 0x10011947c 0x100092bf0 0x10009269c 0x1000926ec 0x186a1aac0 0x186a1b258 0x186901854 0x186904a4c 0x1866d4fd8 0x1865e0014 0x1865dfb10 0x1865df998 0x183f4da20 0x101121a3c 0x1011274e4 0x181410dd8 0x18140ec40 0x181338d10 0x182c20088 0x18660df70 0x1000fcba8 0x180ed68b8) libc + + abi.dylib: प्रकार NSException के न आया हुआ अपवाद के साथ समाप्त

+2

मैं समझ सकता हूं कि यह स्मृति स्टोर के लिए लागू नहीं किया जा रहा है क्योंकि अनुरोध के पूरे बिंदु को किसी भी SQLite स्टोर सामग्री को इसे हटाने के लिए स्मृति में लोड नहीं करना है ... – Wain

+0

@Wain: तो एक इनमेरी स्टोर के लिए, एक बैच निष्पादन प्रदर्शन के संदर्भ में हर वस्तु पर हटाने के बराबर होगा? तथ्य यह है कि ऐप्पल को इस स्टैंड को दस्तावेज करना चाहिए। – Quantaliinuxite

+0

हां और मैं – Wain

उत्तर

1

NSBatchDeleteRequest, अपने ramStoreCoordinator, नहीं ramManagedObjectContext पर निष्पादित किया जाना चाहिए, क्योंकि यह NSPersistenceStore वर्ग उदाहरण के साथ सीधे काम करता है:

try persistentStoreCoordinator.executeFetchRequest(batchDelete, withContext: ramManagedObjectContext) 

चेक अधिक जानकारी के लिए इस लिंक: https://developer.apple.com/videos/play/wwdc2015/220/

आशा है कि यह मदद की)

+5

से सहमत हूं जो मुझे एक ही दुर्घटना – Quantaliinuxite

2

मैं ठीक उसी समस्या थी। इसे स्मृति स्टोर में NSSQLiteStoreType में बदलकर हल किया गया। मेमोरी स्टोर में ऐसा क्यों होता है, लेकिन मुझे उम्मीद है कि आपकी समस्या हल हो जाएगी।

0

यह त्रुटि तब हो सकती है जब आप XCode के बाहर कुछ फ़ाइलों का नाम बदलते हैं। इसे हल करने के लिए आप बस अपनी प्रोजेक्ट से फ़ाइलों को हटा सकते हैं (राइट क्लिक - डिलीट और "रेफरेंस निकालें") आप अपनी प्रोजेक्ट में फाइलों को फिर से आयात कर सकते हैं और सबकुछ ठीक होगा!

तो यह ठीक नहीं हुआ, इस

try persistentStoreCoordinator.executeFetchRequest(
    batchDelete, withContext:context 
) 

NSBatchDeleteRequest के रूप में लगातार की दुकान समन्वयक, नहीं प्रबंधित वस्तु संदर्भ पर निष्पादित किया जाता है की कोशिश करो।

5

मेरे अनुभव में, NSBatchDeleteRequest NSInMemoryStoreType के साथ काम नहीं करेगा। मैं अपनी विधियों का परीक्षण करने के लिए भी कोशिश कर रहा था, लेकिन मुझे उस पर वापस रोकना होगा।

संपादित करें:

सबूत के रूप में Marcus Zarra's ट्वीट जोड़ा जा रहा है।

+0

देता है यह याद रखने योग्य है कि यदि आपका लक्ष्य ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** ** मेमोरी स्टोर साफ करने के लिए कोई SQLite फ़ाइल नहीं है, इसलिए आप वर्तमान इन-मेमोरी स्टोर में किसी भी संदर्भ को फेंक सकते हैं। –

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