Cannot find protocol declaration for ' ' - objective-c

I know this question has been asked a lot, but it doesn't help me...
I have made a lot of delegate protocol in my projects, but this happened a lot...
I got an error cannot find protocol declaration for ''. The weird thing is that when i do this for the first time :
id<dataForEventDelegate> dataEventDelegate;
It works, i build, i try a rebuild and PAF doesn't find the protocole anymore...
my code looks like that in my delegate .H :
#protocol dataForEventDelegate <NSObject>
-(void)setStartDateLabel:(NSDate *)startDaleLabel;
-(void)setEndDateLabel:(NSDate *)endDaleLabel;
-(void)setDefaultCalendarLabel;
#end
#interface EventViewController : UIViewController <UITextFieldDelegate, UIPickerViewDelegate, dataForEventDelegate>
this is in my file.h which should use the delegate
#import "EventViewController.h"
#interface datePickerController : UIPickerView <UIPickerViewDelegate, UIPickerViewDataSource>
{
id<dataForEventDelegate> dataEventDelegate;
NSMutableArray *dateArray;
}
#property(nonatomic, strong) id<dataForEventDelegate> dataEventDelegate;
this dataForEventDelegate is not found !! BUT IT SHOULD :(

It seems you have not made datePickerController conform to the protocol, should be:
#interface datePickerController : NSObject <UIPickerViewDelegate, UIPickerViewDataSource, dataForEventDelegate>
I would also question why you are declaring datePickerController as a UIPickerView. See My example is NSObject.
I am also not sure why you would want EventViewController to conform to its own protocol. See it removed here:
#interface EventViewController : UIViewController <UITextFieldDelegate, UIPickerViewDelegate>

Related

Cannot find interface declaration for superclass of

I know this is a common subject but I did not find any answer to help me out with this problem.
Well, I do have (by now) 3 .h files,
One is the superclass of the two others.
Superclass : ExportationAutoFilterNew
#import <Foundation/Foundation.h>
#import <HIDDEN/PluginFilter.h>
#class MyOutlineView;
#interface ExportationAutoFilterNew : PluginFilter
#property (assign, nonatomic) NSUserDefaults *prefs;
#property (assign, nonatomic) MyOutlineView *databaseOutline;
#end
Then, sub-classes : DetectNewExams & ExportExams
#import <Foundation/Foundation.h>
#import <HIDDEN/PluginFilter.h>
#import "ExportationAutoFilterNew.h"
#interface DetectNewExams : ExportationAutoFilterNew
- (void)detectExams:(NSDate*)currentDate timeInterval:(double)timeInterval afterExitHidden:(BOOL)check;
And
#import <Foundation/Foundation.h>
#import <HIDDEN/PluginFilter.h>
#import "ExportationAutoFilterNew.h"
#interface ExportExams : ExportationAutoFilterNew
- (void)exportExams:(NSManagedObject*)curObj;
The .m goes like this
Superclass : ExportationAutoFilter
#import <HIDDEN/PreferencesWindowController.h>
#import <HIDDEN/browserController.h>
#import "ExportationAutoFilterNew.h"
#import "DetectNewExams.h"
#implementation ExportationAutoFilterNew
Xcode for this file (ExportationAutoFilterNew.m) :
Instance method '-detectExams:timeInterval:afterExitHidden:' not found (return type defaults to 'id')
For the call of :
[self detectExams:lastExportDate timeInterval:0 afterExitHidden:YES];
Sub-classes : DetectNewExams
#import <HIDDEN/PreferencesWindowController.h>
#import <HIDDEN/browserController.h>
#import "DetectNewExams.h"
#import "ExportExams.h"
#implementation DetectNewExams
In this file (DetectNewExams.m), Xcode says :
Instance method '-exportExams:' not found(return type defaults to 'id')
Calling :
[self exportExams:curObj];
And then : ExportExams
#import <HIDDEN/PreferencesWindowController.h>
#import <HIDDEN/browserController.h>
#import "ExportExams.h"
#implementation ExportExams
I'm wasting hours on this thing and I can't figure the problem out, may you help me ? I looked up for compiling circle but I don't think I created one with my imports ..
Thanks.
Your interface is not properly declared. Try this.
#interface ExportationAutoFilterNew : PluginFilter
#property (nonatomic) NSUserDefaults *prefs;
#property (nonatomic) MyOutlineView *databaseOutline;
#end
Now that you have posted the actual error, this becomes more clear. But you still haven't posted enough context.
Instance method '-detectExams:timeInterval:afterExitHidden:' not found (return type defaults to 'id')
That means that the method declaration hasn't been seen at the time the code was compiled or the method is declared on some class that whatever was being called is not an instance of.
Since you haven't shown the call site or the declaration of the variable being called, this is a guess. The method is declared on the DetectNewExams class. I'd bet you have a variable that points to an instance of ExportationAutoFilterNew and, therefore, the compiler is correctly warning that the method doesn't exist on the class.

Objective C protocol - some stupidly basic help needed, please

I'm having a problem when I try to add a second protocol. The first one is working just fine. So I created a test application to try out using two protocols (because I'm still learning how to use protocols). I do not know why I am having so much trouble understanding protocols. I've even gone through tutorials and still struggle with them.
My first issue when I tried to add the second protocol and use it I received the following error:
Assigning to ‘id’ from incompatible type ‘ *const _strong'
But, let's ignore that for now, because my test application is giving me this error for both protocols in my test app:
Cannot find protocol declaration
So, I will post the code for my test application, because I MUST understand the basics before tackling more difficult issues.
DelegateA Header
#import <Foundation/Foundation.h>
#protocol IDDelegateADelegate <NSObject>
#end
#interface IDDelegateA : NSObject
//other properties here
#property (nonatomic, assign) id<IDDelegateADelegate> delegateA;
#end
DelegateA Implementation
#import "IDDelegateA.h"
#implementation IDDelegateA
#synthesize delegateA;
//other methods and properties go here
#end
DelegateB Header
#import <Foundation/Foundation.h>
#protocol IDDelegeteBDelegate <NSObject>
#end
#interface IDDelegeteB : NSObject
//other properties here
#property (nonatomic, assign) id<IDDelegeteBDelegate> delegateB;
#end
DelegateB Implementation
#import "IDDelegeteB.h"
#implementation IDDelegeteB
#synthesize delegateB;
//other methods and properties go here
#end
The test class Header that uses these delegates
#import <Foundation/Foundation.h>
#import "IDDelegateA.h"
#import "IDDelegeteB.h"
#interface IDTestingDelegates : NSObject <IDDelegateA, IDDelegateB>
#end
Right here I receive the Cannot find protocol declaration error for both delegates. I've been searching on SO as well as going through tutorials and sample code. Best answer on SO was here. But I'm just not getting what I'm doing wrong. Can somebody please point out what I am missing here?
#interface IDTestingDelegates : NSObject <IDDelegateA, IDDelegateB>
should be
#interface IDTestingDelegates : NSObject <IDDelegateADelegate, IDDelegeteBDelegate>
You have to list the protocols in <...>, not interfaces.
#interface declares a class, while the ClassName <X> syntax expects X to be a protocol (in your declaration of IDTestingDelegates).
Not sure exactly what you were trying to achieve here.

