Swift 5.5 is built into Xcode 13, and although the version number is only 0.1, it seems like a minor update, but it brings a lot of new content, the biggest of which is the introduction of a whole new way of concurrent programming.

This paper included: http://www.cocoachina.com/art…

Conditional compilation supports expressions

Swiftui will use conditional Modifier in cross-platform, the previous solution is to write a set of judgment system, SWIFT 5.5, the native conditional compiler expression support, cross-platform more convenient.

struct ContentView: View {
    var body: some View {
        Text("SwiftUI")
        #if os(iOS) 
            .foregroundColor(.blue)
        #elseif os(macOS)
            .foregroundColor(.green)
        #else
            .foregroundColor(.pink)
        #endif
    }
}

CGFloat and Double support implicit conversion

Let number1: cgFloat = 12.34 let number2: Double = 56.78 let result = Double number1 + number2 // result

The code below will report an error before SWIFT 5.5, because Scale is of type Double, and SwiftUI requires CGFloat binding.

Struct ContentView: View {@state private var scale = 1.0 // Double var body: some View {VStack {Image(struct ContentView: View) {@state private var scale = 1.0 // Convert CGFloat Slider(value: $scale, in: 0...) to CGFloat Slider(value: $scale, in: 0...) 1)}}}

Static Member Lookup Support in Generic Context

This new feature makes some of the syntax in Swiftui much simpler and easier to use.

struct ContentView: View { @Binding var name: String var body: some View { HStack { Text(name) TextField("", text: $name). / / textFieldStyle (RoundedBorderTextFieldStyle ()) / / before writing. TextFieldStyle (. RoundedBorder) / / new writing, more concise}}}

Local variables support lazy

Func lazyInLocalContext() {print(" before ") lazy var swift = "Hello swift 5.5" print(" after ") print(swift) LazyInLocalContext () /* output lazy before lazy after Hello Swift 5.5 */

Function and closure arguments support property wrapping

  • Property wrapping was introduced in Swift 5.1.
  • Swift 5.4 supports property wrapping to local variables.
  • Swift 5.5 supports property wrapping to function and closure parameters.
@propertyWrapper struct Trimmed { private var value: String = "" var wrappedValue: String { get { value } set { value = newValue.trimmingCharacters(in: .whitespacesAndNewlines) } } init(wrappedValue initialValue: String) { wrappedValue = initialValue } } struct Post { func trimed(@Trimmed content: PropertyWrapper print(content)}} let POST = POST () POST. TRIMed (content: "Swift 5.5 Property Wrappers ")

Enumerations with associated values support Codable

With this capability, enumeration can be used as a data model, just like structures and classes.

  • Enumerate to JSON.
// Enum Score: Codable {case number(Score: Double) case letter(Score: String)} // Let scores: [Score] = [.number(Score: 98.5),.letter(Score: 98.5),. // JSON let encoder = JSONEncoder() encoder. OutputPrinted Do =.prettyPrinted Do {let result = try encoder.encode(scores) let json = String(decoding: result, as: UTF8.self) print(json) } catch { print(error.localizedDescription) }
  • JSON to enumeration.
enum Score: Codable { case number(score: Double) case letter(score: String) } // JSON let json = """ [ { "number" : {"score" : 98.5}}, {"letter" : {"score" : Let decoder = Jsondecoder () do {let scores = try decoder. Decode ([Score]. json.data(using: .utf8)!) for score in scores { switch score { case let .number(value): print(value) case let .letter(value): print(value) } } } catch { print(error.localizedDescription) }

Recommended at the end of the article: iOS popular collection & video analysis

1) Swift

② The underlying technology of iOS

③iOS reverse protection

④iOS interview collection

⑤ big factory interview questions + underlying technology + reverse security + SWIFT

Remember thumb up for your favorite friends

Collection is equal to whoring, thumb up is the true feelings ღ(· · ‘)