0% found this document useful (0 votes)
13 views

Swift Cheat Sheet Formatted

This document is a cheat sheet for Swift programming, focusing on object-oriented programming concepts. It covers classes, stored properties, computed properties, type properties, and type methods with examples. Key classes and structures like MyPointClass, Distance, and Car are illustrated to demonstrate these concepts.

Uploaded by

DARK DUCK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Swift Cheat Sheet Formatted

This document is a cheat sheet for Swift programming, focusing on object-oriented programming concepts. It covers classes, stored properties, computed properties, type properties, and type methods with examples. Key classes and structures like MyPointClass, Distance, and Car are illustrated to demonstrate these concepts.

Uploaded by

DARK DUCK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Swift Cheat Sheet (Object-Oriented Programming)

class MyPointClass {
var x = 0.0
var y = 0.0
}
class MyPointClass { var ptA = MyPointClass()
} ptA.x = 25.0
var ptA = MyPointClass() ptA.y = 50.0
Stored Properties

class Distance {
var miles: Double = 0.0
var km: Double {
get {
return 1.60934 * mil
}
set (km) {
miles = km / 1.6093
class PointMath { }
lazy var someValue = 1.2345 }
} }
operties Computed Properties

class MyPointClass {
var x: Double = 0.0 {
willSet(newX) {
print("About to set to \(newX)")
}
didSet(oldX) {
print("Changed from \(oldX)")
} class MyPointClass {
} static var origin = (x: 0, y:
} }
vers Type Properties

struct Go {
var row: Int class Car {
mutating func move(row: Int) { class func speedLimit() ->
self.row += row return 120
} }
} }
ods in Structures Type Method

You might also like