[Reading Notes] 100 Switf tips and switf tips

Source: Internet
Author: User

[Reading Notes] 100 Switf tips and switf tips

 

StatementWelcome to repost, but please keep the original source of the article :) blog Park: http://www.cnblogs.com farmer UNCLE: http://over140.cnblogs.com


Body

1. Selector can be constructed using string constants in Swift, for example, nsicationicationcenter. defaultCenter (). addObserver (self, selector: "handleMoviePlayerLoadStateDidChange:", name: MPMoviePlayerLoadStateDidChangeNotification, object: nil)
Func handleMoviePlayerLoadStateDidChange (notification: NSNotification) Pay attention to the colon at the end of the string constant. If there is a parameter, add one colon. If there is no colon, multiple parameters are followed by the first colon and followed by a colon, similar to "method: param2: param3 :".

 

2. Use a multivariate group (Tuple) to exchange the variable value func swapMe <T> (inout a: T, inout B: T ){
(A, B) = (B,)
}

 

3. "=" Operator Overloading is not supported (-- it seems that it is not the content of this book. It is written here for the time being)

 

4. the func parameter defaults to let variable. You can set a var by yourself. Note that this does not affect the external parameters, for example: func incrementor (var variable: Int)-> Int {
Return ++ variable
}

 

5. You must ensure that the initialization method of the parent class can be called only after the member of the current subclass instance is initialized. The null Initialization Method of the subclass override init does not need to be displayed. The initialization method subclass that calls super. init and convenience cannot be overloaded, but the subclass that can call the initialization method that adds required must be reloaded.

 

6. When you need to process a large amount of data and perform frequent operations (increase or decrease) on the elements, it is better to select NSMutableArray and NSMutableDictionary. In the case of a small number of entries in the container and a large number of containers, the built-in Array and Dictionary should be used in Swift.

 

7. Generally, weak is weakly referenced. When delegate is set, when the self attribute is stored as a closure

 

8. You can terminate a program by generating a fatal error (fatalError), for example, an invalid parameter.

 

9. Enable a class attribute to read and write externally read-only public class MyClass {
Public private (set) var name: String?
}

 

End

I learned about iOS development almost in February. I made some notes and will share more swift content later. We recommend that you buy and read this electronic version of the "100 Switf essential tips" (http://swifter.tips /)!

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.