Swift Learning Note One: the difference from OC

Source: Internet
Author: User

    • Not in Swift main.m , @UIApplicationMain It's a program entry.
    • Only files in Swift .swift , no .h/.m distinction between files
    • In Swift, a class is enclosed in a pair {} , with no @implementation@end
1. Method invocation  OC [[UIView alloc] initwithxxx:]Swift UIView (XXX:)
UIView ()
 
class name () = = Alloc/init
 
 
2. Class Methods
OC [Uicolor Redcolor]
Swift uicolor.red ()
 
 
3. To access the properties of the current object, you can not use ' self ';
Recommendation: Do not use, when the compiler prompts to add, will have a better understanding of the ' context '
Cause: Closure (block similar to OC), need to use self
 
 
4. No '; '
'; ' Purpose: delimited statement, in Swift, by default does not require
 
 
5. Enumeration type
OC Uibuttontypecontactadd
Swift. Contactadd
 
 
6. Monitoring Methods
OC @selector
Swift #selector, if with parameters, do not need to use ': '
 
 
7. Commissioning
OC NSLog
Swift Print
? No time
efficiency is higher than NSLog.
 
OC __function__
Swift #function
 
 
8. Notes
OC #pragma mark-what to comment on
Swift//MARK:-What to comment
 
OC #warning
Swift//TODO://Fixme:

Swift Learning Note One: the difference from OC

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.