Skip to content

Instantly share code, notes, and snippets.

View adriantofan's full-sized avatar

Adrian Tofan adriantofan

View GitHub Profile
NSLocale *locale = [NSLocale currentLocale];
// [locale localeIdentifier] fr_FR (i'm in france)
NSLog(@"current locale: %@", locale.localeIdentifier);
NSArray* preferredLanguages = [NSLocale preferredLanguages];
NSLog(@"preferredLanguages: %@", preferredLanguages);
// en,fr ( the interface is in english )
NSString* code = [locale objectForKey:NSLocaleCurrencyCode];
@adriantofan
adriantofan / gist:23d01c97a9f47f722495
Created March 6, 2015 08:23
add/remove childviewcontroller
[self addChildViewController:vc];
// [vc willMoveToParentViewController:self] called automatically
[self.view addSubview:vc.view]; // or something like this.
[vc didMoveToParentViewController:self];
// For removing view controllers:
[vc willMoveToParentViewController:nil];
[vc.view removeFromSuperview]; // or something like this
[vc removeFromParentViewController];
@adriantofan
adriantofan / gist:bd5af4fd74124f5c50b1
Created March 31, 2015 08:02
self sizing cells iOS 8
self.tableView.estimatedRowHeight = 44.0;
self.tableView.rowHeight = UITableViewAutomaticDimension;
//
cell.textLabel.numberOfLines = 0;
@adriantofan
adriantofan / x
Created April 14, 2015 09:43
NSArray
//http://ronnqvi.st/array-intersections-and-differences
NSPredicate *intersectPredicate =
[NSPredicate predicateWithFormat:@"SELF IN %@", otherArray];
NSArray *intersect =
[firstArray filteredArrayUsingPredicate:intersectPredicate];
NSPredicate *relativeComplementPredicate = // a minus b
[NSPredicate predicateWithFormat:@"NOT SELF IN %@", otherArray];
NSArray *relativeComplement =
@adriantofan
adriantofan / ProductCreateHeader.xib
Last active August 29, 2015 14:19
table view self sizing header
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="7531" systemVersion="14D131" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="7520"/>
</dependencies>
<customFonts key="customFonts">
<mutableArray key="FreightSansPro-Book.otf">
<string>FreightSansProBook-Regular</string>
</mutableArray>
</customFonts>
@adriantofan
adriantofan / version.sh
Last active August 29, 2015 14:23 — forked from osteslag/version.sh
#!/bin/sh
# Script for managing build and version numbers using git and agvtool.
# Change log:
# v1.0 18-Jul-11 First public release.
# v1.1 29-Sep-12 Launch git, agvtool via xcrun.
version() {
git show-ref --tags
git format-patch -n --stdout sha >file
git am file
@adriantofan
adriantofan / gist:ca867ce2f537996ec1bc
Created June 25, 2015 12:43
preprocessor objective-c
The ' ## ' preprocessing operator performs token pasting.
#define macro(x) ## x \\gets replaced by the value of x
Stringification # x makes x in to a string so @#x in objective-c
@adriantofan
adriantofan / outputStreamToFileAtPathDemo.m
Last active August 29, 2015 14:26 — forked from mingchen/outputStreamToFileAtPathDemo.m
How to use NSOutputStream's outputStreamToFileAtPath
- (void)outputStreamToFileAtPathDemo
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *file = [documentsDirectory stringByAppendingPathComponent:@"foo.dat"];
NSLog(@"file: %@", file);
NSOutputStream *output = [NSOutputStream outputStreamToFileAtPath:file append:NO];
[output open];
no separators for empty cells
tableView.tableFooterView = UIView(frame: CGRectZero)
//http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working
// From End To end
cell.separatorInset = UIEdgeInsetsZero;
cell.layoutMargins = UIEdgeInsetsZero;
cell.preservesSuperviewLayoutMargins = NO;
// invisible