Skip to content

Instantly share code, notes, and snippets.

@inailuy
inailuy / Creating Variables At Run Time
Created August 22, 2013 23:35
Attaching a Variables to a object at run time
id obj;
// Creating a variable at run time
objc_setAssociatedObject(obj,@"variable", variable, OBJC_ASSOCIATION_RETAIN);
// Accessing the variable later
objc_getAssociatedObject(obj,@"variable");
@inailuy
inailuy / gist:6016565
Created July 17, 2013 00:28
example of macro
#define LocalizedString(s) NSLocalizedStringFromTableInBundle((s),@"Localizable", [AppDelegate GetLocalizebundle], nil)
@inailuy
inailuy / Switching to new remote branch
Created May 1, 2013 11:07
Switching to new remote branch GIT
git checkout --track origin/new_branch
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:@"font name" size:20] forKey:UITextAttributeFont];
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];
@inailuy
inailuy / Seconds to Minutes
Created March 21, 2013 19:34
Convert Seconds to Minutes as a NSString
- (NSString *)timeFormatted:(int)totalSeconds
{
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
return [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];
}
self.navigationController.navigationBar.topItem.title = @"Back";
@inailuy
inailuy / Creating View Controller from Storyboard
Created March 19, 2013 18:42
Creating View Controller from Storyboard
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard" bundle:nil];
CustomVC *vc = [storyboard instantiateViewControllerWithIdentifier:STORYBOARDID_VC_ID];
[self.navigationController pushViewController:vc animated:YES];
@inailuy
inailuy / GIT
Last active December 15, 2015 03:39
Conflicts with Remote, dont care about local changes, discard changes -> pull remote
git stash save --keep-index
git stash drop
git push origin newBranch // pushing local branch to remote
@inailuy
inailuy / LongPress on UITableViewCell
Last active December 15, 2015 02:08
check which tableview cell was long pressed
CGPoint p = [gestureRecognizer locationInView:self.tableView];
NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:p];
if (gestureRecognizer.state == UIGestureRecognizerStateBegan)
{
if (indexPath == nil)
{
NSLog(@"long press on table view but not on a row");
}
else
@inailuy
inailuy / Resign keyboard SVProgressHUD
Created March 17, 2013 18:29
properly show SVProgressHUD when resigning keyboard
// resign keyboard
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.3 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
[SVProgressHUD showWithStatus:@"Searching..." maskType:SVProgressHUDMaskTypeBlack];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//do search
dispatch_async(dispatch_get_main_queue(), ^{
//search finished - do smth with search results and hide hud
[SVProgressHUD dismiss];