Need little help incomplete implementation error in Objective-C

I'm getting an "incomplete implementation" error in my .m file, but I cannot figure it out how to fix it. I`ll post .h and .m files if you can give me tips on how to fix that. Thanks.
Apparently, I need to put more details, or I cannot post the question because the post contains mostly code, so this are just some dummy lines.
.h File
#import <UIKit/UIKit.h>
#interface BlogViewController : UIViewController <UIPickerViewDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate>
- (IBAction)selectPicturePressed:(id)sender;
- (IBAction)blogPost:(id)sender;
#property (weak, nonatomic) IBOutlet UITextView *commentTextField;
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (nonatomic, strong) NSString *username;
#end
.m File
#import "BlogViewController.h"
#import <Parse/Parse.h>
#import "SWRevealViewController.h"
#import "PhotoViewController.h"
#interface BlogViewController ()
-(void)showErrorView:(NSString *)errorMsg;
#end
#implementation BlogViewController **//Incomplete Implementation**
#synthesize imageView = _imageView;
#synthesize username = _username;
#synthesize commentTextField = _commentTextField;
IBActions are just regular functions with syntactic sugar for connecting them to interface builder therefore you have to implement them in the .m file
.m file:
- (IBAction)selectPicturePressed:(id)sender {
// code here
}
- (IBAction)blogPost:(id)sender {
// and here
}
On the line that's giving you the Incomplete Implementation error, you can get more details about what you're missing.
You don't paste all your .m so it's anyone's guess what you're missing, however, your .h declares 2 methods and 3 protocols that you must implement.
Your .m file must have method bodies for these two methods:
- (IBAction)selectPicturePressed:(id)sender;
- (IBAction)blogPost:(id)sender;
Likely, you already have these in here, particularly if these were generated by Ctrl+Dragging from interface builder.
But you must also include, at a minimum, all the required methods from the protocols you declared.
UIPickerViewDelegate protocol official documentation
UINavigationControllerDelegate protocol official documentation
UIImagePickerControllerDelegate protocol official documentation.
(I'm not completely familiar with these protocols and don't know for sure that they actually have any #required methods.)
Your .m also has a private interface, which declares a method you must implement in the implementation.
-(void)showErrorView:(NSString *)errorMsg;
You declared this method in a private interface, so be sure to implement this method as well.
Regardless of what you're missing, Xcode will absolutely tell you if you just click on the error/warning. Xcode will give you the names of the methods its expecting to find in your implementation but cannot.

Error when declaring delegate property

This should be an easy question - but I'm having a hard time figuring it out. I'm trying to create a property on an object so that during prepareForSegue I can tell the object what it's delegate is. I know I could do this with protocols but I figured for this case a direct approach would be simplest. Unfortunately, the following code results in a compiler error:
#import <UIKit/UIKit.h>
#import "PlanningViewController.h"
#interface DepartmentViewController : UITableViewController
#property (nonatomic, weak) PlanningViewController *planningDelegate;
#end
When I type the property declaration, Xcode recognizes PlanningViewController and even displays the text for me to just tab through. The compiler, though, complains with:
Unknown type name 'PlanningViewController': did you mean 'UISplitViewController'?
What am I doing wrong?
PlanningViewController.h looks like this:
#import <UIKit/UIKit.h>
#import "DepartmentViewController.h"
#interface PlanningViewController : UITableViewController
// Table cell connections
- (IBAction)addItemPressed:(id)sender;
#end
Remove this line from your PlanningViewController.h header file:
#import "DepartmentViewController.h"
You have something of a loop in your header files.
Better still, make DepartmentViewController.h look like this (there is no need to include PlanningViewController.h in your header file):
#import <UIKit/UIKit.h>
#class PlanningViewController;
#interface DepartmentViewController : UITableViewController
#property (nonatomic, weak) PlanningViewController *planningDelegate;
#end
I think you've kind of missed one of the main points of the delegate patter which is to decouple you objects. The best way of declaring this delegate would be:
#import <UIKit/UIKit.h>
#protocol DepartmentViewControllerDelegate; // forward declaration of protocol
#interface DepartmentViewController : UITableViewController
#property (nonatomic, weak) id <DepartmentViewControllerDelegate> delegate;
#end
#protocol DepartmentViewControllerDelegate
- (void)departmentViewController:(DepartmentViewController *)controller
isProcessingPeople:(NSArray *)people
#end
In your department view controller, you would then write something like this:
if ([self.delegate respondsToSelector:#selector(departmentViewController:isProcessingPeople:)]) {
[self.delegate departmentViewController:self isProcessingPeople:people];
}
And in your planning view controller, you would implement this method:
- (void)departmentViewController:(DepartmentViewController *)controller
isProcessingPeople:(NSArray *)people {
// do necessary work here
}
The example here is just an example of one message you can send to the delegate. You can add whatever you need, but this makes it so there is no coupling between your controllers. The planning view controller knows everything it needs to about the department controller, but the department controller doesn't need to know anything about the planning controller.
If you want to stick with what you have currently, just recognize that it's not really the delegate pattern, and you should probably rename your property.

trouble with declaring a delegate

i have two views with view1 calling view2. i need to pass data from view2 back to view1. so i am attempting to set up a delegate. here's what i got in view controller 2:
.h file
#protocol addEventDelegate <NSObject>
-(void) setAddedEventFlag:(BOOL) hasAddedEvent;
#end
#interface AddEventViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate, UIPickerViewDelegate, UIPickerViewDelegate>
#property (weak, nonatomic) id delegate; //changed from strong to weak
i then #synthesize delegate in the .m file
when try to include the addEventDelegate for the first view controller, xcode can not find it:
.h file
#import "AddEventViewController.h"
#interface FieldReportViewController : UIViewController <UITextFieldDelegate,
UITextViewDelegate, UIPickerViewDelegate, UIPickerViewDelegate, addEventDelegate>
i get the error: "Cannot find protocol declaration for 'addEventDelegate'".
what is wrong?
EDIT:
//code
ERRORS:
Make sure your spelling is correct.
Make sure that AddEventViewController.h/.m are added to the project.
Other than that, what you have is fine.
Edit
Something else I would suggest is to rename your delegate, perhaps there is a naming conflict. Although I haven't seen any issues with 'add' and 'set', but I've seen issues in the past when prefixing with, say, 'new'.
Also, clean your project, and rebuild and see if that helps.
There could be a situation if you have multiple targets in your project, and possibly only added AddEventViewController.h/m to one of them, and you are building/debugging a different target.
Here's the correct way to define a protocol
#protocol addEventDelegate; // forward declaration for delegate property
#interface AddEventViewController : UIViewController <UITextFieldDelegate, UITextViewDelegate, UIPickerViewDelegate, UIPickerViewDelegate>
{
id <addEventDelegate> *delegate
}
#property (weak, nonatomic) id <addEventDelegate> *delegate;
#end // interface
#protocol addEventDelegate <NSObject>
// #optional // if you want to make it optional
-(void) setAddedEventFlag:(BOOL) hasAddedEvent;
#end // protocol
Solved the issue. i had an #import loop. I was #importing all my classes in my .h files. i changed to #Class in .h file and moved the #import's to the .m files and works like a charm now.
You can import addEventDelegate in FieldReportViewController.m file
#interface FieldReportViewController ()<AddEventDelegate>
#end
This one is working in my app