View Full Version : Detecting second and third launch using "prevStartupVersions"

May 5, 2012, 11:53 AM
I'm detecting the number of times my Mac application has being opened using the following code:

NSString *currentVersion = (NSString*)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"];
NSArray *prevStartupVersions = [[NSUserDefaults standardUserDefaults] arrayForKey:@"prevStartupVersions"];
if (prevStartupVersions == nil)
else {
[[NSUserDefaults standardUserDefaults] synchronize];
However, this only works for detecting the first launch. How would I detect a second and third launch? I did try:

if (prevStartupVersions == 1)
However, I am comparing an NSArray with an Interger there. How should adapt this to detect a second launch?

Thanks in advance for any help,


May 5, 2012, 01:34 PM
How about

if ([prevStartupVersions length] == 1)

May 5, 2012, 01:41 PM
No luck I'm afraid :
'NSArray' may not responnd to 'length'

May 5, 2012, 04:12 PM
No luck I'm afraid :
'NSArray' may not responnd to 'length'

Read the reference doc for NSArray. Look up the count method.