Swift class and struct

Source: Internet
Author: User

Classes and struct have many commonalities:

 

Define attributes to store data

Define method execution function processing

Define subscripts and access their values through subscripts

Initialize their status

Extend its functions through extension

Complies with the Protocol, which provides a specific standard

Function

Functions of the analogy struct:


Can inherit another class


Ability to check the types of objects during runtime


Destructor release resources


Reference count allows a class instance to have multiple references

Class and struct Definition

Define classes and struct:

class SomeClass {// class definition goes here } struct SomeStructure { // structure definition goes here }

 

Instance:

struct Resolution { var width= 0 var height =0} class VideoMode { var resolution = Resolution() var interlaced =falsevarframeRate = 0.0 var name: String?}

 

 

Class and struct instantiation


struct Resolution { var width= 0 var height =0}class VideoMode { var resolution = Resolution()var interlaced =falsevarframeRate = 0.0var name: String?}let someResolution= Resolution()//let               someResolution                    = Resolution(width:10,height:20)let someVideoMode= VideoMode()

Swift discussion forum: http://www.cocoagame.net

Welcome to the swift technology exchange group: 362298485




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.