Skip to content

Instantly share code, notes, and snippets.

View aratkevich's full-sized avatar
👋

ratkevich aratkevich

👋
View GitHub Profile
@aratkevich
aratkevich / iOS_version.m
Last active April 11, 2017 11:14
Проверка версии iOS
if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_6_1) {
return [UIImage imageNamed:@"UIActivity7"];
} else {
return [UIImage imageNamed:@"UIActivity"];
}
@aratkevich
aratkevich / TypeDevice.m
Last active April 11, 2017 11:15
Type device
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
return [UIImage imageNamed:@"iPadIcon"];
} else {
return [UIImage imageNamed:@"iPhoneIcon"];
}
@aratkevich
aratkevich / CoreData.m
Last active April 11, 2017 11:15
CoreData
#import <CoreData/CoreData.h>
@property (readonly, strong) NSPersistentContainer *persistentContainer;
- (void)saveContext;
#pragma mark - Core Data stack
@synthesize persistentContainer = _persistentContainer;
- (NSPersistentContainer *)persistentContainer {
@aratkevich
aratkevich / Скрипт TODO: FIXME:
Created April 11, 2017 06:51
Скрипт TODO: FIXME:
TAGS="TODO:|FIXME:"
echo "searching ${SRCROOT} for ${TAGS}"
find "${SRCROOT}" \( -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
@aratkevich
aratkevich / deleteSqlite.sh
Last active April 11, 2017 11:16
Скрипт delete sqlite
rm /Users/$(whoami)/Library/Developer/CoreSimulator/Devices/*/data/Containers/Data/Application/*/Library/Application\ Support/GiftLister.sqlite
@aratkevich
aratkevich / ListInSwift.swift
Last active April 22, 2017 10:45
List in Swift
class Node<T> {
var value: T
weak var parent: Node?
var children: [Node] = []
init(value: T) {
self.value = value
}
func add(child: Node) {
@aratkevich
aratkevich / ssid.m
Created June 20, 2017 07:23
SSID wifi
NSString *ssid = nil;
NSArray *ifs = (id)CFBridgingRelease(CNCopySupportedInterfaces());
for (NSString *ifnam in ifs) {
NSDictionary *info = (id)CFBridgingRelease(CNCopyCurrentNetworkInfo((__bridge CFStringRef)ifnam));
if (info[@"SSID"]) {
ssid = [info[@"SSID"] copy]
}
}
import Foundation
class SingletonC : NSObject {
class var sharedInstance : SingletonC {
struct Static {
static var onceToken : dispatch_once_t = 0
static var instance : SingletonC? = nil
}
dispatch_once(&Static.onceToken) {
@aratkevich
aratkevich / stronglyTyped.swift
Created September 4, 2017 18:34
Strongly typed identifiers
// Option 1
protocol Identity {
associatedtype Identifier
var id: Identifier {get set}
}
struct Person: Identity {
typealias Identifier = String
var id: Identifier
@aratkevich
aratkevich / singleton.swift
Created January 7, 2018 05:31
Lazy singleton
static var shared: SomeManager {
guard let instance = SomeManager._shared else {
SomeManager._shared = SomeManager()
return SomeManager._shared!
}
return instance
}