I've added some frameworks into my project, through the Targets -> Build Phases -> Link binary with Libraries. In particular, I am talking about the AVFoundation.framework. I've also added all the frameworks into the Frameworks folder in the project navigator.
However, when I try to reference classes in the linked frameworks, I'm getting "Semantic issue - Use of undeclared identifier" errors.
For example, I'm getting these errors in the two bottom lines:
- (void)viewDidLoad {
[super viewDidLoad];
AVCaptureSession *session = [[AVCaptureSession alloc] init];
session.sessionPreset = AVCaptureSessionPresetMedium;
}
I'm wondering if the frameworks are being properly linked to my project. So, how can I solve this? I must say that I am new to iOs and ObjC development.
Thank you
Looks like You forgot:
#import <AVFoundation/AVCaptureSession.h>
In my case, the import statements are in the middle of this block #ifdef FB_SONARKIT_ENABLED / #endif
After taking them back from the blocks, archiving was succeeded.
Before
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <RNGoogleSignin/RNGoogleSignin.h>
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
...
#endif
After
#import "AppDelegate.h"
#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import <RNGoogleSignin/RNGoogleSignin.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#ifdef FB_SONARKIT_ENABLED
#import <FlipperKit/FlipperClient.h>
#import <FlipperKitLayoutPlugin/FlipperKitLayoutPlugin.h>
#import <FlipperKitUserDefaultsPlugin/FKUserDefaultsPlugin.h>
#import <FlipperKitNetworkPlugin/FlipperKitNetworkPlugin.h>
#import <SKIOSNetworkPlugin/SKIOSNetworkAdapter.h>
#import <FlipperKitReactPlugin/FlipperKitReactPlugin.h>
...
#endif
Related
I have multiple protocol in Xcode Project it will give error such like this. help me
Error Like :-> Cannot find Protocol declaration for 'ButtonDelegate' did you mean 'CustomDelegate'?
Thanks in Advance
Delegate Header File
#import <UIKit/UIKit.h>
#import "Constant.h"
#protocol ButtonDelegate <NSObject>
-(void)ChatButtonClicked;
#end
#interface DonttreadonmeCell : UITableViewCell<UIGestureRecognizerDelegate,UITextViewDelegate>{
id <ButtonDelegate> Buttondelegate;
.h File
#import <UIKit/UIKit.h>
#import <Twitter/Twitter.h>
#import "JSONParsing.h"
#import "Facebook.h"
#import "DonttreadonmeCell.h"
#import "Constant.h"
#class DonttreadonmeCell;
#interface BookTextPeregraphselectedViewController : UIViewController<MFMailComposeViewControllerDelegate,FBSessionDelegate,FBRequestDelegate,ButtonDelegate,FBLoginDialogDelegate,FBDialogDelegate,JSONParsingDelegate,UITableViewDataSource,UITableViewDelegate,UIGestureRecognizerDelegate,UITextViewDelegate>{
I declared my protocol declaration section in top of the import file... it worked thank God.
#protocol ButtonDelegate <NSObject>
-(void)ChatButtonClicked;
#end
#import <UIKit/UIKit.h>
#import "Constant.h"
Like this
Include header file related to particular missing protocol.
In my case it was MFMailComposeViewControllerDelegate. I added
#import <MessageUI/MessageUI.h>
Problem fixed.
These 2 imports solved my problem. Please try it.
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
Why I get this error "Unknown type name 'XMLParser'; did you mean 'NSXMLParser'?" ? I have imported XMLParser.h, so I can't understand what the problem is.
#import <UIKit/UIKit.h>
#import "XMLParser.h"
#import "televisionList.h"
#import "ListingCell.h"
#interface TelevisionDetail : UIViewController <UITableViewDataSource, UITableViewDelegate>
{
XMLParser *xmlParser;
}
#end
Seems like Xcode bug, but also it's a good practice to avoid unnecessary import in .h file.
So try to add this before #interface..:
#class XMLParser;
And add #import "XMLParser.h" in your .m file.
I have two UIViewController, each has it's delegate and is calling one or the other. One class is called TopicViewController and the other is MentionViewController, the code looks something like the following:
#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <RestKit/RestKit.h>
#import "Message.h"
#import "Imgur.h"
#import "URLViewController.h"
#import "CVore.h"
#import "NSData+Base64.h"
#import "Imgur.h"
#import "ProfileViewController.h"
#import "OptionsViewController.h"
#import "Three20/Three20.h"
#class DetailViewController;
#class MentionViewController;
#protocol DetailViewControllerDelegate
- (void) viewController:(DetailViewController*)viewCon withText:(NSString *) text;
#end
#interface DetailViewController : UIViewController <MentionViewControllerDelegate>
///////////////////////////////////////////////////////////////////////////////////
#import <UIKit/UIKit.h>
#import <RestKit/RestKit.h>
#import "Members.h"
#import "DetailViewController.h"
#import "Three20/Three20.h"
#class MentionViewController;
#protocol MentionViewControllerDelegate
- (void) viewController:(MentionViewController*)viewCon withUsername:(NSString *) text;
#end
#interface MentionViewController : UITableViewController <DetailViewControllerDelegate>
Now the problem is that when I add #import "MentionViewController.h" to the DetailViewController it gives me the following error in the MentioViewController:
Cannot find protocol declaration for DetailViewControllerDelegate.
I understand this might be due to cylical referencing, but how do I solve this?
It is really strange. The MentionViewController needs the header file of DetailViewController, and the DetailViewController needs MentionViewController's header file. It is a cycle. Maybe you need to create a empty header file, and put all protocol inside it. For example,
MyProtocol.h
#class DetailViewController;
#class MentionViewController;
#protocol DetailViewControllerDelegate
- (void) viewController:(DetailViewController*)viewCon withText:(NSString *) text;
#end
#protocol MentionViewControllerDelegate
- (void) viewController:(MentionViewController*)viewCon withUsername:(NSString *) text;
#end
And add #import MyProtocol.h inside DetailViewController.h and MentionViewController.h.
You need to use forward declaration for the protocols and only import the headers in the implementation file.
I think your intuition is correct.
You should be able to solve this problem by declaring the 2 protocols in a header file of their own, then import this file from your .m files.
This will break the cycle.
I want to know the consequence of importing appDelegate in a class and the same class in appDelegate. Because, I'm doing this in my application successfully, but it's recommended that it should not be done. I couldn't find the answer despite a lot of searching.
Thanks in advance.
You can do it, but be careful with how you import headers. This is the recommended way:
AppDelegate.h:
// Import headers here
#class MyViewController;
#interface AppDelegate : NSObject <UIApplicationDelegate> {
MyViewController *viewController;
}
- (void)someMethod;
#end
AppDelegate.m:
#import "AppDelegate.h"
#import "MyViewController.h"
#implementation AppDelegate
//Your code here
#end
MyViewController.h:
// Import headers here
#class AppDelegate;
#interface MyViewController : UIViewController {
AppDelegate *appDelegate;
}
#end
MyViewController.m:
#import "MyViewController.h"
#import "AppDelegate.h"
#implementation MyViewController
// Your code here
#end
As you can see, you want to use #class to declare the classes in your headers, and then import the header in your .m files. This ensures that you’re not importing things that you don’t need; if you imported the view controller header in your app delegate’s header, it would be imported into anything that imported your app delegate’s header. By leaving all the imports to the .m files, you prevent that situation.
I just resolved a cyclic dependency problem by using class forwarding. Now, I am getting a warning of no 'showSumDetails' method found. I don't understand why it should happen at all, any help will be appreciated. Including a bit of code here:
MyAnnotation.h
#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>
//#import "MyMapViewController.h" obviously this wasn't possible :-(
#class MyMapViewController;
#interface MyAnnotation : NSObject<MKAnnotation> {
MyMapViewController* mapController;
}
MyMapViewController.h
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
#import <MapKit/MKReverseGeocoder.h>
#import "MyAnnotation.h"
#interface MyMapViewController : UIViewController <MKMapViewDelegate>{
MyAnnotation *annot;
}
MyMapViewController.m - where the method actually exists, and it is defined in the header file as well.
#implementation MyMapViewController
#synthesize annot;
-(void) showSumDetails:(id)aSumData{
NSLog(#"mapViewController-showSumDetails");
SumDetailsViewController *wrController = [[SumDetailsViewController alloc] init];
wrController.sumData = aSumData;
[self.navigationController pushViewController:wrController animated:YES];//This needs to be pushed
[wrController release];
}
#end
But the following method in MyAnnotation.m can't find the method above :-(
#implementation MyAnnotation
#synthesize sumData;
#synthesize mapController;
- (void) showPD{//is also defined in header file
NSLog(#"sPD - MyAnn");
[mapController showSumDetails:sumData]; //This doesn't have a clue about showSumDetails method- Why??
}
I'd be glad to provide any more info. Please help!!!
Did you import MyMapViewController.h in MyAnnotation.m?
Since you're using a forward reference for MyMapViewController in MyAnnotation.h you need to import MyMapViewController.h in MyAnnotation.m.