Posts

Post not yet marked as solved
0 Replies
372 Views
I am trying to design a 1-many relationship between Advisors and Students in CloudKit. My problem is that in my model classes, I need Student to be able to refer to a Teacher -- so I have a teacher property of type Teacher. But in CloudKit, to establish the relationship, I need a CKRecord.Reference. So now I have two properties, each of which is relevant in different contexts. Is there some standard way of doing this? I'm used to Backendless, that hides most of this detail, but I'd like to try Apple's approach so I don't need to worry about user management.Thanks for any info ...class Teacher : Equatable, CKRecordValueProtocol { var id: Int var lastName: String var firstName: String var students: [Student] // other stuff omitted } class Student : Equatable { var id: Int! var lastName: String! var firstName: String! var teacher: Teacher! // so we can point to the teacher in our model var teacherReference: CKRecord.Reference! // so we can point to records in CloudKit var gpa: Double! // other stuff omitted }
Posted
by mprogers.
Last updated
.
Post not yet marked as solved
2 Replies
1.3k Views
I've got some code, where I've nested 2 Buttons in an HStack in a Form. When I click either Button, both actions fire, printing "US to Canadian" and" Canadian to US" -- like the HStack itself was receiving the tap.If I change the Form to a VStack, each Button works separately, as expected.That's not supposed to happen is it? Is there something about Forms that I'm missing? Or is this a bug?struct Currency { var canadian:String { get { "\(canadianDollar)"} set { americanDollar = Double(newValue) ?? 0.00} } var american:String { get { "\(americanDollar)"} set { americanDollar = Double(newValue) ?? 0.00} } var canadianDollar:Double var americanDollar:Double } struct ContentView : View { @State private var currency = Currency(canadianDollar: 0.00, americanDollar: 0.00) var body: some View { NavigationView { Form { HStack { Text("CAD: ") TextField($currency.canadian).textFieldStyle(.roundedBorder) } HStack { Text("USD: ") TextField($currency.american).textFieldStyle(.roundedBorder) } HStack { Button(action: { print("Canadian to US") }){ Text("CAD -> USD") }.background(Color.green) Spacer() Button(action: { print("US to Canadian") }){ Text("USD -> CAD") }.background(Color.yellow) } }.navigationBarTitle(Text("Currency Converter")) } } }
Posted
by mprogers.
Last updated
.
Post not yet marked as solved
0 Replies
375 Views
I'm working through the Handling User Input tutorial, which I am assuming many of you have done as well.If I preview LandmarkList immediately after Section 2, Step 3 with showFavoritesOnly set to true, I get a blank cell when showFavoritesOnly is set to true.After completing Section 3, Step 1 -- with the iteration through landmarkData being driven by the ForEach, this problem resolves itself -- the blank cell is no longer visible when showFavoritesOnly is set to true.Can someone please explain why this extra blank cell is showing up?
Posted
by mprogers.
Last updated
.
Post marked as solved
1 Replies
804 Views
In the NavigationButton, what is the purpose of the isDetail parameter? If I change it to false the Landmarks app seems to look/act the same, and the documentation is muite on the subject.Speaking of documentaiton, when Swift was announced at WWDC 2014, it was released with a 400 page *book* on the subject ... does anyone know if there's going to be a SwiftUI equivalent?
Posted
by mprogers.
Last updated
.
Post not yet marked as solved
6 Replies
1.1k Views
I'm having trouble wrapping my head around SwiftUI's declarative syntax. For instance, in the Landmarks code, when creating the List ...var body: some View { NavigationView { List(landmarkData) { landmark in NavigationButton(destination:LandmarkDetail()) { LandmarkRow(landmark: landmark) } }.navigationBarTitle(Text("Landmarks")) } }... why is the navigationBarTitle associated with the List? I *think* it's analagous to UINavigationControllers, where each UITableViewController has a navigationItem (and a title). Is that right?More confusingly (for me), why is the LandmarkRow inside the NavigationButton? I think of a button as part of a UITableViewCell, so here the analogy breaks down. Can someone explain this?
Posted
by mprogers.
Last updated
.