I’ve considered turning textString into a to-many relationship by creating a Token entity but I’m unsure whether this will significantly increase overhead? I expect my database to grow very large unless I apply unique constraints on tokens and handle the CloudKit syncing myself (not using NSPersistentCloudKitContainer).
Also in my app if many results are fetched (between 1000 to 100,000 matches) from the predicate I will need to perform an additional filter that can only be done in-memory, in this scenario would I need to perform both the predicate and filter in batches?
Post
Replies
Boosts
Views
Activity
Do you already know all the workplace names or are they fetched from a server?
If you already have the names then you could simply create an enum that conforms to CaseIterable and then if you're using SwiftUI you would have a Picker that loops over allCases from which the user would pick from.
It would be helpful if you showed some code for your SwiftData models so we can provide more specific answers. It's not clear what data you're trying to persist and whether not a workplace is also a SwiftData model.
It seems that SwiftData ignores static properties. When I add one to the SwiftData template Item model, the shared property isn't persisted.
@Model
final class Item {
var timestamp: Date
static var shared: Int = 0
init(timestamp: Date) {
self.timestamp = timestamp
Item.shared += 1
}
}
In my original scenario it seems my options are:
Save an identifier to a Node instance in NSUbiquitousKeyValueStore and on relaunches of the app to somehow use that to fetch the Node from the container and assign it to the Singleton node property.
Make the Singleton class a regular SwiftData model without static properties but to make sure only one object is ever saved.
Does anyone with experience using NSUbiquitousKeyValueStore be able comment on whether option one is feasible?
This seems to be a common issue especially for people outside of the US, I'm from the UK and had problems with enrolment. It took 2-3 weeks for it to be resolved for me.
At first the Developer app wasn't recognising my ID and would present errors but after a few days my account was locked from enrolling. The impression I got from Apple Support was because I was attempting to enrol from my Mac, iPhone and through the website, my account was flagged as potentially fraudulent. If this happens your only solution is to contact Apple Support and try to speak on the phone to a more senior person, in my case a Senior Advisor and politely request their operations team to send you an email which contains a website link where you can securely upload your ID such as your passport.
If you haven't been locked out from enrolling yet, my advice is to use the website. I think it's more reliable than enrolling through the Developer apps. Hope this helps.
Thank you for responding to my question. Below is a simplified code example that displays two SF Symbol images on a Grid View, as seen in the gif. I've included a basic DragGesture but I have a feeling it isn't the right approach. In order for it to work the onEnded closure would need to somehow map the offset coordinate into a Square enum case so that I could update the ModelState. I intend for the board and pieces to scale to fit the available space so the size of the squares won't be known beforehand, making the coordinate mapping difficult. Maybe **GeometryReader ** could solve that but I could see the code becoming a mess. I see other drag and drop methods in the documentation, surely one them is designed to better fit this use case. dropDestination seems like a suitable candidate but I think read somewhere that it doesn't work with SF Symbols. I'm looking for guidance from someone familiar with Apple's documentation because they provide little explanations themselves (I've watched WWDC videos). Also there appears to be a clipping issue with the DragGesture within the Grid, changing the zindex of the images didn't fix that for me.
enum Square: Int { case a, b, c, d }
struct PieceView: View {
@State var offset: CGSize = .zero
var drag: some Gesture {
DragGesture()
.onChanged { value in offset = value.translation }
.onEnded{ value in offset = .zero }
}
var body: some View {
Image(systemName: "circle.fill")
.resizable().scaledToFit()
.foregroundColor(.black)
.offset(offset)
.gesture(drag)
}
}
struct SquareView: View {
let color: Color
let square: Square
@ObservedObject var state: ModelState
var body: some View {
color.overlay(state.pieces[square])
}
}
class ModelState: ObservableObject {
@Published var pieces: [Square: PieceView] = [.a: PieceView(), .b: PieceView()]
}
struct BoardView: View {
@StateObject var state: ModelState = ModelState()
var body: some View {
Grid {
ForEach(0..<2, id: \.self) { row in
GridRow {
ForEach(0..<2, id: \.self) { column in
SquareView(
color: (row + column).isMultiple(of: 2) ? Color(.cyan) : Color(.white),
square: Square(rawValue: 2*row + column)!,
state: state
)
}
}
}
}
}
}