Skip to content
Browse files

Updated for Mac support

  • Loading branch information...
1 parent eca4267 commit 1dad15a431aa50a093ac6a76feae929774e90563 Kevin Malakoff committed Aug 2, 2012
Showing with 78 additions and 44 deletions.
  1. +3 −1 Lib/Helpers/SS+System.h
  2. +28 −2 Lib/Helpers/SS+System.m
  3. +45 −39 Lib/NSDictionary+NamedProperties.m
  4. +2 −2 Lib/Types/NSNumber+SS.m
View
4 Lib/Helpers/SS+System.h
@@ -31,7 +31,9 @@
@interface SS (System)
-+ (NSS*)iOSVersion;
++ (NSS*)systemVersion;
++ (B)macSystem;
++ (B)iOSSystem;
+ (SSTaskId*(^)(SSTaskIdBlock block, I waitNS, BOOL background))addTask;
+ (void(^)(SSTaskId* taskId))stopTask;
View
30 Lib/Helpers/SS+System.m
@@ -31,11 +31,37 @@
#import "SS+System.h"
#import "NSString+Versioning.h"
+
+#include "TargetConditionals.h"
+#if defined(TARGET_OS_IPHONE) || defined(TARGET_IPHONE_SIMULATOR)
#import <UIKit/UIKit.h>
+#elif defined TARGET_OS_MAC
+#import <Cocoa/Cocoa.h>
+#endif
@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
{
@@ -62,7 +88,7 @@ + (A*)_runningTaskList
dispatch_queue_t dispatchQueue;
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);
else
dispatchQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0UL);
View
84 Lib/NSDictionary+NamedProperties.m
@@ -9,6 +9,12 @@
#import "NSDictionary+NamedProperties.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";
@implementation NSDictionary (NamedProperties)
@@ -33,61 +39,61 @@ + (void)setupNamedProperties
{
// - (id)initWithObjects:(const id [])objects forKeys:(const id [])keys count:(NSUInteger)cnt;
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;
for (NSUInteger index=0; index<count; index++) {
[properties setObject:objects[index] forKey:keys[index]];
}
return obj;
- })),
+ }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(initWithObjects:forKeys:count:)))->types
);
// - (NSUInteger)count;
class_addMethod(self.class, @selector(count),
- imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) {
+ BLOCK_TO_IMPL(^(NSDictionary* obj) {
return obj.getPropertiesContainer.count;
- })),
+ }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(count)))->types
);
// - (id)objectForKey:(id)aKey;
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];
- })),
+ }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(objectForKey:)))->types
);
// - (NSEnumerator *)keyEnumerator;
class_addMethod(self.class, @selector(keyEnumerator),
- imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) {
+ BLOCK_TO_IMPL(^(NSDictionary* obj) {
return [obj.getPropertiesContainer keyEnumerator];
- })),
+ }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(keyEnumerator)))->types
);
// - (NSArray *)allKeys;
class_addMethod(self.class, @selector(allKeys),
- imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) {
+ BLOCK_TO_IMPL(^(NSDictionary* obj) {
return obj.getPropertiesContainer.allKeys;
- })),
+ }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(allKeys)))->types
);
// - (NSArray *)allKeysForObject:(id)anObject;
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];
- })),
+ }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(allKeysForObject:)))->types
);
// - (NSArray *)allValues;
class_addMethod(self.class, @selector(allValues),
- imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) {
+ BLOCK_TO_IMPL(^(NSDictionary* obj) {
return obj.getPropertiesContainer.allValues;
- })),
+ }),
method_getDescription(class_getInstanceMethod(NSDictionary.class, @selector(allValues)))->types
);
}
@@ -99,17 +105,17 @@ + (void)setupNamedProperties
{
// - (void)removeObjectForKey:(id)aKey;
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];
- })),
+ }),
method_getDescription(class_getInstanceMethod(NSMutableDictionary.class, @selector(removeObjectForKey:)))->types
);
// - (void)setObject:(id)anObject forKey:(id)aKey
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];
- })),
+ }),
method_getDescription(class_getInstanceMethod(NSMutableDictionary.class, @selector(setValue:forKey:)))->types
);
}
@@ -181,55 +187,55 @@ + (BOOL)resolveNamedProperties:(SEL)selector
IMP implementation;
if (isSetter) {
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];
- }));
+ });
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];
- }));
+ });
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];
- }));
+ });
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];
- }));
+ });
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];
- }));
+ });
else {
NSLog(@"SubjectiveScript: Unsupported type encountered for property '%@' on '%@'. Skipping.", name, NSStringFromClass(owningClass));
return NO;
}
}
else {
if (attrs[1]==_C_ID)
- implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) {
+ implementation = BLOCK_TO_IMPL(^(NSDictionary* obj) {
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))
- implementation = imp_implementationWithBlock((void*)CFBridgingRetain(^(NSDictionary* obj) {
+ implementation = BLOCK_TO_IMPL(^(NSDictionary* obj) {
NSNumber* value = [obj.getPropertiesContainer valueForKey:name];
return value ? value.integerValue : 0;
- }));
+ });
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];
return value ? value.floatValue : 0;
- }));
+ });
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];
return value ? value.doubleValue : 0;
- }));
+ });
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];
return value ? value.boolValue : false;
- }));
+ });
else {
NSLog(@"SubjectiveScript: Unsupported type encountered for property '%@' on '%@'. Skipping.", name, NSStringFromClass(owningClass));
return NO;
@@ -240,4 +246,4 @@ + (BOOL)resolveNamedProperties:(SEL)selector
return YES;
}
-@end
+@end
View
4 Lib/Types/NSNumber+SS.m
@@ -52,15 +52,15 @@ - (B)B { return self.boolValue; }
+ (N*(^)(I value))I
{
return ^(I value) {
- return [N numberWithInt:value];
+ return [N numberWithInteger:value];
};
}
- (I)I { return self.integerValue; }
+ (N*(^)(UI value))UI
{
return ^(UI value) {
- return [N numberWithInt:value];
+ return [N numberWithUnsignedInteger:value];
};
}
- (UI)UI { return self.unsignedIntegerValue; }

0 comments on commit 1dad15a

Please sign in to comment.
Something went wrong with that request. Please try again.