Accessing AppDelegate.h from project - Beginner - iphone

I need to access AppDelegate.h from another project. The project structure is given below:
MYPROJECT
|_ OTHER PROJECT
|______OSAPPDELEGATE.H
|______OSAPPDELEGATE.M
|_ APPDELEGATE.H
|_ APPDELEGATE.M
I need to import #import AppDelegate.h from OsAppDelegate.h. How can i do this?

Set the Header Search Path within Xcode to:
$(PROJECT_DIR)/../OTHER PROJECT
and then simply:
#import "OSAPPDELEGATE.H"
better still, set the Header Search Path to:
$(PROJECT_DIR)/..
and:
#import "OTHER PROJECT/OSAPPDELEGATE.H"
However if you are importing an app delegate from another project then you are most certainly doing something wrong.

u can try doing this.. copy the methods of the app delegate into OsAppDelegate. not sure just try

Related

Cannot find interface declaration for 'UIView' in iOS Swift Project

I have a swift project which I'm making use of MBProgressHUD in through a Bridging header file. The issue I'm having is that UIView doesn't appear to be recognised as type and I don't know why.
In my bridging header I have:
#import "MBProgressHUD.h"
The errors I get when I try to build are all along the same lines:
Cannot find interface declaration for 'UIView', superclass of MBProgressHUD.
I have checked the MBProgressHUD file and I can see that it definitely imports the following:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#import "MBProgressHUD.h"
#import "CSNotificationView.h"
Has anyone else seen a similar issue? If so do you know what the issue is and how can I fix it?
I also come across the same issue and thats what i did to use MBProgressHud with swift 2
1) Specify use_frameworks! in your Podfile to use frameworks.
2) Add #import in your bridging header, use angle brackets instead of double quotes e.g -
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#import <MBProgressHUD/MBProgressHUD.h>
3) in your swift file also import MBProgressHUD e.g.
import UIKit
import MBProgressHUD
Now you can use MBProgressHud like -
MBProgressHUD.showHUDAddedTo(self.view, animated: true);
Hope it will help.
Remove your existing bridging header file and add a new one.
Make sure you are adding your bridging header path in SWIFT_OBJC_BRIDGING_HEADER under the target section instead of the project section.
You could also try adding a precompiled prefix header file (.pch) to your project. You'll find it under File/New/Other, there add the #import <UIKit/UIKit.h>clause, and then in the target's build settings, under Apple LLVM 7.0 - Language, set the Precompile Prefix Header flag to yes and add the .pch file like this "YourProjectName/YourProject-Prefix.pch".
See also this answer.
If you include the MBProgressHUD library with CocoaPods try to include a line similar to this
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <CoreGraphics/CoreGraphics.h>
#import "MBProgressHUD.h"
in
BridgeHeader.h and in Objective-C Bridging Header key in Build Settings choose the header.
For test if the library is correctly added I try to show a progress with this instruction in the ViewController:
MBProgressHUD.showHUDAddedTo(self.view, animated: true);
I tried it in a new project and it works.

Why is my property inaccessible for a class in different folder

I'm noticing something really strange.
I have a class A with a property:
#interface ClassA
#property (nonatomic, strong) NSString *test;
and a synthesize in the .m file.
now if I have a second class B as following:
#import "ClassA.h"
-(void) someMethod
{
ClassA *classA = [[ClassA alloc] init];
classA.test = #"test";
}
than this works fine if the 2 class files are in the same folder.
If I however move the files to separate subfolders, it won't work anymore.
The error I get is that the property doesn't exist. Similarly, 'intellisense' won't show the test property anymore.
If I make folder groups in xcode, but leave the actual files in the same physical folder, it does work.
Whats going on here?
It can't be an include path problem, since then I wouldn't even be able to instantiate ClassA.
already tried Xcode menu "product:clean"?
and i would try to delete your app from simulator, and also Xcode:preferences:locations:derived data -> from finder delete that finder folder
Try COMMAND+SHIFT+K and
Reset content and settings in iOS Simulator.
Did you try #class ClassA?
I solved it. I had an included subproject which used a class with the exact same name.
aaaaargh...
apparently there are no errors during compilation and it's unclear which of the files it will import.

