Skip to content

Commit

Permalink
Updated for Mac support
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Malakoff committed Aug 2, 2012
1 parent eca4267 commit 1dad15a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 44 deletions.
4 changes: 3 additions & 1 deletion Lib/Helpers/SS+System.h
Expand Up @@ -31,7 +31,9 @@


@interface SS (System) @interface SS (System)


+ (NSS*)iOSVersion; + (NSS*)systemVersion;
+ (B)macSystem;
+ (B)iOSSystem;


+ (SSTaskId*(^)(SSTaskIdBlock block, I waitNS, BOOL background))addTask; + (SSTaskId*(^)(SSTaskIdBlock block, I waitNS, BOOL background))addTask;
+ (void(^)(SSTaskId* taskId))stopTask; + (void(^)(SSTaskId* taskId))stopTask;
Expand Down
30 changes: 28 additions & 2 deletions Lib/Helpers/SS+System.m
Expand Up @@ -31,11 +31,37 @@


#import "SS+System.h" #import "SS+System.h"
#import "NSString+Versioning.h" #import "NSString+Versioning.h"

#include "TargetConditionals.h"
#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#elif defined TARGET_OS_MAC
#import <Cocoa/Cocoa.h>
#endif


@implementation SS (System) @implementation SS (System)


+ (NSS*)iOSVersion { return [[UIDevice currentDevice] systemVersion]; } #if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
+ (NSS*)systemVersion { return [[UIDevice currentDevice] systemVersion]; }
#elif defined TARGET_OS_MAC
+ (NSS*)systemVersion {
SInt32 versionMajor = 0;
SInt32 versionMinor = 0;
SInt32 versionBugFix = 0;
Gestalt( gestaltSystemVersionMajor, &versionMajor );
Gestalt( gestaltSystemVersionMinor, &versionMinor );
Gestalt( gestaltSystemVersionBugFix, &versionBugFix );
return [NSString stringWithFormat:@"%d.%d.%d", versionMajor, versionMinor, versionBugFix];
}
#endif

#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
+ (B)macSystem { return NO; }
+ (B)iOSSystem { return YES; }
#elif defined TARGET_OS_MAC
+ (B)macSystem { return YES; }
+ (B)iOSSystem { return NO; }
#endif


+ (A*)_runningTaskList + (A*)_runningTaskList
{ {
Expand All @@ -62,7 +88,7 @@ + (A*)_runningTaskList
dispatch_queue_t dispatchQueue; dispatch_queue_t dispatchQueue;


if (background) { if (background) {
if (SS.iOSVersion.VersionLessThan(@"5.0")) if (SS.iOSSystem && SS.systemVersion.VersionLessThan(@"5.0"))
dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0UL); dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0UL);
else else
dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0UL); dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0UL);
Expand Down
84 changes: 45 additions & 39 deletions Lib/NSDictionary+NamedProperties.m
Expand Up @@ -9,6 +9,12 @@
#import "NSDictionary+NamedProperties.h" #import "NSDictionary+NamedProperties.h"
#import <objc/runtime.h> #import <objc/runtime.h>


#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
#define BLOCK_TO_IMPL(_b) imp_implementationWithBlock((void*)CFBridgingRetain(_b))
#elif defined TARGET_OS_MAC
#define BLOCK_TO_IMPL(_b) imp_implementationWithBlock(_b)
#endif

static const char* NamedPropertiesKey = "SSNP"; static const char* NamedPropertiesKey = "SSNP";


@implementation NSDictionary (NamedProperties) @implementation NSDictionary (NamedProperties)
Expand All @@ -33,61 +39,61 @@ + (void)setupNamedProperties
{ {
// - (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(NSUInteger)cnt; // - (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(NSUInteger)cnt;
class_addMethod(self.class, @selector(initWithObjects:forKeys:count:), class_addMethod(self.class, @selector(initWithObjects:forKeys:count:),
imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, const id objects[], const id keys[], NSUInteger count) { BLOCK_TO_IMPL(^(NSDictionary* obj, const id objects[], const id keys[], NSUInteger count) {
NSMutableDictionary* properties = obj.getPropertiesContainer; NSMutableDictionary* properties = obj.getPropertiesContainer;
for (NSUInteger index=0; index<count; index++) { for (NSUInteger index=0; index<count; index++) {
[properties setObject:objects[index] forKey:keys[index]]; [properties setObject:objects[index] forKey:keys[index]];
} }
return obj; return obj;
})), }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(initWithObjects:forKeys:count:)))->types method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(initWithObjects:forKeys:count:)))->types
); );


// - (NSUInteger)count; // - (NSUInteger)count;
class_addMethod(self.class, @selector(count), class_addMethod(self.class, @selector(count),
imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) { BLOCK_TO_IMPL(^(NSDictionary* obj) {
return obj.getPropertiesContainer.count; return obj.getPropertiesContainer.count;
})), }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(count)))->types method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(count)))->types
); );


