Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

various fixes #1

Merged
merged 2 commits into from

2 participants

@ttilley

Hello! I made a few small, quick, tweaks when including these files in a project. Primarily this includes support for use with both GC and ARC. In one spot I was lazy and fixed a potential leak with GC by using CFBridgingRelease, and just removed the release instead of wrapping it in an ifdef for ARC since CFBridgingRelease makes the object it returns autorelease.

  • fix header when used without pre-compiled header
  • fix implicitly atomic 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
  • small formatting nazi changes
ttilley added some commits
@ttilley ttilley 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
bd5c081
@ttilley ttilley formatting 81dc9d1
@alexzielenski alexzielenski merged commit 764da7c into alexzielenski:master
@alexzielenski

Thanks! These are much needed changes for arc users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 2, 2012
  1. @ttilley

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

    ttilley authored
    …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
  2. @ttilley

    formatting

    ttilley authored
This page is out of date. Refresh to see the latest.
Showing with 26 additions and 12 deletions.
  1. +9 −4 StartAtLoginController.h
  2. +17 −8 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
25 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
+
+@end
Something went wrong with that request. Please try again.