Skip to content

Instantly share code, notes, and snippets.

@AdrienGiboire
Last active October 1, 2019 02:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AdrienGiboire/ab874b1faead0089a38ca608f5f0ee63 to your computer and use it in GitHub Desktop.
Save AdrienGiboire/ab874b1faead0089a38ca608f5f0ee63 to your computer and use it in GitHub Desktop.
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
}
}
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