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 singleton = Singleton.default |
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 Singleton { | |
static let `default` = Singleton() | |
private init() { | |
} | |
} |
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 "Singleton.h" | |
@implementation Singleton | |
+ (id)shared { | |
static Singleton *shared = nil; | |
static dispatch_once_t onceToken; | |
dispatch_once(&onceToken, ^{ | |
shared = [[self alloc] init]; | |
}); |
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/Foundation.h> | |
@interface Singleton : NSObject | |
+ (id)shared; | |
@end |
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 Car: Codable { | |
let model: String | |
let topSpeed: Int | |
let url: URL | |
enum CodingKeys: String, CodingKey { | |
case model = "title" | |
case topSpeed = "speed" | |
case url = "link" | |
} |
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
do { | |
let car = try JSONDecoder().decode(Car.self, from: jsonData) | |
} catch { | |
print("Unresolved error: \(error)") | |
} |