Monday, July 27, 2015

Save and Load Image From NSDocumentDirectory


Save Image  

UIImage *image = [[UIImage alloc] initWithData:[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:@"your Image URL"]];
[Self saveImage:image withImageName:@"ImageName"];


-(void)saveImage:(UIImage*)image withImageName:(NSString*)imageName 


 NSData *imageData = UIImageJPEGRepresentation(image,1.0); //convert image into .jpeg format.
NSFileManager *fileManager = [NSFileManager defaultManager];//create instance of NSFileManager
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //create an array and store result of our search for the documents directory in it


NSString *documentsDirectory = [paths objectAtIndex:0]; //create NSString object, that holds our exact path to the documents directory


NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpeg", imageName]]; //add our image to the path


[fileManager createFileAtPath:fullPath contents:imageData attributes:nil]; //finally save the path (image)
}


Load Image

[self.imageView setImage:[Self  loadImage:@"ImageName"]];

-(UIImage*)loadImage:(NSString*)imageName
{
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    
    NSString *documentsDirectory = [paths objectAtIndex:0];
    
    NSString *fullPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.jpeg", imageName]];
    
    return [UIImage imageWithContentsOfFile:fullPath];
    
}


Sunday, July 26, 2015

Scrum Methodology

The Scrum approach to agile software development marks a dramatic departure from waterfall management. Scrum and other agile methods were inspired by its shortcomings. Scrum emphasizes collaboration, functioning software, team self management, and the flexibility to adapt to emerging business realities.

How to Rename Xcode Project

Don't change the project name. You should be able to without crashing, but the fact that you cannot do so does not matter. You don't need to change it, so don't. Leave the project name alone; it has nothing to do with anything the user ever sees. You want to change the name of the app, which is a completely different thing.
  • The name of the app, as shown below the icon on the device, is the CFBundleDisplayNamesetting (Bundle Display Name) in the Info.plist. That's all you need to change (you might need to create it).
  • The name of the app that users will see in the App Store is different yet again; that is something you will set manually in your browser at iTunes Connect when you submit the app.
But if still you want to change the name of the Project in Xcode follow:


I've used shell commands to rename projects a few times, and it worked better than renaming from Xcode itself. Here are the steps (given we want to rename warnings_test => BestAppEver) (you may need to install a few extra tools with brew install rename ack):
  1. Find all files with name containing the source string:
    $ find . -name 'warnings_test*'
    ./warnings_test
    ./warnings_test.xcodeproj
    ./warnings_test.xcodeproj/xcshareddata/xcschemes/warnings_test.xcscheme
    ./warnings_testTests
    ./warnings_testTests/warnings_testTests.m
  2. Rename those files and directories:
    $ find . -name 'warnings_test*' -print0 | xargs -0 rename -S 'warnings_test' 'BestAppEver'
    You'll need to run this command a couple of times, because directories will be renamed first, then files and directories inside those will be renamed on the next iteration. Check with the step 1 if all the files are renamed (should see empty output).
  3. Find all occurrences of the string in all the files:
    $ ack --literal 'warnings_test'
    Look through the output to make sure all those string should be replaced. In most cases, they should.
  4. Replace all occurrences:
    $ ack --literal --files-with-matches 'warnings_test' --print0 | xargs -0 sed -i '' 's/warnings_test/BestAppEver/g'
    One run is enough. To verify, run the command in step 3 again, you should see empty output.
Done! All your targets, schemes, files, mentions in comments, identifiers, names, etc. have been renamed. If you git add . and git status, you should see a lot of renamed: entries (just another sanity check).