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
/* | |
One of the first things someone new to iOS Development finds is that dealing with the keyboard is trickier | |
than they think it should be. Simply changing the scrolling extents of a UITableView (or UIScrollView, or | |
UICollectionView) that is partially covered by they keyboard reveals a lot about the internals of how iOS | |
works and highlights various "gotchas" that need to be considered. | |
There are various ways to know that a keyboard has been shown - but observing some specific notifications | |
provides a reliable way to allow you to modify your views to deal with it. |
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
Đinh nghĩa capture list như ví dụ sau: | |
lazy var someClosure: (Int, String) -> String = { | |
[unowned self, weak delegate = self.delegate!] (index: Int, stringToProcess: String) -> String in | |
// closure body goes here | |
} | |
Nếu một closure không có tham số thì ta có thể mô tả đơn giản như thế này: | |
lazy var someClosure: () -> 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 HTMLElement { | |
let name: String | |
let text: String? | |
lazy var asHTML: () -> String = { | |
[unowned self] in | |
if let text = self.text { | |
return "<\(self.name)>\(text)</\(self.name)>" | |
} else { |
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 HTMLElement { | |
let name: String | |
let text: String? | |
lazy var asHTML: () -> String = { | |
if let text = self.text { | |
return "<\(self.name)>\(text)</\(self.name)>" | |
} else { | |
return "<\(self.name) />" |
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 Country { | |
let name: String | |
var capitalCity: City! | |
init(name: String, capitalName: String) { | |
self.name = name | |
self.capitalCity = City(name: capitalName, country: self) | |
} | |
} |
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 Customer { | |
let name: String | |
var card: CreditCard? | |
init(name: String) { | |
self.name = name | |
} | |
deinit { print("\(name) is being deinitialized") } | |
} |
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
var john: Person? | |
var unit4A: Apartment? | |
john = Person(name: "John Appleseed") | |
unit4A = Apartment(unit: "4A") |
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 Person { | |
let name: String | |
init(name: String) { self.name = name } | |
var apartment: Apartment? | |
deinit { print("\(name) is being deinitialized") } |
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 Person { | |
let name: String | |
init(name: String) { self.name = name } | |
var apartment: Apartment? |
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 Car { | |
let name: String | |
init(name: String) { | |
self.name = name | |
print("\(name) is being initialized") |
NewerOlder