Skip to content

Instantly share code, notes, and snippets.

View zarochintsev's full-sized avatar

Oleksandr Zarochintsev zarochintsev

View GitHub Profile
let singleton = Singleton.default
class Singleton {
static let `default` = Singleton()
private init() {
}
}
#import "Singleton.h"
@implementation Singleton
+ (id)shared {
static Singleton *shared = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
shared = [[self alloc] init];
});
#import <Foundation/Foundation.h>
@interface Singleton : NSObject
+ (id)shared;
@end
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"
}
do {
let car = try JSONDecoder().decode(Car.self, from: jsonData)
} catch {
print("Unresolved error: \(error)")
}