Swift learns the scattered knowledge points of the third day

Source: Internet
Author: User
Tags closure

SWIFTX study 03

1. Creating an object is just the class name ()

2. Add navigation bar Let Nav = Uinavigationcontroller (rootviewcontroller:home)

3. Add a sub-controller for Uitabbarcontroller Addchildviewcontroller or viewcontrollers

4. Tabbar is a Uitabbarcontroller private property in Swift, so the assignment takes the form of KVC

SetValue (Cztabbar, Forkey: "TabBar")

5. Modify the system rendering color--we recommend that you modify the program just when it starts

Modifying the rendered color of a uitabbar

Uitabbar.appearance (). Tintcolor = Uicolor.orangecolor ()

6. Modify the color of the entire Uitabbar uitabbar.appearance (). Bartintcolor = Uicolor.orangecolor ()

7. Modify the NavBar of the selected dye

Uinavigationbar.appearance () Tintcolor = Uicolor.orangecolor ()

8. Add Tabbar above picture for Uitabbarcontroller's child controller, and select picture

Sub-controller. Tabbaritem.image

Sub-controller. Tabbaritem.selectedimage

Setting Uitabbarcontroller's Tabbar and Tabbar button text is just the same code as the OK controller. Title

9. Uitabbarbutton is a private property within the Uitabbar class and cannot be obtained, so we can iterate through the child controls to get

1) for Subview in Subviews

2) Subview.iskindofclass (nsclassfromstring ("Uitabbarbutton")!) Gets the subview that is the Uitabbarbutton control

10. Two ways to add lazy buttons

1>lazy var Compose1button:uibutton = UIButton (Type:UIButtonType.Custom)

2>lazy var Compose2button:uibutton = {

Return UIButton (Type:UIButtonType.Custom)

}()

11.* in Swift we can directly modify the properties of a struct frame without having to do it like OC

12. We are writing the override Init (Frame:cgrect) method by writing the code in plain code, and the system automatically generates

Required init? (Coder Adecoder:nscoder) {

Artificially produced a crash to remind

FatalError ("Init (coder:) have not been implemented")

}

If you want to use Storboard to create the view, you need to fill in the initialization of the logic code, and the above warning is deleted

13* Create a new project, you can delete Landacape left and Landacape right by default support for the iphone's vertical screen, add class prefix, backwards compatible with two versions, add start Page yourself AppIcon

14. Typical pod file, can be copied directly

use_frameworks!

Platform:ios, ' 8.0 '

Pod ' afnetworking '

Pod ' Sdwebimage '

Pod ' Svprogresshud '

Pod ' Snapkit '

Pod ' FMDB '

14. Typical steps to create a UIWindow

1> window = UIWindow (Frame:UIScreen.mainScreen (). Bounds)

2> window? Rootviewcontroller = Cztabbarviewcontroller ()

3>window?. Makekeyandvisible ()

15. Thread Hibernation Direct sleep (5)

A few steps of 16.git management

1> creating a remote repository on the server Oschina inside (code cloud)

2> git clone download to local

3> Add Ignore File

"Pod Install"--this installation is slow----recommend that you use pod install--no-repo-update

18. Trilogy of Custom Views:

1. Overriding the construction method

2. Adding sub-views and setting constraints

3. Lazy Loading

19. When we switch the page, the animation will stop, so in order to avoid the basic animation does not stop baseanimation.removedoncompletion = False

20.swift class files are not imported, but the pod has a tripartite framework to be imported manually

21.* project experience. The picture's normal, highlighted and checked names are the same, with different suffixes for easy code simplification

22. Three ways to create a single case

How to create a singleton 1

static Let Shareperson:person = Person ()

How to create a singleton 2 (nature is also a closure)

static Let Shareperson1:person = {

Let P = person ()

Return P

}()

How to create a singleton 3

static Let SharePerson2 = {()->person in

Let P = person ()

Return P

}()

Nesting of 23.swift support methods (Implementation part)

Agelab.text = "\ (P?. Age?? 0) "Back add??" The reason that P is optional may not exist, p does not exist, and age certainly does not exist, but the preceding is a required attribute, so add?? Guaranteed value must exist

The method of 25,textfield monitoring

Textfield.addtarget (Self, Action: "Change", forControlEvents:UIControlEvents.EditingChanged)

26. Determine if there is text in the TextField Nametextf.hastext ()

27.swift only true and false no Yes and no

28. Miao Description method for rewrite model

Override

var description:string{

let keys = [' name ', ' age ']

return Dictionarywithvaluesforkeys (keys). Description}

29. The proxy method is implemented in the extension

As! ()? and! Judging by the previous

Let Indexpath = self.tableview.indexpathforselectedrow! Gets the Indexpath of the selected cell

32. Click on the cell via SB connection, get the purpose controller let DESVC = Segue.destinationviewcontroller as!... via Prepareforsegue

33. Get random number ()%25

34. Assignment of data, overriding Didset, equivalent to the Set method override

var P:person? {

didset{

Property assignment of its own value

}

}

35. The self in the closure must be written, because to indicate which controller

Tableview.dequeuereusablecellwithidentifier ("cell", Forindexpath:indexpath) The object returned in this code must be a Persontableviewcell type before we can use as! , because the ID of "cell" is definitely the Persontableviewcell type of cell. But if it's not certain that this object is necessarily of the Persontableviewcell type, it has to be used as? Come and try to turn around a bit.? The expression is not sure, if the transfer is not successful and error. But as! If it doesn't work, it's going to collapse.

Swift learns the scattered knowledge points of the third day

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.