Swift Tutorial - Tutorialspoint

(backadmin) #1
enum Enumname {
static var storedTypeProperty = " "

static var computedTypeProperty: Int {

// return an Int value here
}
}

class Classname {
class var computedTypeProperty: Int {
// return an Int value here
}
}

Querying and Setting Properties


Just like instance properties Type properties are queried and set with '.' Syntax just on the
type alone instead of pointing to the instance.


struct StudMarks {
static let markCount = 97
static var totalCount = 0
var InternalMarks: Int = 0 {
didSet {
if InternalMarks > StudMarks.markCount {
InternalMarks = StudMarks.markCount
}
if InternalMarks > StudMarks.totalCount {
StudMarks.totalCount = InternalMarks
}
}
}
}

var stud1Mark1 = StudMarks()
var stud1Mark2 = StudMarks()

stud1Mark1.InternalMarks = 98
Free download pdf