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>
Related
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'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
I have two objects, both of which are view controllers. The first (Ill call it viewController1) declares a protocol. The second (which unsurprisingly I will name viewController2) conforms to this protocol.
XCode is giving me a build error of: 'Cannot find protocol declaration for viewController1'
I have seen various questions on this subject and I am certain it is to do with a loop error, but I just can't see it in my case...
Code below..
viewController1.h
#protocol viewController1Delegate;
#import "viewController2.h"
#interface viewController1 {
}
#end
#protocol viewController1Delegate <NSObject>
// Some methods
#end
viewController2.h
#import "viewController1.h"
#interface viewController2 <viewController1Delegate> {
}
#end
Initially, I had the import line in viewController1 above that of the protocol declaration. This was preventing the project from building at all. After searching on SO, I realised the problem and switched the two lines around. I am now getting a warning (as opposed to an error). The project builds fine and actually runs perfectly. But I still feel there must be something wrong to be given a warning.
Now, as far as I can see, when the compiler gets to viewController1.h, the first thing it sees is the declaration of the protocol. It then imports the viewController.h file and sees this implements this protocol.
If it were compiling them the other way around, it would look at viewController2.h first, and the first thing it would do is import viewController1.h the first line of which is the protocol declaration.
Am I missing something?
Remove this line from viewController1.h:
#import "viewController2.h"
The problem is that viewController2's interface is preprocessed before the protocol declaration.
The general structure of the file should be like this:
#protocol viewController1Delegate;
#class viewController2;
#interface viewController1
#end
#protocol viewController1Delegate <NSObject>
#end
A.h:
#import "B.h" // A
#class A;
#protocol Delegate_A
(method....)
#end
#interface ViewController : A
#property(nonatomic,strong)id<ViewControllerDelegate> preViewController_B;(protocol A)
#end
B.h:
#import "A.h" // A
#class B;
#protocol Delegate_B
(method....)
#end
#interface ViewController : B
#property(nonatomic,strong)id<ViewControllerDelegate> preViewController_A;(protocol B)
#end
A.m:
#interface A ()<preViewController_B>
#end
#implementation A
(implement protocol....)
end
B.m:
#interface B ()<preViewController_A>
#end
#implementation B
(implement protocol....)
#end
For those who might need it:
It's also possible to fix this by moving the importation of ViewController1.h in ViewController2's implementation file (.m) instead of the header file (.h).
Like so:
ViewController1.h
#import ViewController2.h
#interface ViewController1 : UIViewController <ViewController2Delegate>
#end
ViewController2.h
#protocol ViewController2Delegate;
#interface ViewController2
#end
ViewController2.m
#import ViewController2.h
#import ViewController1.h
#implementation ViewController2
#end
This will fix the case where the error happens because ViewController1.h is imported in ViewController2.h before the protocol declaration.
I have ForceGaugeViewController class and ForceGaugeController class. I'm trying to make the ForceGaugeController class be a subclass of ForceGaugeViewController, but I'm receiving errors.
Error:
Cannot find interface declaration for ForceGaugeViewController
superclass of ForceGaugeController class.
ForceGaugeViewController.h
#import <UIKit/UIKit.h>
#import <math.h>
#import "HardwareController.h"
#import "ForceGaugeController.h"
#interface ForceGaugeViewController : UIViewController{
}
end
ForceGaugeViewController.m
#import "ForceGaugeViewController.h"
#implementation ForceGaugeViewController
ForceGaugeController.h
#import <Foundation/Foundation.h>
#import "ForceGaugeViewController.h"
#import "FMDatabase.h"
#import "FMResultSet.h"
#class ForceGaugeViewController;
// error here
#interface ForceGaugeController : ForceGaugeViewController{
}
#end
ForceGaugeController.m
#import "ForceGaugeController.h"
You can not only forward reference a class that you will inherit from or a protocol that you will implement. You just need to import the superclass in the header which you are already doing and then remove the #class declaration.
Edit: Also the superclass ForceGaugeViewController should not include the subclass ForceGaugeViewController in the header file.
ForceGaugeController.h
#import <Foundation/Foundation.h>
#import "ForceGaugeViewController.h"
#import "FMDatabase.h"
#import "FMResultSet.h"
#interface ForceGaugeController : ForceGaugeViewController{
}
#end
Be sure to avoid circular imports:
Make sure you do not import any of the header or implementation subclasses files into the superclass file where the superclass interface declaration is (.h file)
You're including ForceGaugeController.h in ForceGaugeViewController.h
and including ForceGaugeViewController.h in ForceGaugeController.h. Circular includes will confuse the compiler and that's probably what's wrong.
A header file for a class only needs to include the framework (ie. UIKit), the subclass, and any protocols the class conforms to. Forward declarations will do for the classes of instance instance variables/method arguments/properties.
Remove the line:
#class ForceGaugeViewController;
You are already importing the ForceGaugeViewController class via its header file at the top of your ForceGaugeController.m file.
EDIT 1
And as pointed out by #Chris Devereux, you have a circular reference in your header files, you will want to get rid of that as well.
EDIT 2
And not sure how I missed the self-import in your ForceGaugeController.h file. I assume that it's a typo, but if not I'm sure you know you have to remove it.
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.