|
Hi guys, I can sure use the help. I am making a few view changes to the Converter app as part of day 24 challenges. I am getting the above error on the closing bracket of the MeasurementFormatter init, and cannot get the app to compile. The changes that I made so far is adding a screen with details of the measurement( the values is stored in a seperate swift file, struct and array, and declared by var info: UnitInfo), and changing the foreground colour of the result textfield. Am I missing something somewhere(sure I am missing something very stupid) Code is below. Paul import SwiftUI struct ContentView: View {
} struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } } |
|
|
|
|
|
@roosterby, Thank you for your reply, I am a bit confused as to the initial value for @State public var info: UnitInfo As this is pointing to a struct called UnitInfo and a array called info that is outside on the ContentView.swift file in two separete files, and confused as to how it affects the init for MeasurementFormatter import Foundation struct UnitInfo { var name: String var detail: String
} let info = [ UnitInfo(name: "Unit of measure for acceleration", detail: "Acceleration is the rate of change of velocity. Acceleration can be expressed by SI derived units in terms of meters per second squared (m/s2)."), UnitInfo(name: "Unit of measure for planar angle and rotation", detail: "Angle is a quantity of rotation. The SI unit for angle is the radian (rad), which is dimensionless and defined to be the angle subtended by an arc that is equal in length to the radius of a circle. Angle is also commonly expressed in terms of degrees (°) and revolutions (rev)."), UnitInfo(name: "Unit of measure for area", detail: "Area is a quantity of extent in two dimensions. Area can be expressed by SI derived units in terms of square meters (m2). Area is also commonly measured in square feet (ft2) and acres (ac)."), The snip above is not the entire info |
|
This line just declares a variable called This is a separate variable from any A separate thing is that there is no benefit to declare |
|
@hatisushira says the same about your keyboardIsFocused variable. You tell your But you never tell the struct if keyboardIsFocused is You do this by either:
The key here is you MUST provide values for each of the structure's variables when you create a struct. And remember this important lesson. In SwiftUI, your display elements are structs that conform to the View protocol. These structs may be created, destroyed, and recreated thousands of times a second. Each time, your struct is initialized, its variables must be populated. It may seem like overkill for SwiftUI to destroy and recreate view structs. But this process is trivial compared to the tens of thousands of calculations the iPhone does reading GPS data, barometer data, gyroscope data, step calculations, finger swipes, data encryption, voice recognition, network background tasks, scanning faces, and serving up cat memes. |
TAKE YOUR SKILLS TO THE NEXT LEVEL If you like Hacking with Swift, you'll love Hacking with Swift+ – it's my premium service where you can learn advanced Swift and SwiftUI, functional programming, algorithms, and more. Plus it comes with stacks of benefits, including monthly live streams, downloadable projects, a 20% discount on all books, and free gifts!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.