This file contains hidden or 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
// No memberwise initializer | |
struct Player { | |
let name: String | |
var score: Int = 0 | |
init(json: [String: AnyObject]) { | |
} | |
} | |
// you have the both initializers: |
This file contains hidden or 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
Remove @main or @UIApplicationMain |
This file contains hidden or 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
// Assuming you use one storyboard per view controller | |
extension UIViewController { | |
static func fromStoryboard() -> Self { | |
let name = String(describing: Self.self) | |
let sb = UIStoryboard(name: name, bundle: nil) | |
return sb.instantiateViewController(identifier: name) as! Self | |
} | |
} |
This file contains hidden or 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 Singleton { | |
private static var instance = Singleton() | |
#if DEBUG | |
static var stubbedInstance: Singleton? | |
#endif | |
static var shared: Singleton { | |
#if DEBUG | |
if let stubbedInstance = stubbedInstance { return stubbedInstance } | |
#endif |
This file contains hidden or 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 ViewController { | |
var manager: Singleton { | |
return Singleton.shared | |
} | |
} | |
// in unit testing target | |
class TestingViewController: ViewController { | |
override var manager: Singleton { Singleton() } | |
} |
OlderNewer