View gist:b57cfe037227eb948c0ad6c80c1aefee
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
DispatchQueue.main.async { | |
// Init Drawer | |
let appDelegate = UIApplication.shared.delegate as! AppDelegate | |
let storyBoard = UIStoryboard.init(name: "Main", bundle: Bundle.main) | |
let navVC = storyBoard.instantiateViewController(withIdentifier: "MainController") as! MyTabBarController | |
navVC.loggedAlready = true | |
// is the main controller for the drawer. | |
let drawerVC = storyBoard.instantiateViewController(withIdentifier: "DrawerVC") | |
// is the drawer, and the drawer needs a main controller | |
appDelegate.drawerController.mainViewController = navVC |
View gist:8b7af5f6eb2469d41e15a57ddbb86951
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
static func showStandardMessage(reference: UIViewController, title: String, message: String) { | |
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) | |
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) | |
alert.view.setNeedsLayout() | |
reference.present(alert, animated: true, completion: nil) | |
} | |
static func showStartCancel(reference: UIViewController, title: String, message: String, callback: @escaping (UIAlertAction)->()) { | |
// create the alert | |
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.alert) |
View gist:8f280d6300f6e97933e0400d16e9a530
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
// REMARK: format date for better display | |
func convertDate(date: Date) -> String? { | |
let dateFormatterGet = DateFormatter() | |
dateFormatterGet.dateFormat = "yyyyMMdd HH:mm:ss" | |
let dateString = dateFormatterGet.string(from: date) | |
return dateString | |
} | |
// REMARK: server sends dates on JS string format | |
func convertJSDate(date: String) -> String? { |
View gist:c72a50b7dca030e72d93f13989b556d2
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
// REMARK: format date for better display | |
func convertDate(date: Date) -> String? { | |
let dateFormatterGet = DateFormatter() | |
dateFormatterGet.dateFormat = "yyyyMMdd HH:mm:ss" | |
let dateString = dateFormatterGet.string(from: date) | |
return dateString | |
} | |
// REMARK: server sends dates on JS string format | |
func convertJSDate(date: String) -> String? { |
View gist:0562bf47f162c4351d6f05b602203c7d
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
// REMARK: format date for better display | |
func convertDate(date: Date) -> String? { | |
let dateFormatterGet = DateFormatter() | |
dateFormatterGet.dateFormat = "yyyyMMdd HH:mm:ss" | |
let dateString = dateFormatterGet.string(from: date) | |
return dateString | |
} | |
// REMARK: server sends dates on JS string format | |
func convertJSDate(date: String) -> String? { |
View gist:70649c0d8028a697764a2d06eea61407
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
struct Event: Decodable { | |
let id: String | |
let event: String | |
let data: [[Int]]? | |
let date: String? | |
} | |
func decode() { | |
let json = """ | |
{ | |
"id": "b1afdc30-47e7-11e8-8931-33f1426b7c32", |
View gist:6ee30b24de0ceebc79330ef8945e39b1
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 customersInLine = ["Alex", "Ewa", "Barry", "Daniella"] | |
print(customersInLine.remove(at:0)) // Alex | |
func serve(customer : @autoclosure () -> String) { | |
print("serving customer \(customer())") | |
} | |
serve(customer: customersInLine.remove(at:0)) // Ewa |
View gist:4ebca639123a76f62280fa911446a694
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 param = "try change me brother" | |
func defaultFunc(_ param:String) { | |
// param = "I change you" won't compiles | |
} | |
defaultFunc(param) | |
print(param) // try change me brother | |
func inOutFunc(_ param :inout String) { | |
param = "I changed you" | |
} | |
inOutFunc(¶m) // needs explicit & |
View gist:e4d4d831305e2107997c25e6c4182dd1
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 dictionary = [String: Int]() | |
var counts = "all for all fun fun funny".components(separatedBy:" ").map({ | |
var counter = dictionary[$0] ?? 0 | |
dictionary[$0] = counter + 1 | |
}) | |
print(dictionary) |
View gist:f0dd9bb38cd4d1cc7ccc1ffdbcbefe6c
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
struct User { | |
let id: Int | |
let name: String | |
let username: String | |
init?(dictionary: Dictionary<String: Any>) { | |
guard | |
let id = dictionary[“id”] as? Int, | |
let name = dictionary[“name”] as? String, | |
let username = dictionary[“username”] as? String | |
else { |
NewerOlder