Adding Existing Framework to Xcode (iPhone) error - iphone

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>"

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.

Xcode: very strange error subclassing my own class

I have an iPhone app with a custom class, Detail, a subclass of UIViewController that I created.
I need to make a subclass of Detail, and I want to to call it ActivityDetail. So I wrote the following in my ActivityDetail.h file:
#import <UIKit/UIKit.h>
#import "Detail.h"
#interface ActivityDetail : Detail {
}
#end
The problem is that I'm getting a compiler error telling me this:
error: cannot find interface
declaration for 'Detail', superclass
of 'ActivityDetail'
And the strange thing is: I can change the superclass from Detail to UIView (for example), compile getting many errors (obviously), and then change the superclass to Detail again and everything works fine! But if I then change anything to the Detail class the problem comes back from the beginning...
How can I solve this?
It is recommended to not import classes beyond the default Foundation or UIKit imports in your header files. Instead you should do something similar:
Header
#import <UIKit/UIKit.h>
#class Detail;
#interface ActivityDetail : Detail {
}
#end
Implementation
#import "ActivityDetail.h"
#import "Detail.h"
#implementation ActivityDetail
#end
This allows your header to "know" about additional classes without forcing all "importers" of that header to also import everything it imports.
Here is a great reference question, and a great answer, regarding the usage of #class and #import.
Erm you are importing Detail as Dettaglio.h. Probably the compiler is not fluent in Italian.
Are you importing the .h where Detail is declared?
#import "Detail.h"
Either #import "Detail.h" or subclass from Dettaglio (depends on whichever one your Detail class is actually named.

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.

Can't add iAd delegate to ViewController

I'm trying to add iAd into my project. I'm following this tutorial http://bees4honey.com/blog/tutorial/how-to-add-iad-banner-in-iphoneipad-app/
I just added the iAd.framework package to my project and set it as Weak.
I added #import <iAd/iAd.h> into my .h file but whenever I try to add the ADBannerViewDelegate it doesn't show up in the intellisense, which means it's not accessible to me.
Same thing for ADBannerView class and the delegate methods (in case I add the delegate anyway).
Any ideas?
Restart XCode and set your target to "Device". The framework might not show up on intellisense but should work nevertheless.

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.