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 String { | |
func s_n_a_k_e_c_a_s_e_d() -> String { // OK, you can name it just “snakecased” if you prefer… :) | |
var charactersToRemove = CharacterSet.alphanumerics.inverted | |
charactersToRemove.remove(charactersIn: " ") | |
let result = components(separatedBy: charactersToRemove).joined(separator: "") | |
return result.replacingOccurrences(of: " ", with: "_").lowercased() | |
} | |
} |
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 | |
var nonAlphaNumeric = CharacterSet.alphanumerics.inverted | |
nonAlphaNumeric.remove(charactersIn: " ") |
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 | |
protocol Coordinator { | |
func start() | |
} | |
@UIApplicationMain | |
class AppDelegate: UIResponder, UIApplicationDelegate { | |
var window: UIWindow? |
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 Item { | |
let name: String | |
var price: UInt | |
init(name: String, price: UInt) { | |
self.name = name | |
self.price = price | |
} | |
} |
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
class Cart { | |
let items: [Item] | |
var total: UInt { | |
return items.reduce(0) { sum, item in | |
sum + item.price | |
} | |
} | |
init(items: [Item]) { |
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
class Item { | |
let name: String | |
var price: UInt | |
init(name: String, price: UInt) { | |
self.name = name | |
self.price = price | |
} | |
} |
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 listUsers(completion: Result<[User]> -> Void) { | |
// Get the list of users | |
// If success, call completion(Result.Success(users)) | |
// If error, call completion(Result.Error(error)) | |
} |
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
enum Result<T> { | |
case Success(T) | |
case Error(NSError) | |
} | |
func listMessages(completion: Result<[Message]> -> Void) { | |
// Get the list of messages | |
// If success, call completion(Result.Success(messages)) | |
// If error, call completion(Result.Error(error)) | |
} |
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 listMessages(completion: Result -> Void) { | |
// Get the list of messages | |
// If success, call completion(.Success(messages: messages)) | |
// If error, call completion(.Error(error: error)) | |
} |
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
enum Result { | |
case Success(messages: [Message]) | |
case Error(error: NSError) | |
} |
NewerOlder