// - (id)objectForKey:(id)aKey; // - (id)objectForKey:(id)aKey;
class_addMethod(self.class, @selector(objectForKey:), class_addMethod(self.class, @selector(objectForKey:),
imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, id key) { BLOCK_TO_IMPL(^(NSDictionary* obj, id key) {
return [obj.getPropertiesContainer objectForKey:key]; return [obj.getPropertiesContainer objectForKey:key];
})), }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(objectForKey:)))->types method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(objectForKey:)))->types
); );


// - (NSEnumerator *)keyEnumerator; // - (NSEnumerator *)keyEnumerator;
class_addMethod(self.class, @selector(keyEnumerator), class_addMethod(self.class, @selector(keyEnumerator),
imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) { BLOCK_TO_IMPL(^(NSDictionary* obj) {
return [obj.getPropertiesContainer keyEnumerator]; return [obj.getPropertiesContainer keyEnumerator];
})), }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(keyEnumerator)))->types method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(keyEnumerator)))->types
); );


// - (NSArray *)allKeys; // - (NSArray *)allKeys;
class_addMethod(self.class, @selector(allKeys), class_addMethod(self.class, @selector(allKeys),
imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) { BLOCK_TO_IMPL(^(NSDictionary* obj) {
return obj.getPropertiesContainer.allKeys; return obj.getPropertiesContainer.allKeys;
})), }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(allKeys)))->types method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(allKeys)))->types
); );


// - (NSArray *)allKeysForObject:(id)anObject; // - (NSArray *)allKeysForObject:(id)anObject;
class_addMethod(self.class, @selector(allKeysForObject:), class_addMethod(self.class, @selector(allKeysForObject:),
imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, id object) { BLOCK_TO_IMPL(^(NSDictionary* obj, id object) {
return [obj.getPropertiesContainer allKeysForObject:object]; return [obj.getPropertiesContainer allKeysForObject:object];
})), }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(allKeysForObject:)))->types method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(allKeysForObject:)))->types
); );


// - (NSArray *)allValues; // - (NSArray *)allValues;
class_addMethod(self.class, @selector(allValues), class_addMethod(self.class, @selector(allValues),
imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) { BLOCK_TO_IMPL(^(NSDictionary* obj) {
return obj.getPropertiesContainer.allValues; return obj.getPropertiesContainer.allValues;
})), }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(allValues)))->types method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(allValues)))->types
); );
} }
Expand All @@ -99,17 +105,17 @@ + (void)setupNamedProperties
{ {
// - (void)removeObjectForKey:(id)aKey; // - (void)removeObjectForKey:(id)aKey;
class_addMethod(self.class, @selector(removeObjectForKey:), class_addMethod(self.class, @selector(removeObjectForKey:),
imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, id key) { BLOCK_TO_IMPL(^(NSDictionary* obj, id key) {
[obj.getPropertiesContainer removeObjectForKey:key]; [obj.getPropertiesContainer removeObjectForKey:key];
})), }),
method_getDescription(class_getInstanceMethod(NSMutableDictionary.class, @selector(removeObjectForKey:)))->types method_getDescription(class_getInstanceMethod(NSMutableDictionary.class, @selector(removeObjectForKey:)))->types
); );


