Skip to main content

Posts

Showing posts from December, 2011

NSURL of DocumentDirectory

- (NSURL *)applicationDocumentsDirectory {    NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentPath = [searchPaths objectAtIndex:0];  // NSArray *searchPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  // NSString *documentPath = [searchPaths lastObject];    return [NSURL fileURLWithPath:documentPath]; }

Remove All Images from Document Directory

-( void )removeImagesFromDocumentDic{     /* dir: the directory where your files are */     NSFileManager *fm = [ NSFileManager defaultManager ];     NSError *error = nil ;     NSString *docDirPath  =   [ NSSearchPathForDirectoriesInDomains ( NSDocumentDirectory , NSUserDomainMask , YES ) objectAtIndex : 0 ];     NSArray *items = [fm contentsOfDirectoryAtPath :docDirPath error :&error];     if (error) { /* ... */ }          /* delete png files */     for ( NSString *item in items) {         if ([[item pathExtension ] isEqualToString : @"png" ]) {             NSString *path = [docDirPath stringByAppendingPathComponent :item];             [fm removeItemAtPath :path error :&error];             if (error)             { /* ... */ }         }     } }

How to sort NSMutableArray using sortedArrayUsingDescriptors?

http://stackoverflow.com/questions/1844031/how-to-sort-nsmutablearray-using-sortedarrayusingdescriptors Example using NSString and NSNumber values with sorting on NSNumber value: NSString * NAME       = @ "name" ; NSString * ADDRESS   = @ "address" ; NSString * FREQUENCY = @ "frequency" ; NSString * TYPE       = @ "type" ; NSMutableArray * array = [ NSMutableArray array ]; NSDictionary * dict ; dict = [ NSDictionary dictionaryWithObjectsAndKeys :             @ "Alehandro" , NAME , @ "Sydney" , ADDRESS ,             [ NSNumber numberWithInt : 100 ], FREQUENCY ,             @ "T" , TYPE , nil ]; [ array addObject : dict ]; dict = [ NSDictionary dictionaryWithObjectsAndKeys :             @ "Xentro" , NAME , @ "Melbourne" , ADDRESS ,             [ NSNumber numberWithInt : 50 ], FREQUENCY ,             @ "X" , TYPE , nil ]; [ array