Skip to content

Commit c9148bb

Browse files
author
Matthew York
committed
Merge pull request #15 from uacaps/characterset
Characterset
2 parents 3e97440 + 185bf2a commit c9148bb

3 files changed

Lines changed: 34 additions & 11 deletions

File tree

NSObject-ObjectMap/NSObject+ObjectMap.m

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -365,11 +365,36 @@ +(id)objectOfClass:(Class)objectClass fromJSON:(NSDictionary *)dict {
365365

366366
-(NSString *)classOfPropertyNamed:(NSString *)propName {
367367
objc_property_t theProperty = class_getProperty([self class], [propName UTF8String]);
368-
NSString *className = [NSString stringWithFormat:@"%s", getPropertyType(theProperty)];
369-
return className;
368+
369+
const char *attributes = property_getAttributes(theProperty);
370+
char buffer[1 + strlen(attributes)];
371+
strcpy(buffer, attributes);
372+
char *state = buffer, *attribute;
373+
while ((attribute = strsep(&state, ",")) != NULL) {
374+
if (attribute[0] == 'T' && attribute[1] != '@') {
375+
// it's a C primitive type:
376+
/*
377+
if you want a list of what will be returned for these primitives, search online for
378+
"objective-c" "Property Attribute Description Examples"
379+
apple docs list plenty of examples of what you get for int "i", long "l", unsigned "I", struct, etc.*/
380+
NSString *typeName = [[NSString alloc] initWithData:[NSData dataWithBytes:(attribute + 1) length:strlen(attribute) - 1] encoding:NSUTF8StringEncoding];
381+
return typeName;
382+
}
383+
else if (attribute[0] == 'T' && attribute[1] == '@' && strlen(attribute) == 2) {
384+
// it's an ObjC id type:
385+
return @"id";
386+
}
387+
else if (attribute[0] == 'T' && attribute[1] == '@') {
388+
// it's another ObjC object type:
389+
NSData *data = [NSData dataWithBytes:(attribute + 3) length:strlen(attribute) - 4];
390+
NSString *className = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
391+
return className;
392+
}
393+
}
394+
return @"";
370395
}
371396

372-
397+
/*
373398
static const char * getPropertyType(objc_property_t property) {
374399
const char *attributes = property_getAttributes(property);
375400
char buffer[1 + strlen(attributes)];
@@ -382,7 +407,7 @@ -(NSString *)classOfPropertyNamed:(NSString *)propName {
382407
if you want a list of what will be returned for these primitives, search online for
383408
"objective-c" "Property Attribute Description Examples"
384409
apple docs list plenty of examples of what you get for int "i", long "l", unsigned "I", struct, etc.
385-
*/
410+
386411
return (const char *)[[NSData dataWithBytes:(attribute + 1) length:strlen(attribute) - 1] bytes];
387412
}
388413
else if (attribute[0] == 'T' && attribute[1] == '@' && strlen(attribute) == 2) {
@@ -391,11 +416,13 @@ -(NSString *)classOfPropertyNamed:(NSString *)propName {
391416
}
392417
else if (attribute[0] == 'T' && attribute[1] == '@') {
393418
// it's another ObjC object type:
419+
NSData *data = [NSData dataWithBytes:(attribute + 3) length:strlen(attribute) - 4];
420+
NSString *asdf = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
394421
return (const char *)[[NSData dataWithBytes:(attribute + 3) length:strlen(attribute) - 4] bytes];
395422
}
396423
}
397424
return "";
398-
}
425+
}*/
399426

400427
+(NSArray *)arrayFromJSON:(NSArray *)jsonArray ofObjects:(NSString *)obj {
401428
//NSString *filteredObject = [NSString stringWithFormat:@"%@s",obj];

Tests/UnitTests.xcodeproj/project.pbxproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
1FA6C2051834122B008C5B8D /* Project object */ = {
253253
isa = PBXProject;
254254
attributes = {
255-
LastUpgradeCheck = 0500;
255+
LastUpgradeCheck = 0510;
256256
ORGANIZATIONNAME = "Center for Advanced Public Safety";
257257
TargetAttributes = {
258258
1FA6C22D1834122B008C5B8D = {
@@ -363,7 +363,6 @@
363363
isa = XCBuildConfiguration;
364364
buildSettings = {
365365
ALWAYS_SEARCH_USER_PATHS = NO;
366-
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
367366
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
368367
CLANG_CXX_LIBRARY = "libc++";
369368
CLANG_ENABLE_MODULES = YES;
@@ -402,7 +401,6 @@
402401
isa = XCBuildConfiguration;
403402
buildSettings = {
404403
ALWAYS_SEARCH_USER_PATHS = NO;
405-
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
406404
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
407405
CLANG_CXX_LIBRARY = "libc++";
408406
CLANG_ENABLE_MODULES = YES;
@@ -460,7 +458,6 @@
460458
1FA6C2431834122B008C5B8D /* Debug */ = {
461459
isa = XCBuildConfiguration;
462460
buildSettings = {
463-
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
464461
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/UnitTests.app/UnitTests";
465462
FRAMEWORK_SEARCH_PATHS = (
466463
"$(SDKROOT)/Developer/Library/Frameworks",
@@ -483,7 +480,6 @@
483480
1FA6C2441834122B008C5B8D /* Release */ = {
484481
isa = XCBuildConfiguration;
485482
buildSettings = {
486-
ARCHS = "$(ARCHS_STANDARD_INCLUDING_64_BIT)";
487483
BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/UnitTests.app/UnitTests";
488484
FRAMEWORK_SEARCH_PATHS = (
489485
"$(SDKROOT)/Developer/Library/Frameworks",

Tests/UnitTests.xcodeproj/xcshareddata/xcschemes/UnitTests.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0500"
3+
LastUpgradeVersion = "0510"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

0 commit comments

Comments
 (0)