Skip to content

Instantly share code, notes, and snippets.

@yoman07
yoman07 / quicksort
Created February 15, 2014 16:08
Objective C Quick Sort
- (NSArray*) quickSortArray:(NSArray*) arr {
if(arr.count <2) {
return arr;
}
NSMutableArray *mutableArr = [arr mutableCopy];
NSMutableArray *leftArray = [[NSMutableArray alloc] init];
NSMutableArray *rightArray = [[NSMutableArray alloc] init];
@yoman07
yoman07 / mergeSort
Created February 15, 2014 16:47
Objective C Merge Sort
- (NSArray*) mergeSortArray:(NSArray*) arr {
if(arr.count <2) {
return arr;
}
NSUInteger middle = arr.count/2;
NSRange leftRange = {0,middle};
NSArray *leftArray = [arr subarrayWithRange:leftRange];
NSRange rightRange = {middle,arr.count-middle};
NSArray *rightArray = [arr subarrayWithRange:rightRange];
@yoman07
yoman07 / obj-c_singleton
Created February 15, 2014 16:51
Singleton in objective-c
- (id) sharedInstance {
static MyObject *sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[MyObject alloc] init];
});
return sharedInstance;
}
@yoman07
yoman07 / atoiobj-c
Created February 16, 2014 15:30
Atoi objective-c
- (int) atoi:(char *) str {
if(!str)
NSLog(@"Enter valid string");
int result = 0;
char *p = str;
while((*p>='0') && (*p<='9')) {
result = result*10 + (*p - '0');
p++;
}
@yoman07
yoman07 / reversingWordsObjectivec
Created February 16, 2014 15:45
Objective-c reversing 
the 
words 
in 
a 
string
- (NSString *) reverseString:(NSString *)str {
NSMutableString *reverseString = [[NSMutableString alloc] initWithCapacity:str.length];
for(int i=str.length -1;i>=0;i--) {
[reverseString appendString:[NSString stringWithFormat:@"%c", [str characterAtIndex:i]]];
}
return reverseString;
}
@yoman07
yoman07 / stack.h
Created February 16, 2014 19:05
Stack objective-c
//
// Stack.h
// testing
//
// Created by Roman Barzyczak on 16.02.2014.
//
//
#import <Foundation/Foundation.h>
@yoman07
yoman07 / generateIcons
Created December 14, 2014 13:57
Generate icons for xcode
mkdir MyIcon
sips -z 29 29 Icon1024.png --out MyIcon/icon_29x29.png
sips -z 58 58 Icon1024.png --out MyIcon/icon_29x29@2x.png
sips -z 87 87 Icon1024.png --out MyIcon/icon_29x29@3x.png
sips -z 40 40 Icon1024.png --out MyIcon/icon_40x40.png
sips -z 80 80 Icon1024.png --out MyIcon/icon_40x40@2x.png
sips -z 120 120 Icon1024.png --out MyIcon/icon_40x40@3x.png
sips -z 50 50 Icon1024.png --out MyIcon/icon_50x50.png
@yoman07
yoman07 / Alert with fabric
Last active September 2, 2016 17:06
Display alert view with settings button
//
// AlertControllerFabric.swift
// Mapa Turystyczna
//
// Created by Roman Barzyczak on 05.04.2016.
//
import Foundation
class AlertHelper {
import Foundation
extension Dictionary {
static func contentsOf(url: URL) -> Dictionary<Key, Value>? {
do {
let data = try Data(contentsOf:url)
let properties = try PropertyListSerialization.propertyList(from: data, options: [], format: nil) as? [Key: Value]
return properties
} catch {
return nil
}
import UIKit
final class Action: NSObject {
private let _action: () -> ()
init(action: @escaping () -> ()) {
_action = action
super.init()
}
func action() {
_action()