Posts

Post not yet marked as solved
1 Replies
1.1k Views
I am trying to render a list of entities that are split into sections (think CoreData NSFetchedResultsSectionInfo). This my solution, however it renders poorly. The ScrollView is far too long, scrolling is not fluid and may freeze. struct SectionsGridView: View { let results: Sections<ListItemViewModel> let columns = [ GridItem(.adaptive(minimum: .cellSize)) ] var body: some View { ScrollView { LazyVGrid(columns: columns, spacing: .gridSpacing, pinnedViews: .sectionHeaders) { ForEach(results) { section in Section(header: Text(section.title?.uppercased() ?? "error")) { ForEach(section) { item in GridCell().environmentObject(item) } } } } } } } private extension CGFloat { static let gridSpacing = 8.0 static let cellSize = 100.0 } I believe this solution (or very similar) used to be in the documentation. I have tried several ways of doing this, either I get the scrolling issue or pinnedViews won't pin.
Posted
by jeremy51.
Last updated
.
Post not yet marked as solved
2 Replies
1.2k Views
I have a CoreData model, in a Swift Package with tests. I can successfully run the tests, when I load the model using NSPersistentContainer, however attempting this with NSPersistentCloudKitContainer always fails in the call to loadPersistentStores(completionHandler block: @escaping (NSPersistentStoreDescription, Error?) -> Void) The error is : [CK] BUG IN CLIENT OF CLOUDKIT: Not entitled to listen to push notifications. Please add the 'aps-connection-initiate' entitlement. This issue is described on StackOverflow however, the accepted solution does not appear to work in my case. I have tried adding the aps-connection-initiate key to my App Info.plist, the Test Info.plist and the SPM bundle. No change. (NB. adding this to the entitlements file just breaks auto signing). I have enabled App entitlements for App Groups, Remote Notifications background mode, Push Notifications and iCloud CloudKit with a store identifier. I have checked my model. All relationships have inverses. No unique constraints, etc. etc. I am sharing a Bundle ID with a previous version of the App, that also uses CoreData+CloudKit, each version has it's own Model and container identifier, each container identifier is available in the provisioning profile. The new version of the model has two NSPersistentStoreDescriptions, one is configured for CloudKit, the other is a local cache. I am completely stuck, suggestions would be very welcome.
Posted
by jeremy51.
Last updated
.
Post not yet marked as solved
0 Replies
1.1k Views
I am prototyping an iOS App in Swift Playgrounds. The App has Drag & Drop features internally using custom identifiers. The data that is being moved around is a struct that contains a deeplink URL that can be used to identify my models. I have three different entities to deal with. One is identified with a UTI com.example.item, the other two as com.example.collection. Items may be dropped onto Collections and visa versa, but the same type my not be dropped onto itself. For onDrag(_:) I produce an NSItemProvider and register the entity using registerDataRepresentation(forTypeIdentifier: visibility: loadHandler:). The ‘loadHandler’ encodes the URL of the entity as Data. I use the appropriate custom UTI String for the entity. So far so good, I can see that the right UTI String has been registered by examining the NSItemProvider. For onDrop(of:delegate:) I provide the valid UTI (this filter does not seem to be honoured) and a custom class implementing DropDelegate, giving it a reference to the entity at the drop target. As the filter does not seem to work, my DropDelegate implements func validateDrop(info: DropInfo) -> Bool. In this function, I attempt to filter which drops are valid by calling info.hasItemConformingTo(_:) and checking against the drop target. What I am finding is that even though I can see my custom UTI strings have been registered in the NSItemProviders, they are never visible when calling hasItemConformingTo(_:). In this situation I would be unable to implement performDrop AFAICS. I wonder if this problem is to do with my misunderstanding of how Drag & Drop works (I have also attempted other approaches like registering custom Objects with the NSItemProvider, but have the same problem. Is this possibly caused by my environment? As I am writing this prototype in Swift Playgrounds, where there is no Info.plist, so I am unable to register custom UTI schemes? Many thanks for any suggestions.
Posted
by jeremy51.
Last updated
.
Post not yet marked as solved
4 Replies
5.3k Views
I am writing a SwiftUI App in Xcode 12.0 beta (12A6159), the app is intended to work on iOS13.5 and up. I am instantiating ObservableObjects at one level of my View hierarchy in the View's init() function, passing them as appropriate using .environmentObject, then attempting to pick them up in @EnvironmentObject in Views several layers deeper. The consuming Views are getting the error: A View.environmentObject(_:) for ********* may be missing as an ancestor of this view. After careful testing, I find that the EnvironmentObjects are not being passed through NavigationLink. We already have the well known issue of these not being passed through .sheet presentation (a major inconvenience), now we are contending with the same issue with NavigationLink? Is this intentional or a bug? Is there a workaround? It is definitely not what I would consider my preferred design.
Posted
by jeremy51.
Last updated
.
Post not yet marked as solved
2 Replies
2.7k Views
I am writing a SwiftUI App using CoreData + CloudKit, based partly on sample code from `CoreDataCloudKitDemo`.There is a MasterListView which presents a List of NavigationLinks of the available data, eg. Recents, Tags, etc. embedded in a Double Column Style NavigationView.There are 6 @FetchRequest vars that collect the content for the different Sections in the List.They look similar to this:@FetchRequest(fetchRequest: ThingViewModel.fetchRequest(matching: .recent)) var recentThings:FetchedResults&lt;Thing&gt;Where the .fetchRequest(matching: .recent) is producing a FetchRequest with Predicate and SortDescriptors.The problems start when I use this in MultiTasking mode on an iPad. The user adds new data to the App using a Share Extension.If I have the App side by side with another App that can share to it, the share is successful, I can see the data go into CoreData and the MasterListView re-draws by the logs but the actual data is not reliably refreshed.I have logging in the MasterListView to tell me when it re-draws and when it receives a Notification from the core data stack that there has been an update.The core data stack is running a NSPersistentHistoryChangeRequest, filtering out the added Thing successfully, so I know it is there.I have tried everything I can think of, including things like: NSManagedObjectContext.mergeChanges(fromRemoteContextSave:into:) viewContext.stalenessInterval = 0 viewContext.refreshAllObjects() viewContext.stalenessInterval = -1And everything else I have found on SO ;-)What am I missing?
Posted
by jeremy51.
Last updated
.
Post not yet marked as solved
4 Replies
1.8k Views
Hi AllI am developing a CoreData + CloudKit App for iOS, based partly on the code in CoreDataCloudKitDemo.The intention of the App is that content will be used in the App but added from a Share Extension.The CoreData Store is configured to reside in a shared App Group.Addition and editing of content is functioning but I find that when new content is saved to CoreData from the Share Extension, data does not get pushed to CloudKit until the App itself is brought to the foreground. Which clearly is not the requirement.Saves made within the App itself eg. from an edit, are pushed to CloudKit immediately.How do I ensure this happens from the Share Extension?
Posted
by jeremy51.
Last updated
.
Post marked as solved
6 Replies
3.8k Views
I am writing an app based around DoubleColumnNavigationViewStyle (eg. SplitView).I would like to drag entities from the MasterList onto entities in the Detail View to form coredata relationships between them.My models implement NSItemProviderWriting and NSItemProviderReading.I find I can make a NavigationLink draggable by adding this to it:.itemProvider { () -&gt; NSItemProvider? in return NSItemProvider(object: self.model) }When a drag is instigated from here, the model's NSItemProviderWriting protocol functions are invoked.What I cannot work out is how to make a View 'Dropable'.All of the likely looking ViewModifiers are implemented on MacOS only, as far as I can see.There must be something that takes a list of supported type identifiers and invokes NSItemProviderReading.There is also something strange going on ...Not all of my NavigationLinks have a .itemProvider but once one of them does, they all act draggable, which is not the desired outcome.Are these known bugs or omissions?
Posted
by jeremy51.
Last updated
.
Post not yet marked as solved
1 Replies
813 Views
I am writing an iOS app for collecting URLs.The app has a Share Extension intended for use in other app (eg. Safari) to add a URL to the app.The app is also able to share it's URLs.When you trigger the share sheet, the app's own share extension appears as an option, this seems silly.How can I stop this from happening?
Posted
by jeremy51.
Last updated
.
Post not yet marked as solved
1 Replies
485 Views
I am writing an app using SwiftUI which keeps it's data in CoreData + CloudKit.I have been writing the App's search functionality.Search exists in two different contexts in the App, one where you create entities and one where you can find existing entities.I have written a simple SearchField and SearchPublisher and am using them in two different Views.The SearchField wraps a UISearchBar in UIViewRepresentable, has a String @Binding held as @State in the Views and calls a closure on change, which performs a search.SearchField(text: self.$searchString, placeholder: "Search for Things", onEditingChanged: { _ in self.thingSearch.search(self.searchString) })SearchPublisher extends ObservableObject and @Published an Array of hits.Each time the user types a character in the SearchField, the search function in the SearchPublisher is called with the accumulated String, a FetchRequest and predicate is generated and performed on a global DispatchQueue and the results sent by setting them on the @Published var, on the main queue.So far, so good.My first usage of this code was used in a presented Sheet, used during entity creation and worked as expected.A while later and I get around to adding the search function for existing entities as a View reached by navigation in a List from a NavigationLink.To my consternation, almost exactly the same code behaves completely differently.They both redraw for each character typed (as expected) but in one, the @State is lost each time. Also the sequence of calls within each view (the one in the Sheet and the one not in a Sheet) are different to each other (instantiation, access to the body var etc.).I have spent a long time looking for any subtle differences between the two Views.Eventually it comes down to the only difference being one is presented via .sheet() and the other via NavigationLink.When I present the 'broken' one via Sheet instead of Navigation, it works as expected.I am at a complete loss to understand this difference in behaviour, has anyone got any suggestions?
Posted
by jeremy51.
Last updated
.
Post not yet marked as solved
1 Replies
818 Views
Hi All.I have a view which switches between a summary and edit mode, using an EditButton.Some of the edits are complex enough to require a sub view. For instance, I need a search field to filter certain options.I find that when the view is in edit mode, all types of navigation are disabled: Button raising a sheet is not working. NavigationLink pushing a seperate view is not working.Can anyone confirm this is the case?Is this intentional or a bug?Many thanks.
Posted
by jeremy51.
Last updated
.