Posts Tagged: objective-c


12
Feb 12

XCode iOS simulator is case insnsitive. iOS on Device is not.

We have an iPad app. We load images using file paths into the app. Images appear just fine in the iOS simulator. Images do not show up on the device. Fist shaken madly in the air, agony.

Thanks to my colleague Dolphy Fernandes we managed to discover the culprit. The iOS Simulator used by XCode loads file in a case insensitive manner. To it, a file called A55.jpg and a55.jpg are the same. iOS on devices, on the other hand, is case sensitive. Hence, A55.jpg will not load if the file name you are attempting to load is 'a55.jpg'.

Hope it helps…

Share

8
Feb 11

SBJSON: Testing for nil / NULL value

I am playing with a variety of JSON frameworks in Objective-C. All are severely under-documented but then, they are simple to use, right? No. Nonetheless, I am deeply in awe and in debt to the great individuals who invested endless hours of their time to build these libraries and give them to us to use free of charge. Thanks you.

Anyway, SBJSON from Stig Brautaset, which I am examining right now, exposed a relatively weird issue. How do you test for null values in the contents of the parsed NSDictionary at hand? 

Plain old ([dictionary valueForKey:@"key"] == null) will not work. The breakthrough came when looking at the dictionary printout to gdb (Right-click the object in memory and select 'Print Description to Console'). The null value was 'stored' in a CFNull reference. To test whether a pointer is pointing at CFNull, you do this:

myVariable == kCFNull where kCFNull is a special memory address dedicated to hold this special null (nil!) value. 

Share

4
Feb 11

UITableView cell recycling: knowing what’s visible

On my iOS app project, I need to know what is visible in a UITableView and what's not. Each cell displays a unique countdown timer which updates the label in the cell. UITableView recommends you let it recycle the cells used to display the table. What I could not figure out is what cell is being recycled out of the table. Still, the documentation for the recycling method dequeueReusableCellWithIdentifier is confusing (to me). 

The method's signature

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

actually returns you the cell that is being replaced.

Better yet, you can use the cell's properties to find out which cell it was. Not a major revelation but maybe it will help someone out there. You can play with my test project and see for yourself.

Share