One, can be selected
All types in Swift do not receive nil values by default, and if a data type is required to receive a nil value, the type of data needs to be wrapped into an optional type.
1. Suffix: You must force parsing before you can get the value of the wrapper
2,! Suffix: Implicit parsing can get the value of the wrapper
Second, type conversion
III. privatization in Swift
Private: Modifies properties and functions by using them only in the current class or class extension.
Fileprivate: The file is private, as long as in the same file, then the properties and functions in this file can be accessed
@objc: Used to modify the optional method in Swift, which enables functions to be invoked at the runtime of OC, and is commonly used in #selector called methods
Iv.% transcoding using URLs in Swift
Note: in swift "\" is itself an escape character that needs to be not allowed in the URL through the "\" escape//' \ ' character, so they must be URL-coded let urlstring:string? = "/volumes/hd\\ extension/sourcetreecode/zmwebproduct/main.json" let escapedstring = urlstring? Addingpercentencoding (withallowedcharacters:. urlhostallowed) Let FileUrl = Nsurl.fileurl (withpath:escap
edstring!) Write an array to disk and save it in JSON format let array: [[string:any]] = [["Clsname": "Zmhomeviewcontroller", "title": "Home", "ima Gename ": Home", "Visitorinfo": ["imagename": "", "message": "Pay attention to some people, come back here to see what surprises"]]/// JSON, array ———— > JSON serialization let data = try! Jsonserialization.data (Withjsonobject:array, Options: [. prettyprinted]) let urlstring:string? = "/users/czm/desktop/01-test/deom.json" (data as NSData). Write (tofile:urlstring!, atomically:true) number Groups are written to disk as plist//The configuration information is saved to the sandbox (array as Nsarray). Write (tofile: "/volumes/hd\\ extension/sourcetreecode/zmwebproduct/demo . plist ", AtomicaLly:true)
Modifiers for type members
1, Static and class modifiers
Properties that are defined in enumerations, structures, and methods that use the static property can be transformed into type properties, type methods;
Enum Season:character {case
Spring = ' S ' case
Summer = ' U ' case
Fall = ' F ' case
Winter = ' W '
static var desc:string?
static Let name = "season"
static var info:string {get
{return
] represents the enumeration of seasons \ (desc?? "")
}
set {
print (assign value to info attribute: \ (newvalue))}}
Season.desc = "season"
Season.info = "New Season"
Properties and methods defined in a class are decorated with static or class, and can be changed into type properties, type methods
The difference between a property or a method that is decorated in a class by class or static is:
Type attributes, type methods, which are decorated with static, cannot be overridden by quilts, while class adornments can be overridden by a quilt class.
Note: When a type stores a property, it can only be decorated with static, and can be decorated with the type calculation property class and static
Lass person {
//Type calculation properties can be modified with static, class,
class var name:int {get
{
3
}
set {
print ( Assign value \ (NewValue))
}
//Type storage property can only use static to modify
static var nation:string!
class Func sum (X:int, y:int)-> Int {return
x + y
}
static func agave (result:double)-> Double {return
result/3.0
}
}