Permalink
Browse files

fix header when used without pre-compiled header, fix implicitly atom…

…ic properties to be explicitly atomic for objects and explicitly nonatomic for BOOL, fix potential memory leak when using garbage collection, fix usage with ARC, fix lack of newline at end of file, and small formatting nazi changes
  • Loading branch information...
1 parent b0074d8 commit bd5c0813da42c1a7f4bb20aef14cf34994cf63bd @ttilley ttilley committed Feb 2, 2012
Showing with 25 additions and 11 deletions.
  1. +9 −4 StartAtLoginController.h
  2. +16 −7 StartAtLoginController.m
View
13 StartAtLoginController.h
@@ -20,13 +20,18 @@
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#import <Foundation/Foundation.h>
+
@interface StartAtLoginController : NSObject {
NSString *_identifier;
NSURL *_url;
}
-@property (assign) BOOL startAtLogin;
-@property (copy) NSString *identifier;
-@property (copy) NSURL *url;
+
+@property (assign, nonatomic) BOOL startAtLogin;
+@property (copy, atomic) NSString *identifier;
+@property (copy, atomic) NSURL *url;
+
- (void)setBundle:(NSBundle*)bndl;
- (void)remove;
-@end
+
+@end
View
23 StartAtLoginController.m
@@ -24,50 +24,59 @@
#import <ServiceManagement/ServiceManagement.h>
@implementation StartAtLoginController
+
@synthesize identifier = _identifier;
@synthesize url = _url;
@dynamic startAtLogin;
+
+#if !__has_feature(objc_arc)
- (void)dealloc {
self.identifier = nil;
self.url = nil;
[super dealloc];
}
+#endif
+
- (void)setBundle:(NSBundle*)bndl {
self.identifier = [bndl bundleIdentifier];
self.url = [bndl bundleURL];
}
+
- (BOOL)startAtLogin {
if (!_identifier)
return NO;
-
- NSDictionary *dict = (NSDictionary*)SMJobCopyDictionary(kSMDomainUserLaunchd, (CFStringRef)_identifier);
+
+ CFDictionaryRef cfdict = SMJobCopyDictionary(kSMDomainUserLaunchd, (__bridge CFStringRef)_identifier);
+ NSDictionary *dict = (NSDictionary*)CFBridgingRelease(cfdict);
BOOL contains = (dict!=NULL);
- [dict release];
return contains;
}
+
- (void)setStartAtLogin:(BOOL)flag {
if (!_identifier||!_url)
return;
[self willChangeValueForKey:@"startAtLogin"];
// Let ServiceManagement know that we exist
- if (LSRegisterURL((CFURLRef)_url, true) != noErr) {
+ if (LSRegisterURL((__bridge CFURLRef)_url, true) != noErr) {
NSLog(@"LSRegisterURL failed!");
}
// Make the setting
- if (!SMLoginItemSetEnabled((CFStringRef)_identifier, (flag) ? true : false)) {
+ if (!SMLoginItemSetEnabled((__bridge CFStringRef)_identifier, (flag) ? true : false)) {
NSLog(@"SMLoginItemSetEnabled failed!");
}
[self didChangeValueForKey:@"startAtLogin"];
}
+
- (void)remove {
if (!_identifier)
return;
[self willChangeValueForKey:@"startAtLogin"];
CFErrorRef error = NULL;
- if (!SMJobRemove(kSMDomainUserLaunchd, (CFStringRef)_identifier, NULL, true, &error)) {
- NSLog(@"Could not remove job entry: %@", (NSError*)error);
+ if (!SMJobRemove(kSMDomainUserLaunchd, (__bridge CFStringRef)_identifier, NULL, true, &error)) {
+ NSLog(@"Could not remove job entry: %@", (__bridge NSError*)error);
}
[self didChangeValueForKey:@"startAtLogin"];
}
+
@end

0 comments on commit bd5c081

Please sign in to comment.