helvede.net is one of the many independent Mastodon servers you can use to participate in the fediverse.
Velkommen til Helvede, fediversets hotteste instance! Vi er en queerfeministisk server, der shitposter i den 9. cirkel. Welcome to Hell, We’re a DK-based queerfeminist server. Read our server rules!

Server stats:

163
active users

#swift

5 posts5 participants0 posts today

@nerdd

Answer from Perplexity:

To fix this issue, replace unsupported types with alternatives that SwiftData can handle:

For Duration: Use TimeInterval instead, as it is supported by SwiftData.

For Color.Resolved: Avoid using it directly in your models. Instead, store color-related data in a format like RGB values or another supported type.

This ensures compatibility with SwiftData's encoding requirements.

Heeeelp!

What does the following error mean, and how do I fix it? It happens, when I call `modelContext.save()` in a SwiftUI view.

"SwiftData/ModelCoders.swift:105: Fatal error: Composite Coder only supports Keyed Container”

Edit: Solved! It appears SwiftData does not support Duration properties in models. Changing it to a TimeInterval instead fixes it.

Once again I have stumbled onto something I don’t understand.

In the entry point for my app I set a NavigationContext in the environment, and when I run the app and navigate between views, at some random point, it throws the error in the second image, and the debugger indicates it is on the “struct FooApp: App {“ line.

What is going on? Help!

In the subviews I am accessing the context from the env like so: “@ Environment(NavigationContext.self) var context”.

It can be difficult to find a clear, concise explanation of how method dispatch works in Swift, when calls are resolved statically or dynamically, and what that means for performance.

I wrote a post summarizing my learnings, with key cases and examples: nilcoalescing.com/blog/MethodD

Nil CoalescingMethod dispatch mechanisms in Swift: static and dynamic dispatchDive into how static and dynamic dispatch work in Swift, how they affect performance, and how to control method resolution to write faster, more efficient code.
Continued thread

Bingo! This was what I was looking for:

mastodon.social/@__mbh__/11420

By changing the `TimingSession.duration` to a `Duration` (much better alignment of name and type as well), I can now declaratively format the duration like so:

`Text(timingSession.duration, format: .time(pattern: .hourMinuteSecond(padHourToLength: 2)))`

MastodonMichael Bech Hansen (@__mbh__@mastodon.social)@nerdd@mstdn.social good reference site, and a better way of formatting: https://fuckingformatstyle.com/duration-styles/#time-style