We often use the for-in loop in the Swift programming language (also known as For-each in programming language terminology). Also, from the Swift 2.2 release, the For loop will only support the For-in form, not for the For i = 0; I In Swift, the standard library has defined many types that can directly support the for-in loop form, such as range, Array, Set, dict
Swift basics: no foundation for swift
AMAP developers need to register an ak on the official website http://lbs.amap.com/console/, create a swift project, and then add an NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription in Info. plist.Add the library and dependent library of AMAP to the project.
The required libraries are as follows:
Add he
The two languages that are currently being developed for iOS are OC and swift, and these two languages now present a trend that is fading. But for good development, it is necessary to learn two languages well. Now I will start Swift's study. This is my first Swift program--hello world. Apple has introduced a very good tool to develop Swift in Xcode6, called playg
Instantiate an object based on the class name, for example, to 一个类名的 create a Viewcontroller instance from a string.Let Controllername="Spainappproto. "+xibname // Xibname-shaped like Xxviewcontrollervar classtype:anyobject.type= asBut when you instantiate according to Uiviewcontroller.self, you need to convert a little bit. var x:string = m.debugdescription // m is uiviewcontroller.self x = X.stringbyreplacingoccurrencesofstring ("Optional (" "") = X.stringbyreplacingoccurrences
Shake a shake function presumably everyone has used, the new Year's time to rob red envelopes did not less shake it, then the swift language how to achieve such cool features. Shake belongs to an iOS built-in recognizable action, in the viewcontroller that you need to implement the Shake function, add the following code to the Viewdidload method:Uiapplication.sharedapplication (). Applicationsupportsshaketoedit = True self.becomefirstresponder
Using the switch switch statement in Swift does not need to add a break to the match when it is matched, and in swift it automatically jumps out where the match succeeds. Will not be executed in the following directionExample"Let vegetable =" red pepper "Switch Vegetable {Case "Celery":Let vegetablecomment = "Add some raisins and make ants on a log."Case "cucumber", "watercress":Let vegetablecomment = "so w
Comments
Use annotations to inject executable text into your own code as your own notes or hints. Comments are ignored when the Swift compiler runs.
Swift's comments are very similar to the C language, with Single-line comments beginning with two backslashes:
This is a line of comments
Multiline comment begins with///ends with/*:
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/extra/
Unlike multili
Library
Async: Concise Background Execution Code Encapsulation Library
Euler: An intuitive, concise mathematical expression? 27÷3+∑[3,1,2]
Locationmanager: Location Management Package Library
Siren: Notifies the user and provides an App Store link when the app is updated
Brightfutures: Lengthy or complex computations are performed asynchronously by a separate thread
Storage class
Sqlite.swift: Simple, lightweight, using the most SQL-only SQLite package library
//: Playground-noun:a Place where people can playImport UIKit//----The use of dictionaries------////A dictionary is a container that stores multiple elements of the same type//Each value is associated with a key, which is identified as the stored data in the dictionary//dictionaries are unordered.//Dictionary Limitations: KeyType must be hashed (hashable), providing a hash value so that the key can be identified. //1. Creation of dictionariesvarbooks:dictionary"Journey to the": +,"Kingdoms": $,"
Swift design mode: Prototype and swift design mode prototype
Application scenarios:You need to copy the object to create a new object.Difficulties: Deep copy and light copy
Initializing a class or structure consumes a lot of memory resources and computing resources. However, copying can save these resources.Copy of the value type is a deep copy.So how to implement deep copy for the reference type?The answe
Classes, structs, and enumerations can define subscripts, and he can quickly and easily access the elements of a collection (set,array,dict), and you can make use of subscripts to get and set the collection elements. You can define multiple subscripts for a type, which can be overloaded by the different index value types, and the number of indexed values may be multiple.GrammarLook at an example firstSubscript (index:int), Int { get { // return an appropriate Subscript valuehere }
original articles, welcome reprint. Reprint Please specify: Dongsheng's blog Swift 2.0 in the Print function has 4 kinds of overloaded forms:
Print (_:). Output a variable or constant to the console, and wrap the line.
print (_:_:). Outputs a variable or constant into a stream of the specified type, and wraps the line.
print (_:appendnewline:) Output variable or constant to the console, appendnewline true represents a newline,
whether the value is found. The variable possibleintegervalue has an implicitly initialized nil value, so if an optional binding can determine success, possibleintegervalue changes The amount of four case in switch must set an actual value.In the above code example, Luo lists all possible characters that are not practical. Therefore, the case statement of Deafult handles all mismatches, and the default cases do nothing but use the break statement to end switch execution.Fallthrough ( landing )I
Unicode (Unicode code)Unicode is a text encoding of international standards. Its standard table contains almost any character of any language and can be read and written by extension files or Web pages.In Swift, string (string) and character (character) types are fully Unicode-compatible, and they also support non-Unicode codes.Unicode terminology (Unicode terminology)Each Unicode code can be represented by one or more Unicode scalars. For one charact
Optionals (optional type)When a value may have a value, there may also be no value, in which case you can use an optional type. The optional type means:There is a value that is equal to X, or that there is no value at all.Note the point:The concept of an optional type is not available in both C and OC. In the most similar case in OC, a method returns nil or returns an object. The return nil in OC means that there are no legitimate objects. However, this can only be for objects, not for structs,
with default values (extensions for defaults )In how many cases, it is necessary to provide the extension when using the default value for the parameter. This will clarify the meaning of the parameter, especially when calling the function.For convenience, Swift provides default parameters that are automatically extended to the definition when you do not provide an extension. This auto extension is the same as the local parameter name, as if you had w
function, just as you would with other types in swift. For example, you can define a constant or variable as the type of the function and assign a variable in the corresponding function:var mathfunction: (int, int), int = addtwointsThis code can be read as:"Defines a variable called mathfunction, which has a type of function, which takes two int values and returns an int value, and setting this variable requires referencing a function called addtwoin
First, mind mapSecond, the Code//This will make the code very ugly . ifX! = Nil Y! =Nil {print ("x or Y are not equal to null")} print ("x or Y has an empty") //1 use??Let name:string? ="I am the most handsome"Let age:int= - //?? Represents a selectable unpacking package//The following two execution results behave differently due to changes in values,Print (name??""+ String (age))//I'm the most handsome, because he has the lowest priorityPrint (name??"") + String (age))//I am the
following method requires the Somefunctionthattakesaclosure function pointer passed into the previous interface, Func initwithclosure (closure:sendvalueclosure?). {//Assign the function pointer to the Myclosure closure, which covers references to local variables in the somefunctionthattakesaclosure function myclosure = closure} init (Nibname nibn Ameornil:string, bundle Nibbundleornil:nsbundle?) {Super.init (Nibname:nibnameornil, Bundle:nibbundleornil)//Custom initialization} override func View
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.