Post

Replies

Boosts

Views

Activity

DropInfo doesn't contain my drag object in SwiftUI
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.
1
0
626
Dec ’22
App installed outside of Xcode interrupts library code
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.
1
0
645
Jan ’23
How do I filter @Query with bound item
I have a few that is passed an item of type FamilyMember. Available in the view is a list of Chores. A chore has a member assigned to it. I want to filter the chores to the passed family member. 2 Structures and view code: @Model class Chore: Identifiable { @Attribute(.unique) var id = UUID() var name: String var frequency: ChoreFrequency var assignedTo: FamilyMember var isComplete: Bool var dueDate: Date init(id: UUID = UUID(), name: String = "", frequency: ChoreFrequency = .daily, assignedTo: FamilyMember = FamilyMember(), isComplete: Bool = false, dueDate: Date = Date()) { self.name = name self.frequency = frequency self.assignedTo = assignedTo self.isComplete = isComplete self.dueDate = dueDate } } @Model class FamilyMember: Identifiable { @Attribute(.unique) var id: String { name } var name: String init(name: String = "Unassigned") { self.name = name } } struct MemberView: View { @Bindable var member: FamilyMember @Query private var chores: [Chore] init(member: FamilyMember) { self.member = member let predicate = #Predicate<Chore> { $0.assignedTo == member // <— Error occurs here! } _chores = Query(filter: predicate, sort: \.dueDate) } . . . It's when creating the predicate that I'm running to an error of value conversion. Cannot convert value of type 'PredicateExpressions.Equal<PredicateExpressions.KeyPath<PredicateExpressions.Variable<Chore>, FamilyMember>, PredicateExpressions.Value<FamilyMember>>' to closure result type 'any StandardPredicateExpression<Bool>' What am I doing wrong?
2
0
1.3k
Sep ’23