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
// Convention: using GCD and URLSession | |
import Foundation | |
import UIKit | |
enum NetworkError: Error { | |
case invalidURL | |
case noData | |
case failedRequest | |
case returnedError | |
} |
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 NotificationCenter { | |
static let shared = NotificationCenter() | |
// notification to (class name and closures) | |
private var notificationsStorage = [String: [(String: [(String, Any) -> Void)]]]() | |
private init() { } | |
func addObserver(_ class: Any?, name: String, closure: @escaping (String, Any) -> Void) { } | |
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
// https://stackoverflow.com/questions/26028918/how-to-determine-the-current-iphone-device-model | |
import SystemConfiguration | |
import UIKit | |
public extension UIDevice { | |
static let modelName: String = { | |
var systemInfo = utsname() | |
uname(&systemInfo) | |
let machineMirror = Mirror(reflecting: systemInfo.machine) |
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
// https://stackoverflow.com/questions/26028918/how-to-determine-the-current-iphone-device-model | |
func machineName() -> String { | |
var systemInfo = utsname() | |
uname(&systemInfo) | |
let machineMirror = Mirror(reflecting: systemInfo.machine) | |
return machineMirror.children.reduce("") { identifier, element in | |
guard let value = element.value as? Int8, value != 0 else { return identifier } | |
return identifier + String(UnicodeScalar(UInt8(value))) | |
} |
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 <FBRetainCycleDetector/FBRetainCycleDetector.h> | |
self.block = ^{ | |
NSLog(@"%@", self); | |
}; | |
FBRetainCycleDetector *detector = [FBRetainCycleDetector new]; | |
[detector addCandidate:self]; | |
NSSet *retainCycles = [detector findRetainCycles]; | |
NSLog(@"%@", retainCycles); |
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
@interface ViewController () | |
@property (nonatomic, copy) void (^block)(void); | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; |
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
BEGIN:VCALENDAR | |
VERSION:2.0 | |
BEGIN:VEVENT | |
SUMMARY: [A] 🇷🇺Russia vs. 🇸🇦Saudi Arabia | |
DTSTART;TZID=America/Los_Angeles:20180614T080000 | |
DTEND;TZID=America/Los_Angeles:20180614T094500 | |
END:VEVENT |
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
@interface Queue<__covariant ObjectType> : NSObject | |
- (void)enqueue:(ObjectType)value; | |
- (ObjectType)dequeue; | |
@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
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
Queue<Sub *> *subQueue = [[Queue alloc] init]; | |
Queue<Sup *> *supQueue = subQueue; // Warning: Incompatible pointer types initializing 'Queue<Base *>' with an expression of type 'Queue<Sub *>' | |
[supQueue enqueue:[Sub new]]; | |
} | |
return 0; |
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
int main(int argc, const char * argv[]) { | |
@autoreleasepool { | |
Queue<NSString *> *stringQueue = [[Queue alloc] init]; | |
[stringQueue enqueue:@"abc"] | |
Queue<NSNumber *> *numberQueue = [[Queue alloc] init]; | |
[numberQueue enqueue:@123]; | |
[numberQueue enqueue:@"abc"]; // Warning: Incompatible pointer types sending 'NSString *' to parameter of type 'NSNumber *' |
NewerOlder