I have these extensions to my NSObject, Codable class:
extension SavingsGoal: NSItemProviderWriting {
public static let typeIdentifier = "com.AaronLBratcher.SavingsGoal.Drag"
public static var writableTypeIdentifiersForItemProvider: [String] { [typeIdentifier] }
public typealias DragHandler = (Data?, Error?) -> Void
public func loadData(withTypeIdentifier typeIdentifier: String, forItemProviderCompletionHandler completionHandler: @escaping DragHandler) -> Progress? {
do {
print("^^^ encoding")
let encoder = JSONEncoder()
encoder.outputFormatting = .prettyPrinted
completionHandler(try encoder.encode(self), nil)
} catch {
completionHandler(nil, error)
}
return nil
}
}
extension SavingsGoal: NSItemProviderReading {
public static var readableTypeIdentifiersForItemProvider: [String] { [typeIdentifier] }
public static func object(withItemProviderData data: Data, typeIdentifier: String) throws -> SavingsGoal {
print("^^^ decoding")
let decoder = JSONDecoder()
return try decoder.decode(SavingsGoal.self, from: data)
}
}
and these onDrag, onDrop method calls on my Views:
.onDrag { NSItemProvider(object: goal) }
.onDrop(of: [SavingsGoal.typeIdentifier], delegate: viewModel)
Visually the drag works on the simulator, showing a plus when it hits the target View, however only the delegate's performDrop call is made. The loadData and object methods are not called in the extensions and the DropInfo doesn't contain my object.
I have carefully checked and rechecked the code against available examples and cannot find what I did wrong.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I have a sample app here: https://github.com/AaronBratcher/MoneyTrak where, if I install it onto a device from Xcode it runs fine. (Shows a list of accounts) However if I archive and add the .ipa onto the device the database isn't initialized properly and I don't understand why.
When the database is initially created in the AgileDB package, 2 tables should be created: __settings and __tableArrayColumns. If anyone can help, I would greatly appreciate it.
The Encoder and Decoder protocols have this property: var codingPath: [CodingKey] { get }
In my own custom coding class, how do I override this and pass valid CodingKeys? Every document and code example uses the enum to define coding keys.
Thanks.
Is it possible to do Swift Data operations on a background processing event?
I have a normal UIKit project with a package dependency containing some SwiftUI. Opening the package on its own, I can preview the SwiftUI. However, when I have the package as a dependency, I get the dreaded message saying Active scheme does not build this file regardless of choosing the app or package scheme.
Why can't I get a preview?
Using Xcode 16