Automatic Reference Counting
Posted on
Automatic Reference Counting (or ARC) is a new advancement in Objective-C with the LLVM compiler. There is a lot of debate in the community about its place. I've worked with people who completely despise it and people that think it's the best thing since sliced bread (which by the way, is pretty great). I have some thoughts on ARC too.
I tried it on a Mac app and an iOS app. At first it was really hard to let go of retain
, release
, and controlling the details of an objects lifetime. After awhile, it was really nice to not write dealloc
and just release every ivar.
When I switched back to work on a non-ARC app, I realized how annoying it is to write memory management code. Now, we're switching all of our apps at work to be ARC. Here's are my two biggest reasons:
On Managing Money
Posted on
I generally suck at managing money. My usual attitude to paying for anything is "I need this, so here is the money." When people ask me how much things cost, I never know. This is stupid.
I've kinda of brainwashed myself into thinking I don't have a choice except to pay for this. Doing pretty well as a software engineer in San Francisco makes this a possibility. I realize how stupid this is.
Anyway, I'm starting to hopefully break the habit.
UITableViewCell Silly Magic
Posted on
Ever had a UITableViewCell
's imageView
not update when you set it's image
in a callback or block? It's amazingly frustrating. I usually end up going over and over the code to make sure it sets it on the main thread, the image isn't nil
, the image view is on the screen, etc, etc.
UITableViewCell
s don't update when you set the imageView
's image
. UITableViewCell
's imageView
is magical and stupid. If you don't have an image in the imageView
, it will nil it out and remove it from the contentView
. When you set the image, it will cache it and do some silliness so your updates don't work.
Make your own image view. Easy as that. Don't use the imageView
property unless you want it to work exactly the way Apple uses it in Music.app for albums. For anything else, just make your own and add it to the contentView
.
Always Initialize to Nil
Posted on
Here's an excerpt from a great blog post on why you should always initialize your variables to nil
.
“Always initialize your object variables to nil, no matter what, because some day they may be captured by a block and if they contain junk when the block is copied you’re going to crash.”
It's just good practice, but this really sums it up. Thanks for the write up Ryan Perry!
Open Source is Rewarding
Posted on
I released SSToolkit awhile ago. It's an open source library for doing common things in iOS. It's the overflow of stuff that I use on a daily basis. It's pretty much everything I've ever written that is iOS related that is reusable, open sourced, and released for free.
I recently received this email from a developer using my framework.
Dear Sam
Thank you for SSToolkit. I'm using it to display images from a folder.
your code is easy to use and the instructions to import it into an Xcode project, on your website, are clear and simple.
Regards Ehab