initWithContentsOfFile: IOS evolution and deprecated APIs

My primary word practice title (or set of titles) continues to sell in the iTunes store.  After experimenting with “free” — how many downloads would there be? — and trying different price levels, I have found revenue optimized at $0.99 for iPhone apps and $1.99 for iPad apps of this type.  With ample screen shots and simple functionality, I think most buyers know pretty much exactly what they are getting with this “word learning” app, and I am pretty clear now about what the market will pay for it.

As the apps have been selling for a for quite some time, I have been a bit annoyed at the remaining compiler warnings from my one remaining use of a “deprecated” api — the one in this blog post title.  Apple phased that out after IOS 2.0 (and apparently in OS-X 10.4 or so).  Not seeing an easy automatic “fix-it” in X-code as was provided for other API changes (newly required “id” parameters which Xcode will correct for you with a click), and not seeing the obvious new replacement, I have ignored this for now.

Finding recently that some of my keyword entries on iTunes for some of the non-English versions of the apps contained errors (somehow I updated the German keywords with the German version of the “what is new” text, and didn’t recognize it quickly, as I know only a few sentences in German…), I then learned I needed to create a new version since there are only a couple of bits of meta-data that are not editable for an existing item in the store, but the most important of those are the “keywords”.  So with Germans not finding my app by searching on “learning Chinese” (in German), I have to create and submit a new version of the all (with no changes at all) to update the keywords.  And since i need to recompile anyway, I am going to rid myself of those warnings. And this is now old stuff (ios5 is going to ios 6, and this was an ios3 change).

here is the solution:

Old code:

// fix for deprecated method. 120620 v 3.18

// NSString *scoreString = [[NSString alloc] initWithContentsOfFile:filename];  // old code – gets warning

NSError *error = nil; // new line inserted for use in next line

NSString *scoreString = [[NSString alloc] initWithContentsOfFile:filename encoding:NSUnicodeStringEncoding error:&error];

and so on…

(note: NSUnicodeStringEncoding and NSUTF8StringEncoding could work; i was writing my initial file out with

[str writeToFile:highScoreFilename atomically:YES encoding:NSUnicodeStringEncoding error:nil];  //

so the first choice is what  I needed to use on reading.

What I learned at Apple’s “deprecated string methods” page is that many methods that read in files were simply updated to include (require) new parameters to provide more elegant and robust error handling in the event the file found was not the one expected (or more specifically of the type expected).

Yea, clean compiles again!



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s