Skip to content

Commit e832208

Browse files
committed
Merge pull request #16 from collinjackson/develop
support Swift classes in CCBReader
2 parents 3e133b9 + 6485f12 commit e832208

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

cocos2d-ui/CCBReader/CCBReader.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,6 +1251,14 @@ - (CCNode*) readNodeGraphParent:(CCNode*)parent
12511251

12521252
Class class = NSClassFromString(className);
12531253
if (!class)
1254+
{
1255+
// Class was not found. Maybe it's a Swift class?
1256+
// See http://stackoverflow.com/questions/24030814/swift-language-nsclassfromstring
1257+
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
1258+
NSString *classStringName = [NSString stringWithFormat:@"_TtC%d%@%d%@", appName.length, appName, className.length, className];
1259+
class = NSClassFromString(classStringName);
1260+
}
1261+
if (!class)
12541262
{
12551263
#if DEBUG
12561264
NSLog(@"*** [CLASS] ERROR HINT: Did you set a custom class for a CCNode? Please check if the specified class name is spelled correctly and available in your project.");

0 commit comments

Comments
 (0)