This file contains 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
enum OrderSize { | |
case small | |
case medium | |
case large | |
} | |
enum SpiceRange { | |
case spicy | |
case hot | |
case extraHot |
This file contains 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 Biriyani { | |
let count: Int | |
let size: OrderSize | |
let spiceRange: SpiceRange | |
init (count: Int, size: OrderSize, spiceRange: SpiceRange) { | |
self.count = count | |
self.size = size | |
self.spiceRange = spiceRange | |
} |
This file contains 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 Biriyani { | |
let count: Int | |
let size: OrderSize | |
let spiceRange: SpiceRange | |
let type: BiriyaniType | |
init (count: Int = 1, size: OrderSize = .medium, spiceRange: SpiceRange = .spicy, type: BiriyaniType = .nonveg) { | |
self.count = count | |
self.size = size | |
self.spiceRange = spiceRange |
This file contains 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
enum BiriyaniType { | |
case veg | |
case nonveg | |
} | |
class Biriyani { | |
let count: Int | |
let size: OrderSize | |
let spiceRange: SpiceRange | |
let type: BiriyaniType |
This file contains 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 Person { | |
let name: String | |
init(name: String) { | |
self.name = name | |
} | |
deinit { | |
print("\(name) is being deinitialized") | |
} | |
} |
This file contains 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 Person { | |
let name: String | |
var apartment: Apartment? | |
init(name: String) { | |
self.name = name | |
} | |
deinit { | |
print("\(name) is being deinitialized") | |
} |
This file contains 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
var person: Person? = Person(name: "John Doe") | |
var apartment: Apartment? = Apartment(number: 123) | |
person?.apartment = apartment | |
apartment?.person = person | |
person = nil | |
apartment = nil | |
// output: | |
// |
This file contains 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 Person { | |
... | |
} | |
class Apartment { | |
... | |
weak var person: Person? | |
... | |
} |
This file contains 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 HTMLElement { | |
let name: String | |
let text: String? | |
lazy var asHTML: () -> String = { | |
return "<\(self.name)>\(self.text)</\(self.name)>" | |
} | |
init(name: String, text: String? = nil) { |
This file contains 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 HTMLElement { | |
... | |
lazy var asHTML: () -> String = { [weak self] in | |
guard let htmlElement = self else { return "" } | |
return "<\(htmlElement.name)>\(htmlElement.text)</\(htmlElement.name)>" | |
} | |
... | |
} |