This works as written. I only have issue using vm.
my issue is:
import SwiftUI
...
import Observation
...
@State private var cameraPosition = MapCameraPosition.region(vm.mapRegion)
Error: Cannot use instance member 'vm' within property initializer; property initializers run before 'self' is available
Works:
Text("Region: (vm.mapRegion)")
inside body: does not
var body ...
Map(position: MapCameraPosition.region(vm.mapRegion.))
'MapCameraPosition' expects type 'Binding'
Post
Replies
Boosts
Views
Activity
Thank you Claude31. I am new to Swift Language and I had a larger code base that what I posted. I got a couple of things confused and had to take a break. Now that I have come back and back tracked all of my code modules and I was able to make this example work using the for element in d1 case.
I learned alot about parsing JSON including dates and how to use quicktype better.
Thanks for the help for all who looked at this issue.
Great Forum.
Barry [swifter] West
found another mistake. The try decoder.decode([ApaResultElement].self, from: leagueView) did not decode.
Had error Error found => keyNotFound(CodingKeys(stringValue: "id", intValue: nil), Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "No value associated with key CodingKeys(stringValue: "id", intValue: nil) ("id").", underlyingError: nil))
**Update. Made a type O which caused the compile error
Error found => keyNotFound(CodingKeys(stringValue: "id", intValue: nil), Swift.DecodingError.Context(codingPath: [_JSONKey(stringValue: "Index 0", intValue: 0)], debugDescription: "No value associated with key CodingKeys(stringValue: "id", intValue: nil) ("id").", underlyingError: nil))
Playground execution terminated: An error was thrown and was not caught:
▿ DecodingError
▿ keyNotFound : 2 elements
- .0 : CodingKeys(stringV ...
it am trying the following with errors
ForEach(d1, id: .id) { schema in
ForEach(schema.data, id: .id ) { data in
}
Text("\(schema.data.viewer.lastName)")
}
I do get a result. and no error.
let d1 = try decoder.decode([ApaResultElement].self, from: leagueView)
for element in d1 {. // This is an ApaResultElement
let elementData = element.data // This is a DataClass
let viewer = elementData.viewer
let league = elementData.league }
I get the compile error: Cannot find 'elementData' in scope
also I can not use a for statement in a View. It needs to be ForEach