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