Swift Inbox
pending
some, Swift 5.1@frozenCombine
Self.Output
SwiftUI
@EnvironmentObject & environmentObject(_:)
@EnvironmentObject & environmentObject(_:)The
@EnvironmentObjectattribute.You use this attribute in views that are lower down in the view hierarchy to receive data from views that are higher up.
The
environmentObject(_:)modifier.You apply this modifier so that views further down in the view hierarchy can read data objects passed down through the environment.
Swift 中含关联值的枚举
static可以修饰存储属性,而class不能;class修饰的方法可以继承,而static不能。在协议中需用
static来修饰。
Error
Declaration:
Overview
Any type that declares conformance to the Error protocol can be used to represent an error in Swift’s error handling system. Because the Error protocol has no requirements of its own, you can declare conformance on any custom type you create.
Using Enumerations as Errors
Swift’s enumerations are well suited to represent simple errors.
Including More Data in Errors
Sometimes you may want different error states to include the same common data, such as the position in a file or some of your application’s state. When you do, use a structure to represent errors. The following example uses a structure to represent an error when parsing an XML document, including the line and column numbers where the error occurred:
JSONEncoder
An object that encodes instances of a data type as JSON objects.
Last updated