-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathClassBuilder.cpp
More file actions
28 lines (21 loc) · 903 Bytes
/
ClassBuilder.cpp
File metadata and controls
28 lines (21 loc) · 903 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "ClassBuilder.h"
namespace tns {
// Moved this method in a separate .cpp file because ARC destroys the class created with objc_allocateClassPair
// when the control leaves this method scope
Class ClassBuilder::GetExtendedClass(std::string baseClassName, std::string staticClassName) {
Class baseClass = objc_getClass(baseClassName.c_str());
std::string name = !staticClassName.empty() ? staticClassName : baseClassName + "_" + std::to_string(++ClassBuilder::classNameCounter_);
Class clazz = objc_getClass(name.c_str());
if (clazz != nil) {
int i = 1;
std::string initialName = name;
while (clazz != nil) {
name = initialName + std::to_string(i++);
clazz = objc_getClass(name.c_str());
}
}
clazz = objc_allocateClassPair(baseClass, name.c_str(), 0);
objc_registerClassPair(clazz);
return clazz;
}
}