This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Payment { | |
var amount: Float | |
var comission: Float | |
var totalAmount: Float { | |
return amount + comission | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Pin { | |
var value: String { | |
willSet { | |
print("new pin value: \(newValue)") | |
} | |
didSet { | |
print("old pint value: \(oldValue)") | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PropertyStruct { | |
static var storedTypeProperty = "1" | |
static var computedTypeProperty: Double { | |
return 10.0 | |
} | |
} | |
print("struct type property: \(PropertyStruct.storedTypeProperty)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player { | |
var playing: Bool = false | |
func play() { | |
playing = true | |
} | |
func stop() { | |
playing = false |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct NameComponents { | |
var firstName: String | |
var lastName: String | |
mutating func change(firstName: String, lastName: String) { | |
self.firstName = firstName | |
self.lastName = lastName | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct PropertyStructM { | |
static func typeMethod() { | |
// Code | |
} | |
} | |
PropertyStructM.typeMethod() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// PUT code into playground | |
var globalVariable = "globalString" | |
func fly() { | |
var localVariable = "localString" | |
} | |
struct Airplane { | |
// Local Variable | |
var number: String |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class VideoPlayer: Player { | |
var file: String | |
var width: Int | |
var height: Int | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AudioPlayer: Player { | |
// Overriding Property Observers | |
override var playing: Bool { | |
didSet { | |
print("\(self) did set playing") | |
} | |
} | |
// Overriding Methods |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Setting: NSObject { | |
enum State { | |
case off, on | |
} | |
enum Action { | |
case setup, open | |
} | |