Skip to main content

Posts

Showing posts with the label iPhone File Reading

Core Data Tutorial: How To Use NSFetchedResultsController

So far, we're at exactly the same point we were using the SQLite3 method. However, we didn't have to write nearly as much code (notice the absence of a FailedBankDatabase class constructing raw SQL statements), and adding other functionality such as insert/delete operations would be much simpler. However, there's one notable thing that we could add pretty easily with Core Data that could give us huge benefits to performance: use NSFetchedResultsController. Right now we're loading all of the FailedBankInfo objects from the database into memory at once. That might be fine for this app, but the more data we have the slower this will be, and could have a detrimental impact to the user. Ideally we'd like to load only a subset of the rows, based on what the user is currently looking at in the table view. Luckily, Apple has made this easy for us by providing a great utility class called NSFetchedResultsController. So, start by opening up FailedBanksListViewController.h, remov…

iPhone Tutorials

iPhone TutorialsThis site contains a ton of fun tutorials – so many that they were becoming hard to find! So I put together this little page to help everyone quickly find the tutorial they’re looking for. Hope you enjoy! :]



Beginning iPhone Programming
iPhone programming is like a ladybug - fun and only a little scary! If you’re completely new to iPhone programming, start here! First there’s a tutorial series that will walk you through the process of creating an iPhone app from start to finish – using the most common APIs that almost every app uses. Next there’s a tutorial about memory management – the area where beginners most often get confused about!

How To Create a Simple iPhone App Tutorial: 1/3How To Create a Simple iPhone App Tutorial: 2/3How To Create a Simple iPhone App Tutorial: 3/3Memory Management in Objective-C TutorialHow To Debug Memory Leaks with XCode and Instruments TutorialUsing Properties in Objective-C Tutorial


Game Programming with Cocos2D, Box2D, and Chip…

How To Read a File From Your Application Bundle

First you need to add your file to the Resources folder of your Xcode project. Then you can access the file like this (assuming the file is called MyFile.txt):NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"txt"]; NSData *myData = [NSData dataWithContentsOfFile:filePath]; if (myData) { // do something useful} NSString *filePath = [[NSBundle mainBundle] pathForResource:@"MyFile" ofType:@"txt"]; NSData *myData = [NSData dataWithContentsOfFile:filePath]; if (myData) { // do something useful } Here’s a complete example reading a help text file into a UIWebView.NSString *filePath = [[NSBundle mainBundle] pathForResource:@"HelpDoc" ofType:@"htm"]; NSData *htmlData = [NSData dataWithContentsOfFile:filePath]; if (htmlData) { [webView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@"http://iphoneincubator.com"]]; …