iOS Development-Learning Summary Swift Article &swift 2.0 learning and summarizing one

Source: Internet
Author: User

Swift 2.0 Learn and summarize oneOne: Attribute policy (called in OC)
    • Strong: Is the default in Swift
    • Weak: by weak keyword statement
    • Weak var delegate:uitextfielddelegate?
    • Readonly,readwrie directly by declaring a variable Var, declaring a constant let to indicate
    • Copy is declared through the @nscopying directive.
    • It is important to note that String,array and dictionary appear in Swift as value type (value types) instead of reference type (reference type), so they are copied in terms of assignment, initialization, and parameter passing (in simple terms, String,array,dictionary is implemented by struct in swift)
    • Nonatomic,atomic all the swift properties are nonatomic. But we already have many mechanisms on the thread security, such as NSLOCK,GCD related APIs. The reason for this is that Apple wants to get rid of the very few features that are used, and thread safety gives us more mechanisms to deal with.
In Objective-c, we can cross the property directly with the instance variable, while in Swift it is not possibleTwo: Variablesclass variables defined by static cannot be overridden in subclasses, and class variables defined by class can be overridden in subclasses. Implementation of a single case
class Singletonclass {    static Let sharedinstance = singletonclass ()    Private // This prevents other objects from using the default ' () ' initialization method for this class }

three: If using classic error

The well-known goto fail error causes a serious security problem.

1   if(Err = Sslhashsha1.update (&hashctx, &signedparams))! =0)2     Gotofail;3     GotoFail//:) Note that this is not a python reduction4 ... other checks ...5 fail:6 ... buffer frees (cleanups) ...7     returnerr;8:)

Eventually, at Swift, Apple finally eliminated the potential for such errors at the root.

The condition after the if must be a Boolean expression

That is, it is not implicitly compared to 0, which is wrong, because number is not a Boolean expression, number! = 0 is.

int 0 if number{}
: What is the difference between any, anyobject, Anyclass: Any is an alias for an empty protocol collection that indicates that no protocol is implemented, so it can be any type, including class instances and struct-body instances. Any is an alias. Anyobject is a member of an empty protocol, and any object implements this protocol. Anyclass is the nickname of Anyobject.type. Take a look at the statement of any, in swift:///A protocol type Typealias any = protocol<> because of its empty, and into its large, Lao Tzu said, I do not have any rules, so anyone can abide by me. Protocol is a keyword that is used to place multiple protocols within the angle brackets, and the following code is syntactically: var sss3:protocol<nsobjectprotocol,lyprotocol1> = LYNSObject1 () Here's a look at the definition of Anyobject:
@objc protocol Anyobject {}

This protocol does not define any members. @objc is a declarative attribute used to decorate any declaration that can be accessed or used in OBJC, such as non-nested classes, protocols, properties and methods in classes and protocols, initializers, destructors, and subscripts. If you apply the OBJC attribute to a class or protocol, it is also implicitly applied to the members of that class or protocol. For classes marked with the OBJC attribute, the compiler implicitly adds the OBJC attribute to its subclasses. Anyobject uses @objc to declare attributes because it is meant to be a messenger of OBJC and Swift, and many of the types of passing variables are anyobjct. Unlike Any,anyobject, which is an empty protocol that does not declare any member, any represents an empty set of protocols. Anyobject is a protocol, and any is a 0 protocol. Finally look at a definition of Anyclass:
    • Typealias Anyclass = Anyobject.type
It's really just an alias. Any is also an alias and an alias for protocol<>. The following code can deepen the understanding:
1 Protocol lyprotocol1{2 //some code3 }4 classlynsobject1:nsobject,lyprotocol1{5 //some code6 }7  8 var ly1:any9var ly2:protocol<>Ten   OneTypealias Any1 = protocol<nsobjectprotocol> Avar k:protocol<nsobjectprotocol> - var k1:nsobjectprotocol -   thevar sss1:protocol<nsobjectprotocol> =NSObject () -var sss2:nsobjectprotocol =NSObject () - //var sss1:protocol<nsobjectprotocol,lyprotocol1> = NSObject ()//of the wrong -var sss3:protocol<nsobjectprotocol,lyprotocol1> = LYNSObject1 ()//feasible +  
Anyobject is a protocol, any is 0 protocols!   Anyobject is used for any class instance, and any is for any variable. Copyright NOTICE: Welcome Reprint, please paste the source address: http://www.cnblogs.com/iCocos/(iOS DreamWorks)

More exciting please pay attention to github:https://github.com/al1020119?tab=repositories

iOS Development-Learning Summary Swift Article &swift 2.0 learning and summarizing one

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.