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
// Example of refactoring with protocols | |
// Original javascript version is from Refactoring (2nd Edition) by Martin Fowler | |
import Foundation | |
struct Play { | |
enum Genre { | |
case tragedy | |
case comedy | |
} |
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
// Swift Standard Librray - String | |
// Keith Harrison http://useyourloaf.com | |
// Import Foundation if you want to bridge to NSString | |
import Foundation | |
// ==== | |
// Initializing a String | |
// ==== |
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
// ------------------------------------- | |
// Swift Integer Quick Guide | |
// ------------------------------------- | |
// Created by Keith Harrison http://useyourloaf.com | |
// Copyright (c) 2017 Keith Harrison. All rights reserved. | |
// | |
// Redistribution and use in source and binary forms, with or without | |
// modification, are permitted provided that the following conditions are met: | |
// |
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
// | |
// CoreDataController.swift | |
// | |
// Created by Keith Harrison http://useyourloaf.com | |
// Copyright (c) 2017 Keith Harrison. All rights reserved. | |
// | |
// Redistribution and use in source and binary forms, with or without | |
// modification, are permitted provided that the following conditions are met: | |
// | |
// 1. Redistributions of source code must retain the above copyright |
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
public enum NetworkingError: Error { | |
case unknown | |
case unexpectedStatus(HTTPURLResponse) | |
} | |
extension URLSession { | |
func load(_ url: URL, | |
completionHandler: @escaping (Result<Data, Error>) -> Void) | |
-> URLSessionDataTask { | |
let task = dataTask(with: url) { data, response, error in |
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 Foundation | |
extension DateFormatter { | |
static let iso8601Full: DateFormatter = { | |
let formatter = DateFormatter() | |
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSZZZZZ" | |
formatter.calendar = Calendar(identifier: .iso8601) | |
formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
formatter.locale = Locale(identifier: "en_US_POSIX") | |
return formatter |
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
// | |
// CoreDataController.h | |
// | |
// Created by Keith Harrison http://useyourloaf.com | |
// Copyright (c) 2016 Keith Harrison. All rights reserved. | |
// | |
// Redistribution and use in source and binary forms, with or without | |
// modification, are permitted provided that the following conditions are met: | |
// | |
// 1. Redistributions of source code must retain the above copyright |
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 Foundation | |
struct Country { | |
let name: String | |
let capital: String | |
var visited: Bool | |
} | |
extension Country: Equatable { | |
static func == (lhs: Country, rhs: Country) -> Bool { |
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
# Global GIT ignored files | |
# Ignore X-code files | |
build/ | |
*~.nib | |
*.so | |
*.pbxuser | |
*.mode* | |
*.perspective* | |
# Xcode 4 |
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
// Set the popover presentation controller when prepare for segue | |
// The presentation style is set in the storyboard | |
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender | |
{ | |
if ([segue.identifier isEqualToString:@"SeguePopover"]) | |
{ | |
self.featuredPPC = segue.destinationViewController.popoverPresentationController; | |
self.featuredPPC.delegate = self; | |
} | |
} |
NewerOlder