Where do I get a managed object context?

In my AppDelegate.m, in the application: didFinishLaunchingWithOptions: method, I put the following line:
NSManagedObjectContext *context = [self managedObjectContext];
But it says: AppDelegate may not respond to managedObjectContext. I saw this in a tutorial online, what am I doing wrong? I put #import <CoreData/CoreData.h> in my App_Prefix.pch file (see Adding Core Data to existing iPhone project) but that didn't help.
The goal is to then set myViewController.context = context and then use that context to fetch some data in the view controller.
EDIT: Please see my comment to the answer of O. Begemann.
Create an empty sample app and make sure you check the Core Data checkbox. Then look at the boilerplate code for Core Data that has been generated in the application delegate. You need corresponding pieces of code in your app.
It is likely that the tutorial you are looking at used an iPhone project template that included Core Data. When you create a new project, most templates have a checkbox option to "Use Core Data for storage". Selecting that option creates three methods in your app delegate to retrieve a managedObjectContext, managedObjectModel and persistentStoreCoordinator. You would access those methods using [self managedObjectContext] etc, like in the tutorial you mention.
If you decide to add core data to an existing project and you didn't check off that box mentioned in the tutorial, you'll want to add the properties into the appdelegate header file as well as this important piece in your prefix.pch
#import <Availability.h>
#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#import <CoreData/CoreData.h>
#endif
Do you have a method with the signature -(NSManagedObjectContext *) managedObjectContext; or a #property(...) NSManagedObjectContext *managedObjectContext; in your AppDelegate.h?
Tim,
Thanks a lot for your suggestion. After creating this boilerplate app I have realized that XCode generates some additional code in the app delegate IF you select CoreData option. I could not understand why Apple's dev guide has relatively long multi-step process for initializing the core data stack and most of the examples just refer to this (non-existing by default!) property. It turns out that all these examples assume that the application was created in certain way.

Adding Existing Framework to Xcode (iPhone) error

I have added the <QuartzCore/QuartzCore.h> to my Frameworks folder in my iPhone project and added the #import "<QuartzCore/QuartzCore.h>" statement at the top of a custom UIView class.
However the custom UIView class gives me a "No such file or directory" compliation error in relation to the <QuartzCore/QuartzCore.h> framework. Is there something else I need to set so that the compiler can see the framework.
I'm not expert on the Xcode IDE so any assistance would be extremely welcome.
try removing the quotes around the <QuartzCore/QuartzCore.h>
you don't need them when you are importing a framework.
This is the correct syntax:
#import <QuartzCore/QuartzCore.h> // not #import "<QuartzCore/QuartzCore.h>"

Why do I get this error "error: expected specifier-qualifier-list before 'NSManagedObjectContext'?

1) I have the CoreData.framework imported. In Groups & Files I see it in the Framworks list together with UIKit.framework, Foundation.framework, CoreGraphics.framework.
2) I have this code, which should actually work. Don't know what that error means...
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#interface RootViewController : UITableViewController <CLLocationManagerDelegate> {
NSMutableArray *dataArray;
NSManagedObjectContext *managedObjectContext; // HERE's THE ERROR LINE
}
Edit: After importing CoreData, the error disappeared. BUT: Actually UIKit contains it, or not??
#import <CoreData/CoreData.h>
I have an Apple example code and they NEVER import CoreData, and it works.
Apple is taking advantage of the precompiled header (.pch file). Your projects do too when you start with a template and check the "Use Core Data for storage" option.
Also, you can use the precompiled header file to add any header files you wish to import for all source files in your target and project.
You need to link the CoreData framework and import CoreData/CoreData.h in the header file. UIKit does not contain the Core Data framework.