Skip to content

Instantly share code, notes, and snippets.

MacOS

Build 3059

MD5: 59bab8f71f8c096cd3f72cd73851515d

Rename it to: Sublime Text

Make it executable with: chmod u+x Sublime\ Text

@derektu
derektu / ResourcePathLocator.mm
Created March 14, 2013 01:33
Sample code for determine the path of a resource file. Initially the resource file is shipped with the application bundle, but if user modifies it, it is saved to document folder
// TODO: pathForResource:@"Party.xml" ofType:nil should work.
// If so, then we can extract Party.xml as parameter. Better, we can add a path parameters, so that the file is stored
// to <DocumentPath>/data/<someFile>
//
+ (NSString *)dataFilePath:(BOOL)forSave {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentsPath = [documentsDirectory
@derektu
derektu / UpdateTableViewRows.m
Created February 15, 2013 08:43
Code snippet to manage TableView rows
//--------------------------------------------------------------
// To add a row
//--------------------------------------------------------------
// TODO: append one row to self.dataArray
//
NSIndexPath* indexPath = [NSIndexPath indexPathForRow:self.dataArray.numberOfItems - 1 inSection:0];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
@derektu
derektu / DocumentPathBuilder.h
Created February 12, 2013 03:23
Provide Documents path related API
#import <Foundation/Foundation.h>
// Provides Path undrer "Documents"
//
@interface DocumentPathBuilder : NSObject
@property (nonatomic, copy, readonly) NSString* documentFolder;
// Given a 'relative' filePath, return its absolute path under documents folder
//
@derektu
derektu / ArchiveHelper.h
Last active June 9, 2017 16:27
Helper functions for doing object serialization (to plist file)
// ArchiveHelper.h
//
@interface ArchiveHelper : NSObject
+ (id)loadObjectFromFile:(NSString*)filePath withKey:(NSString*)key;
+ (void)saveObject:(id)object toFile:(NSString*)filePath withKey:(NSString*)key;
@end
@derektu
derektu / UIImage+UIImageExtension.h
Last active December 12, 2015 09:49
UIImage extension
// UIImage+UIImageExtension.h
//
#import <Foundation/Foundation.h>
@interface UIImage (UIImageExtension)
// Resample to create another image: aspect ratio is not preserved (not yet)
//
- (UIImage *)resample:(CGSize)newSize;
@derektu
derektu / NSString+StringExtension.h
Last active December 12, 2015 09:09
NSString extension
// NSString+StringExtension.h
//
#import <Foundation/Foundation.h>
@interface NSString (StringExtension)
// Trim off leading and trailing whitespaces
//
-(NSString*) trim;
@derektu
derektu / LocateControl.mm
Last active December 10, 2015 02:38
Identify controls without using IB to hook up IBOutlet
// When there are many controls, you can identify each control by giving them an unique tag property
// and use the following code to locate the control
//
// Return the button with the specified ID (as tag)
//
- (UIButton*) getButton:(int)idButton
{
return [self.view viewWithTag:idButton];
}
@derektu
derektu / CreateImageButton.mm
Created December 24, 2012 10:27
Manually create and hookup ImageButton
UIButton* btn = ..;
UIImage* imageForButtonFace = ..;
UIImage* imageForHighlight = ..;
[btn setBackgroundImage:[factory getButtonFaceImageFor:imageForButtonFace] forState:UIControlStateNormal];
[btn setBackgroundImage:[factory getButtonHighlightImageFor:imageForHighlight] forState:UIControlStateHighlighted];
[btn addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
- (void)btnClicked:(UIButton*)sender