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
//: Playground - noun: a place where people can play | |
import UIKit | |
import XCPlayground | |
let mainView = UIView(frame: CGRect(x: 0, y: 0, width: 375, height: 667 )) | |
mainView.backgroundColor = UIColor.blue | |
let sun = UIImageView(image: UIImage(named: "Sun")) | |
sun.frame.size = CGSize(width: mainView.frame.width/2, height: mainView.frame.width/2) | |
sun.center.y = mainView.bounds.height + sun.frame.width/2 |
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
import UIKit | |
import XCPlayground | |
public class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
var tableView: UITableView! | |
var numbers = [Int]() | |
override public func viewDidLoad() { |
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
import UIKit | |
import CoreLocation | |
import Charts | |
class ViewController: UIViewController, ChartViewDelegate { | |
let locationManager = CLLocationManager() | |
var latitude = Double() | |
var longitude = Double() | |
var storeData = DataStore.sharedInstance |
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
func addNotificationObservers(){ | |
NotificationCenter.default.addObserver(self, selector: #selector(switchViewController(with:)), name: .closeLoginVC, object: nil) | |
NotificationCenter.default.addObserver(self, selector: #selector(switchViewController(with:)), name: .closeMainVC, object: nil) | |
} |
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
func addNotificationObservers(){ | |
NotificationCenter.default.addObserver(self, selector: #selector(switchViewController(with:)), name: .closeLoginVC, object: nil) | |
NotificationCenter.default.addObserver(self, selector: #selector(switchViewController(with:)), name: .closeMainVC, object: nil) | |
} |
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
extension Notification.Name { | |
static let closeLoginVC = Notification.Name("close-login-view-controller") | |
static let closeMainVC = Notification.Name("close-main-view-controller") | |
} | |
enum StoryboardID: String { | |
case loginVC = "login-view-controller" |
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
func switchViewController(with notification: Notification) { | |
switch notification.name { | |
case Notification.Name.closeLoginVC: | |
switchToViewController(with: .mainVC) | |
case Notification.Name.closeMainVC: | |
switchToViewController(with: .loginVC) | |
default: | |
fatalError("\(#function) - Unable to match notficiation name.") | |
} |
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
func loadViewController(withID id: StoryboardID) -> UIViewController { | |
let storyboard = UIStoryboard(name: "Main", bundle: nil) | |
return storyboard.instantiateViewController(withIdentifier: id.rawValue) | |
} | |
func add(viewController: UIViewController, animated: Bool = false) { | |
self.addChildViewController(viewController) | |
containerView.addSubview(viewController.view) | |
containerView.alpha = 0.0 |
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
func loadInitialViewController() { | |
let id: StoryboardID = FIRAuth.auth()?.currentUser?.uid != nil ? .mainVC : .loginVC | |
self.actingVC = self.loadViewController(withID: id) | |
self.add(viewController: self.actingVC, animated: true) | |
} |
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
func logout() { | |
do{ | |
try FIRAuth.auth()?.signOut() | |
}catch let error{ | |
print(error) | |
} | |
NotificationCenter.default.post(name: .closeMainVC, object: nil) | |
} |
OlderNewer