Tuesday, May 29, 2012

How to Create ,Rename and Delete a file from Documents Directory

Documents Directory

// For error information
NSError *error;
 
// Create file manager
NSFileManager *fileMgr = [NSFileManager defaultManager];
 
// Document directory
NSString *documentsDirectory = [NSHomeDirectory() 
         stringByAppendingPathComponent:@"Documents"];
 
 
 
Creating a File
// File we want to create in the documents directory 
// Result is: /Documents/file1.txt
NSString *filePath = [documentsDirectory 
         stringByAppendingPathComponent:@"file1.txt"];
 
// String to write
NSString *str = @"Maheswaran.cm";
 
// Write the file
[str writeToFile:filePath atomically:YES 
         encoding:NSUTF8StringEncoding error:&error];
 
// Show contents of Documents directory
NSLog(@"Documents directory: %@",[fileMgr contentsOfDirectoryAtPath:
                           documentsDirectory error:&error]);
 
Renaming a File
 
// Rename the file, by moving the file
NSString *filePath2 = [documentsDirectory 
             stringByAppendingPathComponent:@"file2.txt"];
 
// Attempt the move
if ([fileMgr moveItemAtPath:filePath toPath:filePath2 
                                              error:&error] != YES)
  NSLog(@"Unable to move file: %@", [error localizedDescription]);
 
// Show contents of Documents directory
NSLog(@"Documents directory: %@",[fileMgr contentsOfDirectoryAtPath:
                        documentsDirectory error:&error]);
 
Deleting a File
 
// Attempt to delete the file at filePath2
if ([fileMgr removeItemAtPath:filePath2 error:&error] != YES)
  NSLog(@"Unable to delete file: %@", [error localizedDescription]);
 
// Show contents of Documents directory
NSLog(@"Documents directory: %@",[fileMgr contentsOfDirectoryAtPath:
                                   documentsDirectory error:&error]); 

Wednesday, May 16, 2012

How to get Suck Effect in iOS

[UIView beginAnimations:@"suck" context:NULL];
[UIView setAnimationTransition:103 
                 forView:myViewContainer cache:YES];
[UIView setAnimationPosition:CGPointMake(12, 345)];
[myView removeFromSuperview];
[UIView commitAnimations]; 
 

 /*setAnimationTransition:103, it invokes suck effect.*/

For reference:
http://www.iphonedevwiki.net/index.php?title=UIViewAnimationState

Swift Operators - Basic Part 3 (Range operators in swift)

Range Operators: Closed Range operators  Half-Open Range Operators One-Sided Ranges Closed Range Operators:  a...b It defines...