Summary of various kinky techniques in iOS development (II.)First, the author of the computer installed on the Mac appOne: Internal implementation (SWIFT) for :
1 var g = array.generate ()2while let obj = g.next () {34< /c9>5print (obj)}6
Two: Map/fileter/reduce
Map method, which gets a closure expression as its only parameter. Each element in the array is called once for the closure function and returns the value that the element is mapped to (or a different type of value). The specific mapping method and return value type are specified by the closure.
When supplied to the array closure function, the map method returns a new array containing the mapped values corresponding to the original array one by one.
Definition of Map
func map(transform: (T) -> U) -> U[]
Over here
T
And
U
are generic and refer to a type,
T
And
U
Only two different types can also be the same.
Let prices = [ten,A,"¥\ ($)"
The results obtained:
print(strPrices) //[¥10, ¥20, ¥30]
Filter, as the name implies, is used to select elements in the array that satisfy the criteria
Definition: filter(includeElement: (T) -> Bool) -> T[]
Accepts an array element to return a bool type
Let p = [ten,A, A, a,a.] Let res = p.filter{$0> (}
Get results:
print(res) //[33, 44, 87]
The reduce method calculates the combination of array elements as a value and accepts an initial value, which may be different from the set element type. To see the definition.
reduce(initial: U, combine: (U, T) -> U) -> U
let P1 = [all,ten] let sum = P1.reduce (0) {$0+$1/// -
Summary: It is necessary to note that when the data is large, higher-order functions are faster than traditional implementations because they can be executed in parallel (as running on multicore), and they can be used for faster execution unless they really need a higher custom version of Map,reduce and filter.Three: iOS get Modle,version,app
- NSLog (@ "uniqueidentifier:%@", [[Uidevice Currentdevice] uniqueidentifier]);
- NSLog (@ "Name:%@", [[Uidevice Currentdevice] name]);
- NSLog (@ "SystemName:%@", [[Uidevice Currentdevice] systemName]);
- NSLog (@ "systemversion:%@", [[Uidevice Currentdevice] systemversion]);
- NSLog (@ "model:%@", [[Uidevice Currentdevice] model]);
- NSLog (@ "Localizedmodel:%@", [[Uidevice Currentdevice] localizedmodel]);
Nsdictionary *infodictionary = [[NSBundle Mainbundle] infodictionary]; Cfshow (infodictionary);
NSString *app_name = [infodictionary objectforkey:@ "cfbundledisplayname"];
NSString *app_version = [infodictionary objectforkey:@ "cfbundleshortversionstring"];
NSString *app_build = [infodictionary objectforkey:@ "cfbundleversion"];
four; UIL and Uri
1. Abbreviations:
- URI (Uniform Resource Identifier) uniform Resource identifier;
- URL (Uniform Resource location) Uniform Resource Locator (or Uniform Resource Locator);
- URN (Uniform Resource Name) uniform Resource naming.
Comparison of 2.URI and URLs
- A. URIs are a relatively broad concept, URLs are a kind of URI, a subset of the URI naming mechanism, it can be said that URIs are abstract, and specifically to use URLs to locate resources.
- B. every resource on the web, such as pictures, documents, videos, etc., is located by Uri, where the so-called positioning refers to the specific path on the server that the resources on the web are stored on the servers relative to the host server.
- c. a URL is a string on the Internet that describes an information resource file, used on client programs and servers to locate the information needed by the client to connect to the server, not only locating the information resource, but also defining how to find the resource.
3. My vernacular understandingURI is a resource positioning mechanism, it is relatively general positioning of resources, not limited to the client and server, and the URL to locate all the resources on the Internet, as long as the resources on the Internet, there is a unique URL.
iOS development--Kinky skills Summary of various sexual techniques in the development of &ios (ii)