Reputation: 36003
I have this project called engine.xcodeproj embedded inside another project myApp.
This engine has to get an value from MainViewController.h that is the header of a class of the application, outside the scope of the engine.xcodeproj.
How do I make all app main paths visible to embedded projects!
I am using Xcode 5 and compiling for iOS 6.
I have answered this before on SO, but the answers to those questions are not solving this case...
see picture:
thanks.
Upvotes: 0
Views: 90
Reputation: 57060
Uhm, this is what is called spaghetti code.
It would be better to define a protocol in the Engine project, which your view controller can implement, and then pass an id<Protocol>
to the engine. This creates an abstraction between the two projects while defining a strong language (API) between them. You mention you wish to use the Engine project in several apps - this is your best solution.
In Engine project:
@protocol MyAPIProtocol
@required
//Define here the actions you want to perform/get from the data source.
- (CGFloat)floatValue;
- (UITextView*)textView;
- (void)displayAlertWithMessage:(NSString*)message;
@end
Now, your Rocket class should have a property defined like so:
@property (nonatomic, weak) id<MyAPIProtocol> dataSource; //Whatever name you need, of course
Now in your apps that use this Engine project:
#import "MyAPIProtocol.h"
@interface MainViewController () <MyAPIProtocol>
@end
@implementation MainViewController
...
//Implement the protocol
- (CGFloat)floatValue
{
return 123.0f;
}
- (UITextView*)textView
{
return self.textView;
}
- (void)displayAlertWithMessage:(NSString*)message
{
//...
}
@end
The result is that the Engine project is self-contained, and does not need to know the implementation of MainViewController
. It just knows that it has a dataSource
property which can satisfy all its needs.
Now, when you have your Engine object ready in your MainViewController, you should set its data source by:
self.engine.dataSource = self;
Upvotes: 4