swift5.1

What does the SwiftUI `@State` keyword do?

烈酒焚心 提交于 2019-11-28 21:17:39
The SwiftUI tutorial uses the @State keyword to indicate mutable UI state: @State var showFavoritesOnly = false It offers this summary: State is a value, or a set of values, that can change over time, and that affects a view’s behavior, content, or layout. You use a property with the @State attribute to add state to a view. What does the keyword mean, exactly? How does mutating a @State variable cause the view to be recomputed? How are other variables immutable within the body getter? The @State keyword is a @propertyWrapper , a feature just recently introduced in Swift 5.1. As explained in

What is the `some` keyword in SwiftUI?

前提是你 提交于 2019-11-28 02:59:53
The new SwiftUI tutorial has the following code: struct ContentView: View { var body: some View { Text("Hello World") } } The second line the word some , and on their site is highlighted as if it were a keyword. Swift 5.1 does not appear to have some as a keyword, and I don't see what else the word some could be doing there, since it goes where the type usually goes. Is there a new, unannounced version of Swift? Is it a function that's being used on a type in a way I didn't know about? What does the keyword some do? some View is an opaque result type as introduced by SE-0244 and is available

What does the SwiftUI `@State` keyword do?

拜拜、爱过 提交于 2019-11-27 13:05:08
问题 The SwiftUI tutorial uses the @State keyword to indicate mutable UI state: @State var showFavoritesOnly = false It offers this summary: State is a value, or a set of values, that can change over time, and that affects a view’s behavior, content, or layout. You use a property with the @State attribute to add state to a view. What does the keyword mean, exactly? How does mutating a @State variable cause the view to be recomputed? How are other variables immutable within the body getter? 回答1:

Instantiated optional variable shows as nil in Xcode debugger

这一生的挚爱 提交于 2019-11-26 23:28:42
问题 Since I upgraded to Xcode 11 and Swift 5.1 I've encountered a strange issue -- after an optional variable is instantiated, it can still show as up nil in the Xcode debugger! I have an optional class variable called booking : var booking: Booking? It's of type Booking : public struct Booking: Codable { var id: Int? var start_time: Date? var payment_currency: String = "USD" var payment_amount: Int? } When I'm stepping through the code, I can see booking before it's allocated... It's nil, great:

What is the `some` keyword in SwiftUI?

不想你离开。 提交于 2019-11-26 22:29:50
问题 The new SwiftUI tutorial has the following code: struct ContentView: View { var body: some View { Text("Hello World") } } The second line the word some , and on their site is highlighted as if it were a keyword. Swift 5.1 does not appear to have some as a keyword, and I don't see what else the word some could be doing there, since it goes where the type usually goes. Is there a new, unannounced version of Swift? Is it a function that's being used on a type in a way I didn't know about? What