Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
RubyMotion vs. Objective-C showdown
NSString *bundleID = @"blah";
NSArray * jobDicts = nil;
jobDicts = (NSArray *)SMCopyAllJobDictionaries( kSMDomainUserLaunchd );
if ( (jobDicts != nil) && [jobDicts count] > 0 ) {
BOOL bOnDemand = NO;
for ( NSDictionary * job in jobDicts ) {
if ( [bundleID isEqualToString:[job objectForKey:@"Label"]] ) {
bOnDemand = [[job objectForKey:@"OnDemand"] boolValue];
CFRelease((CFDictionaryRef)jobDicts); jobDicts = nil;
return bOnDemand;
return NO;
def launchesAtLogin?
SMCopyAllJobDictionaries(KSMDomainUserLaunchd).any? do |job|
job['Label'] == HELPER_BUNDLE_ID && job['OnDemand']

This comment has been minimized.

Copy link

joshuatbrown commented May 8, 2014

The Objective-C can be shorter...

Line 4 could be:

NSArray *jobDicts = (NSArray *)SMCopyAllJobDictionaries( kSMDomainUserLaunchd );

(this removes the need for line 5)

Line 7 can be:

if ([jobDicts count] > 0) {

No need for the nil check, since this expression will evaluate to false if jobDicts is nil.

I realize the Ruby is still much shorter, but this helps a bit...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.