Skip to content

Commit a543437

Browse files
committed
Merge pull request #947 from collinjackson/develop
support Swift classes in CCBReader
2 parents 903b558 + fcdeb4d commit a543437

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
@@ -1245,6 +1245,14 @@ - (CCNode*) readNodeGraphParent:(CCNode*)parent
12451245

12461246
Class class = NSClassFromString(className);
12471247
if (!class)
1248+
{
1249+
// Class was not found. Maybe it's a Swift class?
1250+
// See http://stackoverflow.com/questions/24030814/swift-language-nsclassfromstring
1251+
NSString *appName = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleName"];
1252+
NSString *classStringName = [NSString stringWithFormat:@"_TtC%d%@%d%@", appName.length, appName, className.length, className];
1253+
class = NSClassFromString(classStringName);
1254+
}
1255+
if (!class)
12481256
{
12491257
#if DEBUG
12501258
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)