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
protocol CellType { | |
static var identifier: String { get } | |
} | |
extension CellType { | |
static var identifier: String { return "\(Self.self)" } | |
} | |
extension UITableView { | |
func register<Cell>(forReuse cell: Cell.Type) |
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 Alamofire | |
import SwiftyJSON | |
protocol NetworkClientType { | |
func makeRequest<Response: JSONDecodable>(url: String, | |
params: [String : AnyObject], | |
callback: (Response?, ErrorType?) -> Void) | |
} | |
struct NetworkClient: NetworkClientType { |
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
let defaults = Defaults() | |
let hasLoggedIn = true | |
defaults.save(true, forKey: .LoggedIn) | |
defaults.save(false, forKey: .NotificationsEnabled) | |
let regularOrder = Order(item: "Cold Brew", size: .Large) | |
let alternateOrder = Order(item: "Latte", size: .Small) | |
defaults.save(regularOrder) | |
defaults.save(alternateOrder, forKey: .Alternate) |
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
let defaults = Defaults() | |
let person = Person(firstName: "Austin", lastName: "Feight", age: -3) | |
defaults.save(person) | |
let fetched: Person? = defaults.fetch(Person.self) | |
print("\(fetched!.firstName) \(fetched!.lastName) is \(fetched!.age) years old") | |
// Output: Austin Feight is -3 years old |
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
// Define Model | |
struct Person { | |
let firstName: String | |
let lastName: String | |
let age: Int | |
} |
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 Person: DefaultConvertible { | |
private static let firstNameKey = "first_name" | |
private static let lastNameKey = "last_name" | |
private static let ageKey = "age" | |
var serialized: [String : AnyObject] { | |
return | |
[ | |
Person.firstNameKey: firstName as AnyObject, | |
Person.lastNameKey: lastName as AnyObject, |
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 Person { | |
var firstName: String | |
var lastName: String | |
var age: String | |
} | |
let person = Person(firstName: "Austin", lastName: "Feight", age: -3) | |
UserDefaults.standard.set(person) | |
let fetchedPerson = UserDefaults.standard.fetch(Person.self) |
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
protocol DefaultConvertible { | |
var serialized: [String : AnyObject] { get } | |
init?(dictionary: [String : AnyObject]) | |
} | |
class Defaults { | |
let userDefaults = NSUserDefaults.standardUserDefaults() | |
func save<T: DefaultConvertible>(toSave: T) | |
{ |
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
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
_multipeerController = [MultipeerController.alloc init]; | |
_multipeerController.delegate = self; | |
[_multipeerController start]; | |
_graphManager = [GraphManager.alloc init]; | |
_graphManager.delegate = self; | |
_myPeerID = [MCPeerID.alloc init]; | |
_selectedPeer = -1; |
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
override func viewDidLoad() | |
{ | |
super.viewDidLoad() | |
initMultipeerDependencies() | |
configureTableView() | |
addSegmentedControl() | |
addDismissKeyboardRecognizer() |