Hi,
I'm try to convert from CoreData to SwiftData.
Problem is that I'm using inheritance in CoreData.
So, I have a base class "animal" and "cat" and "bird" inherit from it.
I can have a array of type "animal" which contains both cats and dogs.
Now as I try to move to SwiftData I tried the following approach
protocol Animal {
var name: String { get set }
}
@Model
class Cat: Animal {
var name: String
var legs: Int
}
@Model
class Bird: Animal {
var name: String
var legs: Int
var wings: Int
}
@Model
class Enviroment {
//leads to error:
//Type 'any Animal' cannot conform to 'PersistentModel'
var animals: [any Animal]
}
So how to I get around of this? I would like to store multiple types of animals (classes that conform to protocol animal) … but how can I achieve that?
Thanks
Post
Replies
Boosts
Views
Activity
Hi,
is there a way to different swift packages for different build configuration?
I.e. when I do Release-Builds I'd like to use MyPackage and for debug builds I'd like to use MyPackage-Debug.
My first thought was that I could handle this in the Package.swift but .target does not support configurations in .when but only plattforms.
So is there any way to use different packages depending on configuration?
Hi,
I have a strange problem when drawing NSAttributedStrings in SwiftUI. Compared to render it in AppKit the SwiftUI characters are 1pt smaller.
To display the string in SwiftUI I have to use NSViewRepresentable but it does not matter if I render the view in draw() of NSView or use a NSTextField to display it. I have to use NSViewRepresentable as I also have to use CMYK-Colors.
The font used is "The Sans Mono-W8 ExtraBold".
Can anyone point my for a hint? Or is this a bug?
I try to use some CMYK-Colours with SwiftUI, the view is exported to a PDF.
The problem is that after the export, the colours are no longer correct and it seems that SwiftUI transforms them in to sRGB.
I have a pretty complex and dynamic SwiftUI View which wrapps around multiple other Views which have different dynamic contents (images, texts …)
But I also need those views as a thumbnail with a fixed height.
I.e. something like a magazine where a page is displayed and the other pages are displayed in a thumbnail bar at the bottom of the screen.
The thumbnails should be presented in a UICollectionView (the rest of the App is still UIKit!)
I tried to scale down the UIView (coming from UIHostingController) using Autolayout but had no success with that.
My next approach would be creating preview images but to render and SwiftUI-View as image I need it to be displayed on the screen … but how to do that?
Thank you very much in advance
Hi,
I have a SwiftUI View which contains Images and Borders.
I'd like to export this to a Vector-PDF.
I tried
let pdfExportView = NSHostingView(rootView: MySwiftUIView())
let pdfData = pdfExportView.dataWithPDF(inside: pdfExportView.bounds)
But the PDF does not contain the Images and the borders. Is there any other solution? PDF as Bitmap is not an option.