Skip to content
This repository has been archived by the owner on Jun 19, 2019. It is now read-only.

Commit

Permalink
fixed swift class resolution when app name has spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Aggouri committed Aug 31, 2015
1 parent 67a17a7 commit 78b1f6f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Classy/Parser/CASParser.m
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ - (NSArray *)nextStyleNodes {
styleSelector.styleClass = [tokenValue substringFromIndex:1];
} else {
styleSelector.objectClass = NSClassFromString(tokenValue);
if (!styleSelector.objectClass) {
if (!styleSelector.objectClass) {
// Maybe it's a custom Swift class
styleSelector.objectClass = [self swiftClassFromString:tokenValue];
}
Expand Down Expand Up @@ -779,9 +779,10 @@ - (CASStyleProperty *)nextStylePropertyIsParent:(BOOL *)isParent {
}

- (Class)swiftClassFromString:(NSString *)className {
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
NSString *classStringName = [NSString stringWithFormat:@"_TtC%lu%@%lu%@", (unsigned long)appName.length, appName, (unsigned long)className.length, className];
return NSClassFromString(classStringName);
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
NSString *sanitizedAppName = [appName stringByReplacingOccurrencesOfString:@" " withString:@"_"];
NSString *classStringName = [NSString stringWithFormat:@"_TtC%lu%@%lu%@", (unsigned long)sanitizedAppName.length, sanitizedAppName, (unsigned long)className.length, className];
return NSClassFromString(classStringName);
}


Expand Down

0 comments on commit 78b1f6f

Please sign in to comment.