2

I have a relatively simple question and I hope to get an answer on it.

Imagine I have a static library in iOS say MyLibrary.a

In this library say there is some .m file which calls: "#import SomeHeaderWhichDoesNotYetExist.h" -- however the thing is that, when the "#import SomeHeaderWhichDoesNotYetExist.h" is called, the SomeHeaderWhichDoesNotYetExist.h may not necessarily exist in the project (as suggested also by its title). e.g.,

#ifdef something #import SomeHeaderWhichDoesNotYetExist.h #endif 

When someone uses the Mylibrary.a -- he/she may then, later implement the SomeHeaderWhichDoesNotYetExist.h, and we want the MyLibrary.a to be able to automatically use it as specified in the code above. Do you think this is possible?

Thank you.

4
  • My use case is following. I have myLibrary.a file, which has certain .m files in it. One of the .m files say class1.m has a method in it, which depending on whether iPhone or iPad application is running, should #import different header files. Additional thing is that, when I mention inside the library the header files that should be included in class1.m method for instance, these headers may not exist, i.e., they maybe later added by a user to his/her project, separately from the library and I want the library to be able to automatically use those headers. was wondering if this was possible? Commented Dec 5, 2012 at 14:21
  • To make long story short, the library should behave differently on iPhone and iPad? Run different code, maybe reference different assets? Commented Dec 5, 2012 at 14:36
  • Yes, let's say not the whole library. Big part of the library stays the same, i.e., core -- that was the main idea actually of having the shared library. But in some cases, in some functions, the library behaves differently depending on whether it is an iPad or iPhone indeed. Commented Dec 5, 2012 at 14:43
  • Then IMHO the best thing you can do is to delete this question and start a new one, describing these high-level goals. Because conditional compilation is not the only way to solve your problem, there are others that would probably work better. Commented Dec 5, 2012 at 15:27

2 Answers 2

2

We often use similar kind as you can see

#ifdef TARGET_OS_IPHONE // iOS #elif defined TARGET_IPHONE_SIMULATOR // iOS Simulator #elif defined TARGET_OS_MAC // Other kinds of Mac OS #else // Unsupported platform #endif 

So I would say, yes you can!!!

But you need to define something.

Sign up to request clarification or add additional context in comments.

1 Comment

thanks but I doubt now due to some answers above. please also see my comment above if it clarifies more my situation. Thanks !!
0

No, it can't, at least not the way you showed.

The conditional compilation blocks you showed are for the pre-processor, and it is called before compilation. If you want to include anything new this way, you must rebuild.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.