wannabegeek

Icon

Things I find interesting – generally programming

User Defined Runtime Attributes


“User Defined Runtime Attributes” are variables which can be set using key-value paths via Interface Builder. These properties work for Mac OS X 10.6 and in iOS 5.0 and later.
I have often overlooked this functionality, but actually they can be extremely useful, and prevent subclassing or writing extra code to alter properties of a class.

You will find the “User Defined Runtime Attributes” in the “Identity Inspector”‘panel in interface builder. Here you can set various attributes using key-value paths of the class your re-implementing.
Read the rest of this entry »

Expandable UITableView

Here I am going to implement a UITableView with sections that you can expand and contract by tapping on a header cell.
I have tried to make my code generic using the same delegate and data source model as UITableView, this should make it relatively easy to slot into place of a standard UITableView/UITableViewController.

Read the rest of this entry »

Controlling Debug Logging Levels and Logging to File in Cocoa

The Cocoa Framework includes the logging function NSLog (which in turn just calls NSLogv). On OS X this just outputs the log message to the console (if there is one), on iOS it writes the message to the central logging console. In both OS X and iOS, it you are running you applications thought the Xcode debugger, the log output is written a to the console output view.

In this post I’m going to demonstrate how I use simple pre-processor macros to control different logging levels and how they are included in debug and release builds, and also how you can log all this output to a separate file.

Read the rest of this entry »

Star Ratings Control for iOS

There are loads if controls available in the Internet for creating rating stars (just take a look at Cocoa Controls. However, I couldn’t quite find one that fitted my needs – so, here is my version.

Read the rest of this entry »

Comparing NSURL file URL objects

Comparing NSURL objects for equality would on the surface seem like quite a simple task. According to Apple’s documentation for the isEqual method

This method defines what it means for instances to be equal. Two NSURLs are considered equal if and only if they return identical values for both baseURL and relativeString.

However, you may have two URLs which point to the same physical file but the URL is different for example a file that is referenced through a symlink. An example on iOS would be:

file:///var/mobile/Applications/06A3AEBA-8C34-476E-937F-A27BDD2E450A/Documents

and

file://localhost/var/mobile/Applications/06A3AEBA-8C34-476E-937F-A27BDD2E450A/Documents

are exactly the same directory, but calling isEqual: to compare them will return false.

Read the rest of this entry »

UIDocument & UIManagedDocument closeWithCompletionHandler failues

I have been having problem when closing a UIManagedDocument. If you go though the process of opening a document, closing it and then reopening it you get the following exception in the console logs.


2012-03-07 08:33:53.186 DocumentTest[3207:707] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'closeWithCompletionHandler called while document is already closing'
*** First throw call stack:
(0x30ec388f 0x32aa93e9 0x30ec3789 0x30ec37ab 0x34d253e5 0xbfcd 0x416d 0x349e206d 0x34a3bd87 0x349e4db1 0x349e49db 0x34a2edc3 0x34a2ebf1 0x505463 0x34a2f151 0x34a2ef67 0x34a7e71f 0x4e7af9 0x34a7e5ad 0x34a7e20b 0x349b9e13 0x349b9801 0x3499fb7d 0x3499f423 0x36f9f22b 0x30e97523 0x30e974c5 0x30e96313 0x30e194a5 0x30e1936d 0x36f9e439 0x349ce1bd 0x242b 0x23d0)
terminate called throwing an exception[Switching to process 7171 thread 0x1c03]
[unknown](gdb)

Read the rest of this entry »

Unit Testing blocks with completion handlers

With all the recent advancements in the Apple APIs, Apple have tented toward using blocks, especially with the iCloud and UIDocument implementation. I have also started using blocks a fair amount in my code, I find this make the code much cleaner and easier to read/maintain.
The issues I have come across is testing these units of code, most uses of blocks farm off the complex time consuming functionality to an auxiliary thread and call you back when the task is complete.

Read the rest of this entry »

UIManagedDocument Save Errors

I have been messing around with iCloud and UIManagedDocument for some time now. It is a fairly nice API although get very complex quite quickly. I think Apple really need to provide an abstraction layer over the top of all this, I have attempted to do this in my simple iCloud testing in my github repository.

One error which I came across and had me confused for quite some time was….


2012-02-06 22:25:42.152 RouteMonitor[3662:450f] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'The specified persistent store was not found.'

*** First throw call stack:
(0x30b5588f 0x3273b3e9 0x3072986b 0x349ec227 0x349b3959 0x37d61f4b 0x37d6319b 0x37d634f5 0x37d61eaf 0x349b3607 0x34c8bd39 0x34c96cf3 0x34c96b8d 0x34c977a7 0x3184edfb 0x3184ecd0)

terminate called throwing an exception(lldb)


Read the rest of this entry »

Using UIPageControl as a container UIViewController

Using a UIPageControl to navigate though a series of UIView (or UIViewControllers) I would imagine is a fairly common task. However, there is now Apple provided way of doing this with out writing some code.
Read the rest of this entry »

Useful Macros for UnitTests in Xcode

Unit testing is pretty simple within Xcode, especially since Xcode 4 started including ocunit. There are still a few things I come across which have taken some time for me to get around, to be able to test certain classes.
Most of the below has been found else where on the internet, I can’t remember where, since I have been using it foe some time. But I just bought it may be useful to consolidate this information into one place.
Read the rest of this entry »