Swift Classes and structures

Source: Internet
Author: User

Classes and structs have a lot in common:

Defining properties to store data

Define method Execution function handling

Define subscript to access their values by subscript

Initialize their state

Extend its functionality with extensions (Extension)

Compliance Agreement (PROTOCOL). The protocol provides a specific standard

Function

Analogy structure multi-out function:


can inherit another class


You can check the type of the execution period object


destructor Frees resources


reference count agrees that a class instance has multiple references  

definition of class and struct body  

define classes and struct bodies:  

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 =falsevarfr Amerate = 0.0 var name:string?}

Instantiation of classes and struct bodies


struct Resolution {var width= 0 var height =0}class videomode {var Resolution = Resolution () var interlaced =falsevarfram Erate = 0.0var name:string?

}let someresolution= Resolution ()//let someresolution = Resolution (width:10,height:20) Let somevideomode= Videomode ()


Swift Exchange Discussion Forum Forum: http://www.cocoagame.net

Welcome to add Swift Technology Group: 362298485




Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

Swift Classes and structures

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.