Posts

Post not yet marked as solved
2 Replies
683 Views
I want to check the contents of an NSItemProvider to validate a drop action in SwiftUI on macOS. I use the code: let urlProviders = info.itemProviders(for: [.url]) if urlProviders.filter({ $0.canLoadObject(ofClass: NSImage.self) }).some { return true } But I get the compilation error: Instance method 'canLoadObject(ofClass:)' requires that 'NSImage' conform to '_ObjectiveCBridgeable' Is this a bug? The same code works with UIImage when compiling for iOS. Xcode 13.4
Posted
by Gillies.
Last updated
.
Post not yet marked as solved
0 Replies
797 Views
When trying to copy photos from the Photos app using my Share Extension I am regularly getting an error: Error copying file type public.jpeg. Error: Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.jpeg" UserInfo={NSLocalizedDescription=Cannot load representation of type public.jpeg, NSUnderlyingError=0x117f16640 {Error Domain=NSItemProviderErrorDomain Code=-1 "Cannot copy file at URL ...[].jpg., NSUnderlyingError=0x117f45ce0 {Error Domain=NSItemProviderErrorDomain Code=-1 "Cannot create a temporary file. Error: Undefined error: 0" UserInfo={NSLocalizedDescription=Cannot create a temporary file. Error: Undefined error: 0}}}}} I have seen this error elsewhere on the forums linked to PHPickerViewController and bug 64630315. Bug 64630315 is claimed fixed on iOS, but might it still be an issue on macOS? My Share Extension works correctly on iOS. On macOS I see this error when trying to share photos that I didn't take, but have been added to my library manually, via WhatsApp for example. Everything works as expected when sharing Live or Portrait images taken by me. I am trying to share as jpg. Photos that fail on macOS share as expected on iPhone from the same library.
Posted
by Gillies.
Last updated
.
Post not yet marked as solved
2 Replies
541 Views
I am trying to deduplicate data created by NSPersistentCloudKitContainer in my app. I have a universal app, with Share Extensions on both macOS and iOS. On each platform I share a store between the app and the extension with an App Group. The app and the extensions are both configured to sync to CloudKit. (This means local sharing is handled when offline, and a remote share extension will sync to CloudKit work when the main app is closed) This configuration is causing duplicates to be generated. I believe this is because when the macOS app is open, both it and the macOS share extension will try and (almost simultaneously) sync a newly shared object, resulting in two copies in CloudKit. On the macOS app, I can look through the persistent history and see the insertion 'author'. The first insertion is made by the extension "macOSShareExtension", the second is made by "NSCloudKitMirroringDelegate.import". I could easily make a choice to delete the second object. However, at the same time, on the iOS app, I will get two insertions, both with the author "NSCloudKitMirroringDelegate.import". I don't want to deduplicate only on the macOS app in this case. That would mean the the iOS app has duplicate objects until the deduplication propagates. If I use CKRecord's creationDate to keep the first syncd Object, can I guarantee that if one Object has an associated CKRecord and the other doesn't, the one with out will subsequently gain a record with a later creationDate? Should I be taking a different approach? Thank you.
Posted
by Gillies.
Last updated
.
Post marked as solved
1 Replies
1.3k Views
I am creating a Safari App Extension for users to save web links and quotes to my app. I would like to cache web page metadata when links are saved by the extension. I am using a context menu command to capture information with the code below. override func contextMenuItemSelected( withCommand command: String, in page: SFSafariPage, userInfo: [String : Any]? = nil) { switch command { case "sendToApp": Task { guard let properties = await page.properties(), let pageURL = properties.url else { return }                 let provider = LPMetadataProvider()                 provider.timeout = 0.01                 os_log("*** Starting metadata call ***")                 let metadata = try? await provider.startFetchingMetadata(for: pageURL)                 os_log("*** Continued past metadata call ***") // ...             }         } I get the log: *** Starting metadata call *** LPMetadataProvider<1>: start fetching for URL ...but I am never seeing the log "*** Continued past metadata call ***" I wonder if the task is being killed for some reason? I thought maybe async code was an issue in SFSafariExtensionHandler, but the first await call in the guard passes successfully. I thought that the default timeout of 30s on LPMetadataProvider may be too great, but it still fails with a tiny timeout of 0.01s. I have added com.apple.security.network.client to the entitlements of the extension. Is there something I am missing please?
Posted
by Gillies.
Last updated
.
Post not yet marked as solved
0 Replies
485 Views
Hello My application uses NSOutlineViews with a floating group row as the title. In previous versions of macOS I have had a semi-transparent background to my heading, so scrolling rows can be seen underneath. In Big Sur there is a solid background to my floating row, and a thin border drawn on the bottom edge. I can see no way of stopping this background being rendered! I have a custom NSOutlineView with all drawing overridden: override func draw(_ dirtyRect: NSRect) {} I have a custom NSTableRowView with the same override. If I set the NSTableRowView that is floating to hidden, the background and border are still visible. The parent view of the floating row (a subview of NSScrollView) has the same dimensions as the whole scroll view, so I suspect the background is being drawn into this view, but by what!? Any ideas welcome please.
Posted
by Gillies.
Last updated
.
Post not yet marked as solved
0 Replies
398 Views
I have an NSManagedObject with an NSOrderedSet to-many relationship named 'children'. I am observing changes to this set using the following:addObserver(self, forKeyPath: #keyPath(children), options: [], context: nil)This can be called only once in the initialisation of a lazy property on the NSManagedObject. Any new relations are added in a child NSManagedObjectContext, and then saved down to my main context. When I set the relationship, I use the following code, only setting the 'many' side of the relationship from the 'one':superpoint.insertIntoChildren(self, at: 0)insertIntoSubpointChildren is an autogenerated accessor.In the child NSManagedObjectContext I see a single correct call to observeValue(forKeyPath..., that gives me the correct insertion index on children, when the above insertion code is called.However, when I save to the parent NSManagedObjectContext I am seeing two calls to observeValue(forKeyPath... on the same object. The first call is for an insertion at the end of the NSOrderedSet. The second call is for an insertion at the correct position.When evaluating the NSOrderedSet in each observation call, the new object is indeed at the position described - it is on the end of the set on the first call, and then moved to the correct position on the second call. However, I get no call to say that it was removed from the end position.I am not sure if I have set something up incorrectly here. The many objects in my one-many relationship will be unique, so I could write the code to work around this, but that feels wrong.I have replicated this issue in a simple project here: Github: /GilesHammond/KVO-Core-Data-Extra/Run in debug and select "ADD CHILD" multiple times from the app Main Menu. Observe the debug output showing the extra erroneous observation on the main NSManagedObjectContext.Any thoughts on what I might be doing wrong?
Posted
by Gillies.
Last updated
.
Post not yet marked as solved
1 Replies
771 Views
I am seeing a crash when trying to clear an NSKeyValueObservation on an NSOrderedSet on a NSManagedObject.I am trying to set the observation to nil in willTurnToFault but I get an EXC_BAD_ACCESS doing so.Trying to call invalidate() on the NSKeyValueObservation has no effect in willturnToFault(), and an error will follow: "...deallocated while key value observers were still registered with it."I have created a simple project that replicates the issue when run in debug:Github - /GilesHammond/KVO-Core-Data-Crash The definition of the crashing NSManagedObject is below. Any insights greatly appreciated!Thank you.public class Matter: Point { override public func awakeFromFetch() { super.awakeFromFetch() print("\(hosts)") // Initialise lazy member and set observation } public override func willTurnIntoFault() { super.willTurnIntoFault() hostsObservation = nil // &lt;-- EXC_BAD_ACCESS } @objc dynamic public internal(set) lazy var hosts: [Point] = { hostsObservation = observe(\.hostConnections_) { [unowned self] data, change in } // Empty observation closure return [] }() private var hostsObservation: NSKeyValueObservation? } // Matter+CoreDataProperties.swift - auto generated extension Matter { @nonobjc public class func fetchRequest() -&gt; NSFetchRequest { return NSFetchRequest(entityName: "Matter") } @NSManaged public var hostConnections_: NSOrderedSet? }
Posted
by Gillies.
Last updated
.
Post not yet marked as solved
1 Replies
733 Views
I do not know, and cannot find, the standard technical term for the drag-select functionality when the alt/option button is pressed when hovering over an NSTextView.When alt is pressed, the crosshair appears and text can be selected/highlighted in columns/vertically, as in Xcode.I would like to disable this functionality in my NSTextViews, how can I do that please?
Posted
by Gillies.
Last updated
.