Skip to content

Instantly share code, notes, and snippets.

@Ben-G
Created July 28, 2015 21:57
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 Ben-G/03a7bc42891ec49ec62e to your computer and use it in GitHub Desktop.
Save Ben-G/03a7bc42891ec49ec62e to your computer and use it in GitHub Desktop.
Edge cases with default values for methods in Swift
//: Playground - noun: a place where people can play
import UIKit
protocol APIClientProtocol {
init()
init(urlSession: NSURLSession)
init(apiKey: String)
init(urlSession: NSURLSession, apiKey: String)
}
struct APIClient: APIClientProtocol {
init(urlSession: NSURLSession = NSURLSession.sharedSession(), apiKey: String = "") {
}
}
let client = APIClient()
let client2 = APIClient(urlSession: NSURLSession())
let client3 = APIClient(apiKey: "")
let client4 = APIClient(urlSession: NSURLSession(), apiKey: "")
protocol AProtocol {
func a()
}
struct A: AProtocol {
func a(string: String = "") {
}
func a() {
}
}
A().a()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment