Skip to content
Browse files

Make 10.6-compatible by only offering dynamic property addition when …

…targeting 10.7.
  • Loading branch information...
1 parent b261adb commit c4d55566b2f16c1dfedee1e0f944ec2fd3c0b708 @rentzsch rentzsch committed Nov 27, 2011
Showing with 18 additions and 3 deletions.
  1. +2 −0 MARTNSObject.h
  2. +2 −0 MARTNSObject.m
  3. +2 −0 RTProperty.h
  4. +2 −0 RTProperty.m
  5. +2 −0 RTUnregisteredClass.h
  6. +2 −0 RTUnregisteredClass.m
  7. +4 −1 main.m
  8. +2 −2 xcode/MAObjCRuntime.xcodeproj/project.pbxproj
View
2 MARTNSObject.h
@@ -33,7 +33,9 @@
+ (NSArray *)rt_properties;
+ (RTProperty *)rt_propertyForName: (NSString *)name;
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ (BOOL)rt_addProperty: (RTProperty *)property;
+#endif
// Apple likes to fiddle with -class to hide their dynamic subclasses
// e.g. KVO subclasses, so [obj class] can lie to you
View
2 MARTNSObject.m
@@ -159,10 +159,12 @@ + (RTProperty *)rt_propertyForName: (NSString *)name
return [RTProperty propertyWithObjCProperty: property];
}
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
+ (BOOL)rt_addProperty: (RTProperty *)property
{
return [property addToClass:self];
}
+#endif
- (Class)rt_class
{
View
2 RTProperty.h
@@ -22,7 +22,9 @@ RTPropertySetterSemantics;
- (id)initWithName: (NSString *)name attributes:(NSDictionary *)attributes;
- (NSDictionary *)attributes;
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- (BOOL)addToClass:(Class)classToAddTo;
+#endif
- (NSString *)attributeEncodings;
- (BOOL)isReadOnly;
View
2 RTProperty.m
@@ -55,6 +55,7 @@ - (NSDictionary *)attributes
return [[_attrs copy] autorelease];
}
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- (BOOL)addToClass:(Class)classToAddTo
{
NSDictionary *attrs = [self attributes];
@@ -72,6 +73,7 @@ - (BOOL)addToClass:(Class)classToAddTo
free(cattrs);
return result;
}
+#endif
- (NSString *)attributeEncodings
{
View
2 RTUnregisteredClass.h
@@ -21,7 +21,9 @@
- (void)addProtocol: (RTProtocol *)protocol;
- (void)addIvar: (RTIvar *)ivar;
- (void)addMethod: (RTMethod *)method;
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- (void)addProperty: (RTProperty *)property;
+#endif
- (Class)registerClass;
View
2 RTUnregisteredClass.m
@@ -56,10 +56,12 @@ - (void)addMethod: (RTMethod *)method
class_addMethod(_class, [method selector], [method implementation], [[method signature] UTF8String]);
}
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
- (void)addProperty: (RTProperty *)property
{
[property addToClass:_class];
}
+#endif
- (Class)registerClass
{
View
5 main.m
@@ -216,6 +216,7 @@ static void TestPropertyQuery(void)
TEST_ASSERT([[property ivarName] isEqual: @"someIvar"]);
}
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
static void TestAddProperty(void)
{
RTUnregisteredClass *unreg = [NSObject rt_createUnregisteredSubclassNamed: @"TestAddPropertyClass"];
@@ -235,13 +236,13 @@ static void TestAddProperty(void)
TEST_ASSERT([[properties valueForKey: @"name"] containsObject: @"assignedObjectProp"]);
RTProperty *property = [c rt_propertyForName: @"assignedObjectProp"];
- NSLog(@"%@", property);
TEST_ASSERT([[property name] isEqual: @"assignedObjectProp"]);
TEST_ASSERT([[property typeEncoding] isEqual: [NSString stringWithUTF8String: @encode(id)]]);
TEST_ASSERT([[property ivarName] isEqual: @"assignedIvar"]);
TEST_ASSERT([property setterSemantics] == RTPropertySetterSemanticsAssign);
}}
}
+#endif
static void TestIvarAdd(void)
{
@@ -340,7 +341,9 @@ int main(int argc, char **argv)
TEST(TestProtocolQuery);
TEST(TestIvarQuery);
TEST(TestPropertyQuery);
+#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070
TEST(TestAddProperty);
+#endif
TEST(TestIvarAdd);
TEST(TestEquality);
TEST(TestMessageSending);
View
4 xcode/MAObjCRuntime.xcodeproj/project.pbxproj
@@ -188,7 +188,7 @@
GCC_WARN_UNUSED_VARIABLE = YES;
ONLY_ACTIVE_ARCH = YES;
PREBINDING = NO;
- SDKROOT = macosx10.7;
+ SDKROOT = macosx;
};
name = Debug;
};
@@ -200,7 +200,7 @@
GCC_WARN_ABOUT_RETURN_TYPE = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
PREBINDING = NO;
- SDKROOT = macosx10.7;
+ SDKROOT = macosx;
};
name = Release;
};

0 comments on commit c4d5556

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