iOS Archives

These posts are syndicated from my iOS Dev Diary over at pinkstone.co.uk.

The format is slightly different with more code snippets and less explanations. I had originally designed it as a notebook in iOS Development – now you can follow along if you’re interested.

How to delete a file

Once you have a reference to the file in question you can call the removeItemAtPath method: // get reference with path and filename NSString *filePath = [[NSString alloc]initWithFormat:@”Documents/myFile.txt”]; NSString *deleteThis = [NSHomeDirectory()stringByAppendingPathComponent:filePath]; // now delete the file [[NSFileManager defaultManager]removeItemAtPath:deleteThis error:nil]; This does not work with wildcards in the file name (for example *.jpg).

How to access the iPhone Simulator Directory Structure

You can see the full directory under ~Library/Application Support/iPhone Simulator You’ll be presented with a list of iOS Versions, each of which has several folders to explore. To access data that your apps have written, head over to Applications and see a list of cryptic folders, each one corresponding to one of your apps. In […]

How to test if a file exists

Imagine we had a file that we’ve saved: NSString *myFile = [NSHomeDirectory() stringByAppendingPathComponent:@”Documents/myFile.txt”]; Before accessing it we can determine if it exists or not: BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[NSHomeDirectory()stringByAppendingPathComponent:myFile]];

How to create an NSTimer

Timers are good if you want to delay executing a method, or if you need to call a method repeatedly. To set a one-off timer without setting a property you can use this: // calls the updateLabel method in 5 seconds [NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(updateLabel) userInfo:nil repeats:NO]; However, you won’t be able to stop it […]