I'm trying to get deep linking working for my app's widgets. The widgets simply display an image from a Core Data entity: Project. I'd like for when a user taps on the widget, it opens up the ProjectDetailView()
that the image is a member of.
Everything I read says I should be able to add Link(destination: url)
but I'm not getting anywhere with that. In my app, project
is pulled from Core Data, but it has no url
attribute. I feel like it doesn't need one based on the examples I've seen?
The below code gives me the error Value of type 'FetchedResults<Project>' has no member 'url'
which is true.. it doesn't. I don't understand how to get the url to the ProjectDetailView()
the image is included in. Thanks so much for taking a look!
struct SimpleEntry: TimelineEntry {
let date: Date
}
struct WidgetEntryView : View {
var entry: Provider.Entry
@State var projectImage1: Data = .init(count: 0)
@FetchRequest(entity: Project.entity(), sortDescriptors: []) var project: FetchedResults<Project>
var body: some View {
if let randomProject: Project = project.randomElement() {
Link (destination: project.url) {
Image(uiImage: UIImage(data: randomProject.image1 ?? self.projectImage1) ?? UIImage(imageLiteralResourceName: "icon"))
.resizable()
.aspectRatio(contentMode: .fill)
}
}
}
}