pod 'Snakepit'
override func viewDidLoad() {
super.viewDidLoad()
showAlert("This is an alert")
.cancelAction(title: "Cancel") { print("Cancel pressed") }
.action(title: "Confirm") { print("Confirm pressed") }
showActionSheet("This is an action sheet")
.action(title: "option 1") { print("option1 pressed") }
.action(title: "option 2") { print("option2 pressed") }
.action(title: "option 3") { print("option3 pressed") }
.cancelAction(title: "Cancel") { print("Cancel pressed") }
}
Let's say you have a
UITabBarController
inMain.storyboard
calledTabBarViewController
, make sure its storyboard ID is alsoTabBarViewController
// Step 1
enum Storyboard: String, StoryboardGettable {
case Main
var bundle: Bundle? {
return Bundle.main
}
}
// Step 2
let tabVc = Storyboard.Main.get(TabbarViewController.self)
Let's say you have a custom prototype cell
MyCell
, make sure its reuse identifier isMyCell
.
override func tableView(_ tableView: UITableView,
cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let myCell = tableView.deque(cell: MyCell.self, for: indexPath)
return myCell
}
you can use tableView.register(cell: MyCell.self)
in viewDidLoad
if you want to register a cell from a .xib
UIColor(0xFF0000) // the same as UIColor.red
UIColor(0x00FF00) // the same as UIColor.green
UIColor(0x0000FF) // the same as UIColor.blue
UIButton().onTouch(for: .touchUpInside) {
print("button pressed")
}
UISwitch().onTouch(for: .valueChanged) {
print("switch toggled")
}
UITapGestureRecognizer().onTouch {
print("tap detected")
}
UIBarButtonItem(title: "item", style: .plain) {
print("item pressed")
}
Let's say you want to store a
URL
inUserDefault
with keymyURL
and a phone number (String
) with keyphone
// Define keys
enum UserDefaultsKey: String, UserDefaultsGettable {
case myUrl
case phone
static var bundle: Bundle {
return Bundle.main
}
}
// Save to UserDefault
let url = URL(string: "www.google.com")
UserDefaultsKey.myUrl.set(url)
// Retrive from UserDefault
let myURL = UserDefaultsKey.myUrl.get(URL.self)
// Remove from UserDefault
UserDefaultsKey.myUrl.remove()