Post

Replies

Boosts

Views

Activity

Reply to [SwiftUI] multiple NSPersistentContainer generate error: A fetch request must have an entity.
This is an example code that generate error ... Why I cannot loadPersistentStores with 2 sqlite files ? import CoreData struct PersistenceController {     static let shared = PersistenceController()     let container: NSPersistentContainer let container2: NSPersistentContainer func urlApplicationSupportDirectory() -> URL { let paths = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask) let documentsDirectory = paths[0] return documentsDirectory } func sqliteURL() -> URL { let url = urlApplicationSupportDirectory().appendingPathComponent("MM1.SQLite") return url } func sqliteURL2() -> URL { let url = urlApplicationSupportDirectory().appendingPathComponent("MM2.SQLite") return url } init(inMemory: Bool = false) {         container = NSPersistentContainer(name: "testCoreData") container2 = NSPersistentContainer(name: "testCoreData")         if inMemory {             container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")         } let url = sqliteURL() print(url.absoluteString) let description = NSPersistentStoreDescription(url: url) description.shouldMigrateStoreAutomatically = true description.shouldInferMappingModelAutomatically = true container.persistentStoreDescriptions = [description]         container.viewContext.automaticallyMergesChangesFromParent = true         container.loadPersistentStores(completionHandler: { (storeDescription, error) in             if let error = error as NSError? {                 fatalError("Unresolved error \(error), \(error.userInfo)")             }         }) let url2 = sqliteURL2() print(url2.absoluteString) let description2 = NSPersistentStoreDescription(url: url2) description2.shouldMigrateStoreAutomatically = true description2.shouldInferMappingModelAutomatically = true container2.persistentStoreDescriptions = [description2] container2.viewContext.automaticallyMergesChangesFromParent = true container2.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError("Unresolved error \(error), \(error.userInfo)") } }) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’22
Reply to When I try to pass parameter to @FetchRequest, how to solve?
Thank you for your reply. However for your first solution, Xcode still show the same error message. 2nd solution is work fine but it is not my solution for multiple view with parameter (accountType). I want to make multiple view with difference accountType by using same SwiftUI file (object). Do you have any more suggestion?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’22
Reply to [SwiftUI] multiple NSPersistentContainer generate error: A fetch request must have an entity.
This is an example code that generate error ... Why I cannot loadPersistentStores with 2 sqlite files ? import CoreData struct PersistenceController {     static let shared = PersistenceController()     let container: NSPersistentContainer let container2: NSPersistentContainer func urlApplicationSupportDirectory() -> URL { let paths = FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask) let documentsDirectory = paths[0] return documentsDirectory } func sqliteURL() -> URL { let url = urlApplicationSupportDirectory().appendingPathComponent("MM1.SQLite") return url } func sqliteURL2() -> URL { let url = urlApplicationSupportDirectory().appendingPathComponent("MM2.SQLite") return url } init(inMemory: Bool = false) {         container = NSPersistentContainer(name: "testCoreData") container2 = NSPersistentContainer(name: "testCoreData")         if inMemory {             container.persistentStoreDescriptions.first!.url = URL(fileURLWithPath: "/dev/null")         } let url = sqliteURL() print(url.absoluteString) let description = NSPersistentStoreDescription(url: url) description.shouldMigrateStoreAutomatically = true description.shouldInferMappingModelAutomatically = true container.persistentStoreDescriptions = [description]         container.viewContext.automaticallyMergesChangesFromParent = true         container.loadPersistentStores(completionHandler: { (storeDescription, error) in             if let error = error as NSError? {                 fatalError("Unresolved error \(error), \(error.userInfo)")             }         }) let url2 = sqliteURL2() print(url2.absoluteString) let description2 = NSPersistentStoreDescription(url: url2) description2.shouldMigrateStoreAutomatically = true description2.shouldInferMappingModelAutomatically = true container2.persistentStoreDescriptions = [description2] container2.viewContext.automaticallyMergesChangesFromParent = true container2.loadPersistentStores(completionHandler: { (storeDescription, error) in if let error = error as NSError? { fatalError("Unresolved error \(error), \(error.userInfo)") } }) } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Jun ’22
Reply to SwiftUI did NOT support 2 CoreData containers ?
I'm sorry for broken link. Here is correct one. https://www.dropbox.com/s/wn1lxwmafg3fp63/testCoreData3.zip?dl=0
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to SwiftUI did NOT support 2 CoreData containers ?
I don't know why the link is changed automatically when I post. The ** in link should be wn.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to SwiftUI did NOT support 2 CoreData containers ?
I don't know why the link is changed automatically when I post. The ** in link should be w and n
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22
Reply to SwiftUI did NOT support 2 CoreData containers ?
I don't know why w and n is changed to be ** !!? So please refer this link instead. https://www.dropbox.com/s/8vhicr4y07v5kj7/testCoreData03.zip?dl=0
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Dec ’22