Mix and Match is when you want to combine other codes with Swift programming. For instance, using objective C with swift programming. You can find more details here.
Using the set type: each item must be unique. The items are not ordered. The type stored in the set must be hashable. A basic type (like string, int, double, float) are all hashable. They are able to compute hash values for themselves. To create an initialise a set: var mySet = Set<String>() //initialise values var mySet = Set(["ABC", "DEF", "GHI"]) //instead of var, you can use let Insert items into a set. If we try to insert something that is already there, it will be ignored. mySet.insert("JKL") To check to see if it has been inserted successfully: var results = mySet.insert("JKL") if results.inserted{} Get the number of items in a set: mySet.count Check to see if a set contains an item: var contain = mySet.contains("ABC") //will return true Iterating over each item in a set: for item in mySet { } Removing items in a set: var item = mySet.remove("ABC") mySet.removeAll() Construct sets from 2 sets: var set1 =...
Defining a function with parameters and return types: func hello(name: String) -> Void{} //the above does not have a return value func hello(name: String) -> String { let ret = "Hello " + name return ret} To call the above function: let msg = hello(name: "Mary") //I am aware of the return value but don't want to use it: _ = hello(name: "Mary") You can also do this: @discardableResult func hello(name: String) -> String { let ret = "Hello " + name return ret } Multi-parameter functions: func hello(name: String, greeting: String) { } To call: hello(name:"Mary", greeting:"Whats up") You can define a parameter with default values. func hello(name: String, greeting: String = "Whats up"){} When calling, you can either call with the greeting or without it: hello(name: "Mary") hello(name:"Mary", greeting:"Good day") We can also declare multiple default values: func hello(name: String...
Prevent rotation to landscape view: Override the following functions: override var shouldAutorotate: Bool { return false } override var supportedInterfaceOrientations: UIInterfaceOrientationMask { return UIInterfaceOrientationMask.portrait }
Comments
Post a Comment