Last active
August 29, 2015 14:01
-
-
Save madrobby/9f134c440bd6524e7e7a to your computer and use it in GitHub Desktop.
RubyMotion vs. Objective-C showdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(BOOL)appIsPresentInLoginItems | |
{ | |
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]; | |
break; | |
} | |
} | |
CFRelease((CFDictionaryRef)jobDicts); jobDicts = nil; | |
return bOnDemand; | |
} | |
return NO; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HELPER_BUNDLE_ID = 'blah' | |
def launchesAtLogin? | |
SMCopyAllJobDictionaries(KSMDomainUserLaunchd).any? do |job| | |
job['Label'] == HELPER_BUNDLE_ID && job['OnDemand'] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Objective-C can be shorter...
Line 4 could be:
(this removes the need for line 5)
Line 7 can be:
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...