56 questions
- Bountied 0
- Unanswered
- Frequent
- Score
- Trending
- Week
- Month
- Unanswered (my tags)
0
votes
1
answer
87
views
Convert AnyKeyPath to ReferenceWritableKeyPath with Optionals
Context
Consider this class and the KeyPath instances:
class Foo {
var name: String? = ""
}
var foo = Foo()
let keyPath: ReferenceWritableKeyPath<Foo, String?> = \.name
let ...
2
votes
1
answer
538
views
How to update SwiftData fetch when upgrading to Swift 6?
I've been stuck on this for the past week and I'm asking here out of desperation. I have a project using Swift 5, and I recently enabled "Strict Concurrency Checking" to "Complete" so I can slowly ...
0
votes
0
answers
38
views
Can't Send Keypath across boundary?
From what I understand, it should be ok to send a Keypath over actor boundaries if what it points to is Sendable, and it feels like this should be the case in this snippet?
If not, can someone explain ...
0
votes
1
answer
181
views
Swift #Predicate Macro Crashes for Multiple KeyPath Components
Context
I'm attempting to create a Swift Predicate using the #Predicate macro as shown here:
final class Foo
{
var title: String = ""
var name: String = ""
}
let p = #...
1
vote
1
answer
339
views
How SwiftUI Table sorting work with multiple KeyPathComparator?
I am new to the Swift and the SwiftUI. Trying to understand how sorting works on SwiftUI Table view.
The following code does what I intend to do, but I am not able to understand how does it actually ...
1
vote
1
answer
245
views
Type Parameter Packs: how to return a tuple instead of an array?
To begin with I have this code, which works totally fine:
protocol ComponentAccessible {}
extension ComponentAccessible {
func components<each T>(_ keyPaths: repeat KeyPath<Self, each T&...
1
vote
1
answer
73
views
Best way to copy set of parameters from one object to another
As example I have struct/class:
struct Pet {
var id: String
var name: String
var age: Int
var type: PetType
}
enum PetType: Int {
case cat
case dog
}
Is it possible to write ...
0
votes
1
answer
384
views
Create NSPredicate using generic KeyPath<Root, Value>
This is a simplified version of my code but I'd like to be able to initialise an NSPredicate from a generic KeyPath<Root, Value> but despite persistent attempts I've fallen short. Can anyone ...
0
votes
1
answer
98
views
How to construct key path for encapsulated Toggle accessing a collection
I'm trying to build a new SwiftUI View that encapsulates a Toggle.
The Toggle accesses a collection so that it can show up in a mixed state.
I'm having difficulties constructing the proper KeyPath.
I'...
-1
votes
1
answer
243
views
Swift - Pass a parameter to a KeyPath
SwiftUI modifiers don't allow passing optional values, and I'd really like to handle them in a clean way. E.g.
struct MyView: View {
let accessibilityValue: String?
var body: some View {
...
3
votes
1
answer
867
views
How to animate custom material property in RealityKit?
I can successfully load a custom ShaderGraphMaterial material loaded from a .usda file created with Reality Composer
var shotTrailMaterial : ShaderGraphMaterial? = nil
do {
...
let materialData =...
15
votes
1
answer
1k
views
Crash when sorting SwiftData Query with a SortDescriptor made from a KeyPath with an optional relationship in the chain
I have the following models:
@Model
class Game {
var name: String
var firstReleasedOn: Date?
@Relationship(deleteRule: .cascade, inverse: \QueueEntry.game)
var queueEntry: QueueEntry?
...
1
vote
0
answers
148
views
Getting String representation of Swift ReferenceWritableKeyPath is failed (returns pointer instead of type)
I have a Product class inherited from Realm Object:
@objc class Product: Object {
@Persisted(primaryKey: true) var id: String = ""
@Persisted var externalId: String?
@Persisted ...
0
votes
0
answers
32
views
How to cast KeyPath<CNContact, Array<CNLabeledValue>> to KeyPath<CNContact, Any>
I need to put KeyPath values in an array of type Array<KeyPath<CNContact,Any>>. However, \CNContact.phoneNumbers fails to cast to KeyPath<CNContact,Any>.
Here is my test code:
let ...
0
votes
0
answers
87
views
How can I sort dates in swift realm repository using my own comparator?
Context: I saved a list of objects in realm repository. These objects contain a property of standard type Date. I would like to get a list of those objects back from Realm based on distinct dates ...