// - (void)setObject:(id)anObject forKey:(id)aKey // - (void)setObject:(id)anObject forKey:(id)aKey
class_addMethod(self.class, @selector(setValue:forKey:), class_addMethod(self.class, @selector(setValue:forKey:),
imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, id value, id key) { BLOCK_TO_IMPL(^(NSDictionary* obj, id value, id key) {
[obj.getPropertiesContainer setValue:value forKey:key]; [obj.getPropertiesContainer setValue:value forKey:key];
})), }),
method_getDescription(class_getInstanceMethod(NSMutableDictionary.class, @selector(setValue:forKey:)))->types method_getDescription(class_getInstanceMethod(NSMutableDictionary.class, @selector(setValue:forKey:)))->types
); );
} }
Expand Down Expand Up @@ -181,55 +187,55 @@ + (BOOL)resolveNamedProperties:(SEL)selector
IMP implementation; IMP implementation;
if (isSetter) { if (isSetter) {
if (attrs[1]==_C_ID) if (attrs[1]==_C_ID)
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, id value) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj, id value) {
[obj.getPropertiesContainer setValue:value forKey:name]; [obj.getPropertiesContainer setValue:value forKey:name];
})); });
else if ((attrs[1]==_C_CHR) || (attrs[1]==_C_UCHR) || (attrs[1]==_C_USHT) || (attrs[1]==_C_INT) || (attrs[1]==_C_UINT) || (attrs[1]==_C_LNG) || (attrs[1]==_C_ULNG)) else if ((attrs[1]==_C_CHR) || (attrs[1]==_C_UCHR) || (attrs[1]==_C_USHT) || (attrs[1]==_C_INT) || (attrs[1]==_C_UINT) || (attrs[1]==_C_LNG) || (attrs[1]==_C_ULNG))
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, NSInteger value) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj, NSInteger value) {
[obj.getPropertiesContainer setValue:[NSNumber numberWithInteger:value] forKey:name]; [obj.getPropertiesContainer setValue:[NSNumber numberWithInteger:value] forKey:name];
})); });
else if(attrs[1]==_C_FLT) else if(attrs[1]==_C_FLT)
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, float value) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj, float value) {
[obj.getPropertiesContainer setValue:[NSNumber numberWithFloat:value] forKey:name]; [obj.getPropertiesContainer setValue:[NSNumber numberWithFloat:value] forKey:name];
})); });
else if(attrs[1]==_C_DBL) else if(attrs[1]==_C_DBL)
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, double value) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj, double value) {
[obj.getPropertiesContainer setValue:[NSNumber numberWithDouble:value] forKey:name]; [obj.getPropertiesContainer setValue:[NSNumber numberWithDouble:value] forKey:name];
})); });
else if(attrs[1]==_C_BOOL) else if(attrs[1]==_C_BOOL)
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj, bool value) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj, bool value) {
[obj.getPropertiesContainer setValue:[NSNumber numberWithBool:value] forKey:name]; [obj.getPropertiesContainer setValue:[NSNumber numberWithBool:value] forKey:name];
})); });
else { else {
NSLog(@"SubjectiveScript: Unsupported type encountered for property '%@' on '%@'. Skipping.", name, NSStringFromClass(owningClass)); NSLog(@"SubjectiveScript: Unsupported type encountered for property '%@' on '%@'. Skipping.", name, NSStringFromClass(owningClass));
return NO; return NO;
} }
} }
else { else {
if (attrs[1]==_C_ID) if (attrs[1]==_C_ID)
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj) {
return [obj.getPropertiesContainer valueForKey:name]; return [obj.getPropertiesContainer valueForKey:name];
})); });
else if ((attrs[1]==_C_CHR) || (attrs[1]==_C_UCHR) || (attrs[1]==_C_USHT) || (attrs[1]==_C_INT) || (attrs[1]==_C_UINT) || (attrs[1]==_C_LNG) || (attrs[1]==_C_ULNG)) else if ((attrs[1]==_C_CHR) || (attrs[1]==_C_UCHR) || (attrs[1]==_C_USHT) || (attrs[1]==_C_INT) || (attrs[1]==_C_UINT) || (attrs[1]==_C_LNG) || (attrs[1]==_C_ULNG))
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj) {
NSNumber* value = [obj.getPropertiesContainer valueForKey:name]; NSNumber* value = [obj.getPropertiesContainer valueForKey:name];
return value ? value.integerValue : 0; return value ? value.integerValue : 0;
})); });
else if(attrs[1]==_C_FLT) else if(attrs[1]==_C_FLT)
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj) {
NSNumber* value = [obj.getPropertiesContainer valueForKey:name]; NSNumber* value = [obj.getPropertiesContainer valueForKey:name];
return value ? value.floatValue : 0; return value ? value.floatValue : 0;
})); });
else if(attrs[1]==_C_DBL) else if(attrs[1]==_C_DBL)
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj) {
NSNumber* value = [obj.getPropertiesContainer valueForKey:name]; NSNumber* value = [obj.getPropertiesContainer valueForKey:name];
return value ? value.doubleValue : 0; return value ? value.doubleValue : 0;
})); });
else if(attrs[1]==_C_BOOL) else if(attrs[1]==_C_BOOL)
implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) { implementation = BLOCK_TO_IMPL(^(NSDictionary* obj) {
NSNumber* value = [obj.getPropertiesContainer valueForKey:name]; NSNumber* value = [obj.getPropertiesContainer valueForKey:name];
return value ? value.boolValue : false; return value ? value.boolValue : false;
})); });
else { else {
NSLog(@"SubjectiveScript: Unsupported type encountered for property '%@' on '%@'. Skipping.", name, NSStringFromClass(owningClass)); NSLog(@"SubjectiveScript: Unsupported type encountered for property '%@' on '%@'. Skipping.", name, NSStringFromClass(owningClass));
return NO; return NO;
Expand All @@ -240,4 +246,4 @@ + (BOOL)resolveNamedProperties:(SEL)selector
return YES; return YES;
} }


@end @end
4 changes: 2 additions & 2 deletions Lib/Types/NSNumber+SS.m
Expand Up @@ -52,15 +52,15 @@ - (B)B { return self.boolValue; }
+ (N*(^)(I value))I + (N*(^)(I value))I
{ {
return ^(I value) { return ^(I value) {
return [N numberWithInt:value]; return [N numberWithInteger:value];
}; };
} }
- (I)I { return self.integerValue; } - (I)I { return self.integerValue; }


+ (N*(^)(UI value))UI + (N*(^)(UI value))UI
{ {
return ^(UI value) { return ^(UI value) {
return [N numberWithInt:value]; return [N numberWithUnsignedInteger:value];
}; };
} }
- (UI)UI { return self.unsignedIntegerValue; } - (UI)UI { return self.unsignedIntegerValue; }
Expand Down

0 comments on commit 1dad15a

Please sign in to comment.