Structure vs class in Swift language

Source: Internet
Author: User
Tags type casting

Both class and structure can do:

    • Define Properties to store values
    • Define methods to provide functionality
    • Be extended
    • Conform to Protocols
    • Define intialisers
    • Define subscripts to provide access to their variables

Only class can do:

    • Inheritance
    • Type Casting
    • Define deinitialisers
    • Allow reference counting for multiple references.

Major differences between structures and Classes:

    • Structures cannot Inherit from the other types.
    • Classes use type-casting to treat a class as a superclass or subclass, as well as check protocol adoption. Structs can only use the protocol adoption part.
    • Structures does not have deinitializers.
    • Structures cannot has multiple references to the same instance

Https://stackoverflow.com/questions/24217586/structure-vs-class-in-swift-language

Structure vs class in Swift language

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.