Skip to content

Instantly share code, notes, and snippets.

@kishikawakatsumi
Created July 17, 2023 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kishikawakatsumi/a7fe19004afe10069cf6c23215668520 to your computer and use it in GitHub Desktop.
Save kishikawakatsumi/a7fe19004afe10069cf6c23215668520 to your computer and use it in GitHub Desktop.
[SwiftData] Compiler cannot reject models containing types that cannot be saved.
SwiftData raises a runtime error when attempting to save a property of CGFloat type, but the compiler cannot validate it.
Models with properties of type CGFloat, such as the example below, cannot be saved in SwiftData. It will cause a run-time error.
I believe that the compiler should reject such incorrect models. However, such models cannot be made an error at compile-time, so the following documentation statement that SwiftData can safely describe the model layer is highly questionable.
> Using modern language features like macros, SwiftData enables you to write code that is fast, efficient, and safe, enabling you to describe the entire model layer (or object graph) for your app.
```swift
@Model
final class Point {
var x: CGFloat
var y: CGFloat
init(x: CGFloat, y: CGFloat) {
self.x = x
self.y = y
}
}
```
@kishikawakatsumi
Copy link
Author

Please verify this issue with iOS 17.1 beta and update your bug report with your results by logging into https://feedbackassistant.apple.com/ or by using the Feedback Assistant app.

iOS 17.1 beta (21B5045h)
https://developer.apple.com/download/

If the issue persists, please attach a new sysdiagnose captured in the latest build and attach it to the bug report.

iOS sysdiagnose Instructions:
https://developer.apple.com/services-account/download?path=/iOS/iOS_Logs/sysdiagnose_Logging_Instructions.pdf

If this is no longer an issue you can close this feedback by selecting “Close Feedback” via the Actions button in Feedback Assistant.


For a complete list of logging instructions visit:
https://developer.apple.com/bug-reporting/profiles-and-logs/

@kishikawakatsumi
Copy link
Author

I have confirmed that this has been fixed in iOS 17.1 beta2. For your information, in 17.1 beta1, when I tried to save CGFloat, it always saved zero value without any error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment