Posts

Post not yet marked as solved
5 Replies
2.6k Views
We raised a bug on this, but just double checking we are not doing something silly, has anyone seen this?We set up a FetchRequest like this:@FetchRequest(entity: Activity.entity(), sortDescriptors: [NSSortDescriptor(keyPath: \Activity.name, ascending: true)], predicate: NSPredicate(value: true), animation: .default) var test : FetchedResultsand then try to use it in a view:ForEach (test) { activity in Text(activity.name) }But get the following compile-time bug:*** Value of type 'ServerObject' has no member 'name'Now the type of the entity is "Activity" defined as:@objc(Activity) public class Activity: ControlledResource { ... @objc(ControlledResource) public class ControlledResource: ServerObject { ... @objc(ServerObject) publicclass ServerObject: NSManagedObject, Identifiable {And "Actifvity" definitely has "name", this is an existing app and core data model being migrated to swiftui. "name" works in the original code.But it seems from the compiler error that the compiler thinks its the superclass type (ServerObject) being returned which does NOT have "name".Is it possible the compiler is looking for the "Identifiable" conformant super class and not correctly working out the explicit subclass type is actually the object being fetched?
Posted
by Allow2.
Last updated
.
Post not yet marked as solved
0 Replies
381 Views
Am I doing something silly here?I am trying to layout some overlapping avatars, using a simple offset in a zstack.If I use hard-coded values in the closures, then it works fine (though they are not offset of course): var body: some View { //let count : Int = min(3, self.childModels.count) return ZStack { ForEach(0..<3) { i in // let offset : CGFloat = i * 10.0 // let opacity : CGFloat = 1.0 - (i * 0.2) return Image("fiona") .resizable() .frame(width: self.height, height: self.height) .clipShape(Circle()) .overlay(Circle().stroke(Color.white, lineWidth: Length(2.0))) .shadow(radius: 10) .padding(.trailing, 1) .offset(x: 1) .opacity(1) } } }Note the closures are set up to have explicit returns.but if I change nothing and just uncomment the let statements in preparation for using the calculated offset: var body: some View { //let count : Int = min(3, self.childModels.count) return ZStack { ForEach(0..<3) { i in <<<<<<<<< ERROR let offset : CGFloat = i * 10.0 let opacity : CGFloat = 1.0 - (i * 0.2) return Image("fiona") .resizable() .frame(width: self.height, height: self.height) .clipShape(Circle()) .overlay(Circle().stroke(Color.white, lineWidth: Length(2.0))) .shadow(radius: 10) .padding(.trailing, 1) .offset(x: 1) .opacity(1) } } }I get an error on ForEach:Unable to infer complex closure return type; add explicit type to disambiguate. Insert ' -> some View'But inserting that breaks the syntax and it complains I need a semicolon between statements.We should be able to do location calculations based on index, right?
Posted
by Allow2.
Last updated
.