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
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 |
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
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) |
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
// 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? { |
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
// 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? { |
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
// 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? { |
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 Event: Decodable { | |
let id: String | |
let event: String | |
let data: [[Int]]? | |
let date: String? | |
} | |
func decode() { | |
let json = """ | |
{ | |
"id": "b1afdc30-47e7-11e8-8931-33f1426b7c32", |
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 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 |
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 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 & |
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 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) |
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 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