Last active
October 1, 2019 02:18
-
-
Save AdrienGiboire/ab874b1faead0089a38ca608f5f0ee63 to your computer and use it in GitHub Desktop.
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
import UIKit | |
import RealmSwift | |
import TTTabBar | |
let realm = try! Realm() | |
let octoClient = OctolyClient( | |
baseUrl: "https://www.octoly.com/api", | |
apiVersion: "v1") | |
var currentUser:User? = realm.objects(User).first; | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window:UIWindow? = UIWindow(frame: UIScreen.mainScreen().bounds) | |
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { | |
if let window = window { | |
if (currentUser != nil) { | |
window.rootViewController = TabBar() | |
} else { | |
let navcontroller = UINavigationController() | |
navcontroller.viewControllers = [SignInController()] | |
window.rootViewController = navcontroller | |
} | |
window.backgroundColor = TOPBAR_BACKGROUND_COLOR | |
window.makeKeyAndVisible() | |
} | |
return true | |
} | |
} |
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
import UIKit | |
import SwiftHTTP | |
class SignInController:UIViewController, UITextFieldDelegate { | |
func connectToOctoly() { | |
/* ... */ | |
let params = ["email": (self.emailField?.text)!, "password": (self.passwordField?.text)!] | |
octoClient.post("/session", options: params) { | |
json in | |
let responseData = json as! NSDictionary | |
currentUser = User() | |
if let token = responseData["private_token"] as? String { | |
currentUser?.privateToken = token | |
octoClient.setToken(token) | |
} | |
if let first_name = responseData["first_name"] as? String { | |
currentUser?.firstName = first_name | |
} | |
if let last_name = responseData["last_name"] as? String { | |
currentUser?.lastName = last_name | |
} | |
try! realm.write { | |
realm.add(currentUser!) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment