Post

Replies

Boosts

Views

Activity

Reply to Multiple commands produce.
I had this issue. I was trying to add two widgets to my project and realized that the intents (for the widget target they are named ConfigurationIntent) needed to have different names for each of the targets. Open the Intents file for the target, change the name, then change the name in the project itself, wherever ConfigurationIntent is in the file, replace with your new name. If the Custom name you choose were Today, the name to use in your project is TodayIntent(). IntentConfiguration(kind: kind, intent: TodayIntent.self, provider: Provider()) { entry in             TodayWidgetView(entry: entry)         }
Jan ’22
Reply to Core Data + CloudKit - I need to get FetchRequest's data into my Model
Here is what I did to get it working, although it isn't what I wanted it does work, in case anyone else is attempting to pull from cloudkit+core data public db and has run into issues with the initial, on-launch, fetch -- This is how I got FetchRequest in SwiftUI working with my need to do additional things with those items as they are pulled into the app. In body of the main view, I call my model when the NavigationItem is being created, and ask it to finish setup for the current item.                         NavigationLink(destination: ItemDetailView(detailViewModel: ItemDetailViewModel(item: item, pairedFavorite: self.itemModel.pairedFavoriteForItem(cloudItem: Item), manager: self.itemModel))) { Text(item.name) And in the model, I have this method var fetchedAlreadyFavoritesReturnedEntities: Bool?     func pairedFavoriteForItem(cloudItem: Item) -> FavoriteItem {                  if allItems.contains(s) == false {             self.allItems.append(cloudItem)         }         if self.fetchedAlreadyFavoritesReturnedEntities == nil && self.allFavoriteItemObjects.isEmpty == true {             let request = NSFetchRequest<FavoriteItem>(entityName: "FavoriteItem")                                       request.sortDescriptors  = [NSSortDescriptor(key: "favoritedState", ascending: true)]             let favoriteRequestFRC =  NSFetchedResultsController(fetchRequest: request,                                                                  managedObjectContext: self.localManagedObjectContext,                                                                  sectionNameKeyPath: nil,                                                                  cacheName: nil)             favoriteRequestFRC.delegate = self             try? favoriteRequestFRC.performFetch()             let fetched: [FavoriteItem]? = favoriteRequestFRC.fetchedObjects                          if let f = fetched {                 self.allFavoriteItemObjects = Set<FavoriteItem>(f)             }             self.fetchedAlreadyFavoritesReturnedEntities = true         }         let results = self.allFavoriteItemObjects.filter {             return ($0.matchingItemUUID!.uuidString == cloudItem.uuid!.uuidString)         }         if results.isEmpty == false {             if let fave: FavoriteItem = results.first {                 s.isFavorite = fave.favoritedState             }             return results.first!         }         else {                         let newFavorite = self.makeFavoriteWithItem(cloudItem)                         self.allFavoriteItemObjects.insert(newFavorite)                                                  return newFavorite         }     }
Sep ’21
Reply to Seeding user's core data store with a pre-made core data database
So I followed these instructions https://stackoverflow.com/questions/40093585/swift-3-preload-from-sql-files-in-appdelegate/40107699 after finding this thread https://developer.apple.com/forums/thread/61745 and found it working well - the issue was that I needed to copy that seed database into the documents folder, then reference it there via NSPersistentStoreDescription, for anyone with the same circumstances.   if FileManager.default.fileExists(atPath:seedDataDestination.path) == false {                 do {                     try FileManager.default.copyItem(at: seededDataURL, to: seedDataDestination)                 } catch {                     print("Error copying seeded data to documents directory!")                 }           }             let persistentDescription = NSPersistentStoreDescription(url:seedDataDestination)
Jul ’20