Z
Z
Zaur Abdulgalimov2015-02-26 14:53:55
Objective-C
Zaur Abdulgalimov, 2015-02-26 14:53:55

How to make classes unique for each static library in ObjectiveC?

There are two static libraries: lib1.a and lib2.a . Each library has its own implementation of class A.
The problem is that when executing, if the class from the lib1 library was used first, the same class is also used in the lib2 library.
How can I make each library use its own implementation of class A?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
An, 2015-02-26
@Flanker_4

I'm not sure if this will work, you need to try
1) Get the Class from the desired one
or something like this (the code was written right here, focusing on )

static inline Class getClassFromLib1(){
     int numberOfClasses = objc_getClassList(NULL, 0);
    Class *classes = calloc(sizeof(Class), numberOfClasses);
    Class retClass = Nil;
    numberOfClasses = objc_getClassList(classes, numberOfClasses);
    for (int i = 0; i < numberOfClasses; ++i) {
        Class c = classes[i];
        if (([NSBundle bundleForClass:c] ==/*нужная либа*/)&&(/*проверка на нужный класс*/)) {
               retClass = c;
               break;
        }
    }
    free(classes);
    return retClass;
}

2) create an object based on the received classes.
Class a = getClassFromLib1();
   id objectClass1 = [[a alloc] init];

Similarly for the second one.
Just add the "caching" of getting the class

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question