Java
多线程 Java 多线程编程笔记 🔗
多线程 Java 多线程编程笔记 🔗
Unlike arithmetic operators in C, arithmetic operators in Swift don’t overflow by default. If want to overflow by default, use the overflow operation begin with ampersand (&). For example, the overflow addition operator (&+). It’s so free to define custom infix, prefix, postfix and assignment operators, precedence and associativity values. Bitwise Operators Here we use a function to pad 0 for the number’s print result. func pad(num: UInt8, count: Int) -> String { var str = String(num, radix: 2) var res: String = str for _ in 0..<(count - str.count) { res = "0" + res } return res } ~ NOT ...
Access control restrict access to part of the code form code in other source files and modules. It enable us to hide the implement detail of the code, and to specify a preferred interface which that code can be accessed and used. Set access levels to individual types (classes, structures, enumerations), as well as to properties, methods, initializers, and subscripts belonging to those types. Protocols can be restricted to a certain context, as can global constants, variable, and functions. ...
Most of the time we don’t have to think about accessing memory, but it’s important to understand where potential conflicts can occur, so we can avoid writing code that has conflicting access to memory. Here we are talking about the situation that happen on a single thread. Memory Access var one = 1 // write access to the memory one is stored. print("\(one)") // read access from the memory one is stored. The conflicting access to memory can occur when different part of the code are trying to access the same location in memory at the same time. ...
Swift use ARC to track and manage the app’s memory usage. ARC frees up the memory used by class instances when those instances are no longer needed. Reference counting applies only to instance of classes. Reference: strong: retain the obj. (default) weak: don’t retain the object referred to, track the object referred to. unowned: don’t retain the object referred to, don’t tract the object referred to. How ARC Work Allocate a chunk of memory to store information about that instance ...
A function with an opaque type hides its return value’s type information. Hiding type information at some boundaries between a module and code that calls into the module. Unlike returning a value whose type is a protocol type, opaque type preserve type identity —the compile has access to the type information, but clients of the module don’t. The Situation Here we have a Shape protocol. protocol Shape { func draw() -> String } The struct Triangle conform to the Shape. Describe how to draw(). ...
Define a class with template type , then should illustract the type when use the class.
A process for querying and calling properties, methods, and subscripts on an optional that might currently be nil .Multiple queries can be chained together, and the chain fails gracefully if any link in the chain is nil . Optional Chaining as an Alternative to Forced Unwrapping ! force unwrapping triggers a runtime error when the optional is nil . Use the optional chaining to check if the optional value querying is succeed. the chain return optional value is nil , the optional chaining fail. the chain return optional contains a value, the optional chaining succeed. Force Unwrapping ...
A protocol defines a blueprint with methods, properties.
Extension add new functionality to an existing class, structure, enumeration, or protocol type.