You should absolutely be using ARC in your iOS projects, and if the project predates ARC, go ahead and use the refactoring tool to get it to ARC. It really doesn’t take long and you’ll end up with a more stable app that will be easier to maintain.
That being said, you can’t completely ignore memory management. You can still get EXC_BAD_ACCESS, Zombies, leaks, etc., even with ARC projects. Here are some things you should know
- ARC is not garbage collection. It statically analyzes your code and then puts in release and retain calls where they are needed. It’s still susceptible to a retain-cycle — two objects with references to each other. You can still have references to dead objects.
- If you have a retain-cycle, a common way to deal with that is to make one of the properties weak (which you should probably do), but now that reference is susceptible to becoming a Zombie. A weak property will not call retain on the object, so when the object is deallocated, it would then refer to a dead object. If you have weak properties and get EXC_BAD_ACCESS, go reproduce it under the Zombie instrument.
- Under ARC, you cannot use autorelease any more, but the calls into non-ARC libraries can (and do, especially iOS frameworks). This means that you sometimes need to use your own autorelease pool. Under ARC, use the @autoreleasepool keyword to wrap areas where autoreleased objects are created that you need released before you return back to the thread’s main pool. If you see leaks of objects in Instruments that you don’t alloc or hold onto, and use threads, add in @autoreleasepool blocks.
- Don’t use non-ARC code in your project by copying the source in. Build them in their own Xcode projects and then use the resulting .framework or .a in your project. It’s likely you wouldn’t be able to anyway, but just in case. (if you happen to be MRC — then really don’t copy ARC source into your projects — this will usually be compilable code, but will leak like crazy)
- Test your code under the Zombie and Leaks instruments — especially if you use bridging, weak references, or are in any way managing retain-cycles (breaking them yourself without weak).
- It’s rare, but I ran into a bug in the iOS framework that didn’t retain Storyboard created Gestures correctly in a tabbed-app. It was my first big ARC project, and it didn’t even occur to me to check for Zombies, but that would have pin-pointed the issue right away. Rule of thumb, the underlying code is still normal retain/release/autorelease based — debug it the same way you would have with Manual Reference Counting.
Get iPhone programming tips in your inbox with my Beginner iPhone Programming Tips newsletter.
If you read XKCD on an iPhone and iPad, there’s no way to see the tooltip text on the comic (usually the funniest part).
Here’s a bookmarklet to pop-up the XKCD tooltip.
Here’s the process for adding it your iPhone
- Go to this blog-entry on your iPhone
- Select and Copy the bookmarklet above
- Go to XKCD, bookmark it, and save the bookmark
- Edit the bookmark, change the Title to “XKCD Tooltip”
- Paste the bookmarklet to the URL of the bookmark
To use it
- Go to XKCD,
- Choose the bookmarklet from your bookmarks — it will popup the tooltip
Starting with Habits 1.1, I started incorporating static analysis into my build. In my previous experience with things like Lint and FXCop — I had found the signal to noise ratio to be too low to be useful. It’s hard to believe, but scan-build is 100% signal — every single issue it flagged was legitimate and needed to be fixed. Now, keeping Habits free from issues is easy, since I only have to deal with one or two at a time.
There were a couple of times I thought it was leading me in the wrong direction, but it was right so often that I just trusted it, and it was right about those too. I had a particularly interesting case with a custom table cell, where I wasn’t releasing properly, and causing a crash when I dealloced the window. Scan-build helped me make sure I found that before release.
I thought Java was bad. Took me a while to figure this out and googling didn’t help, so I am just putting this out there for the next person who needs this.
To get the number of days in a month:
+ (NSInteger) getDaysInMonth:(NSDate*)date
NSCalendar * cal = [NSCalendar currentCalendar];
return [cal rangeOfUnit:NSDayCalendarUnit
There’s a great thread by an iPhone developer on Reddit.
Yay! It took several months but as of today I was able to search for my app and I saw it listed inside the app store. Now you may be saying “so what”, but if you have ever looked into the steps that this takes, you know it’s something to celebrate.My app is a very simple game, but I think I’ve learned enough during this process to distill some important lessons that may help you if this is something you’ve been wanting to do…
I wrote a similar post when I finally finished my iPhone App.
Helen Crozier, the CalmTechCoach, has started a new iPhone Blog to keep all of her iPhone recommendations and reviews in one place. Check it out: My Fabulous iPhone
I saw this list of New Year’s Resolutions on the Did I Get Things Done blog (originally from Amazon)
- Lose Weight
- Get Your Finances in Order
- Go Greener
- Curb Your Vices
- Get in Shape
- Relax More
- Pursue a New Career
- Upgrade Your Technology
- Organize and Optimize
- Start a New Hobby
The main reason that I have had a problem with a resolution is that I don’t really think about them much a week or so after New Year’s. A few years ago, I created a small web app for myself to log how well I was doing at keeping to resolutions I was making. A few months ago, I ported it to the iPhone as Habits.
Instead of making resolutions this year, I created a few habits instead. I want to lose some weight this year (the #1 resolution), so I added a habit to run every 2-3 days, to do bicep/chest and shoulder/tricep weight training once a week. I want to keep my house in better order, so I added a habit to clean up and to process my mail pile more regularly.
A lot of these resolutions should just be a recurring task that you try to do as often as possible.
Macworld reviewed some GTD iPhone applications including Habits:
Habits by Louis Franco helps users form good habits, which sounds simple enough. But developing habits requires a bit of time and discipline. It requires repetition and awareness. Habits keeps your calendar free from clutter associated with routine tasks or the general stuff of life.
Habits is the perfect application to make sure that you stick to your New Year’s resolutions, so from now until the end of January, I am putting Habits on sale for $0.99.
I am working on version 1.1, and I will post it at the end of January and return it to its old price. Until then, here’s hoping that you’re able to turn your resolutions into habits.
(The AppStore takes time to fully update — please make sure it says that the price is $0.99 before you buy)
Buy Habits on the App Store
iPhone AppStore Answers from O’Reilly’s Inside iPhone Blog. There are frustrations with the AppStore, but as O’Reilly acknowledges, Apple appears to be listening:
Changes have been relatively slow to come to the App Store. However, with the addition of review copies, as well as limiting ratings to those who’ve purchased applications, Apple has made changes that have been welcomed by developers. I’m hopeful that the App Store will continue to improve over time and address additional issues.
The other major improvement is dropping the NDA for released SDK’s, thus opening up the possibility of books, online tutorials and blogging about iPhone development.