Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ace2600

macrumors member
Original poster
Mar 16, 2008
71
0
Austin, Texas
I am getting the warning "warning: class 'Search' does not implement the 'ResultProtocol' protocol" even though Search is not suppose to implement ResultProtocol.

I have three protocols: SearchProtocol, ResultsProtocol, and ResultProtocol. SearchProtocol defines a method that returns id<ResultsProtocol>, and ResultsProtocol defines a method that returns id<ResultProtocol>. I am having a tough time getting to the bottom of this.
PHP:
//SearchProtocol.h
#import "ResultsProtocol.h"
@protocol SearchProtocol <NSObject>
- (id<ResultsProtocol, UITableViewDataSource>)results;
@end

//ResultsProtocol.h
#import "ResultProtocol.h"
@protocol ResultsProtocol <NSObject>
- (id<ResultProtocol,UITableViewDataSource>)resultAtIndexPath:(NSIndexPath *)indexPath;
@end

//ResultProtocol.h
@protocol ResultProtocol <NSObject>
+ (NSArray *)doSomething:(NSString *)foo;
- (void)doSomethingElse:(NSString *)bar;
@end
These classes implement the protocols and make calls
PHP:
//Search.h
@interface Search : NSObject <SearchProtocol,UITableViewDataSource>
{...}
@end
//Search.m
@implementation Search
- (id<ResultsProtocol,UITableViewDataSource>)results {
    Results *results = [[[Results alloc] init] autorelease];
    return results;
}
@end

//Results.h
@interface Results : NSObject <ResultsProtocol,UITableViewDataSource>
{...}
@end
//Results.m
@implementation Results
- (id<ResultProtocol, UITableViewDataSource>)resultAtIndexPath:(NSIndexPath *)indexPath {
    Result *result = [[[Result alloc] init] autorelease];
    return self result;
}
@end

//Result.h
@interface Result : NSObject <ResultProtocol,UITableViewDataSource>
{...}
@end
//Result.m
@implementation Result
//Implements functions in protocol
@end
And this is the main page that gives the warning "warning: class 'Search' does not implement the 'ResultProtocol' protocol".
PHP:
//implementation of MainDataSource.m (a root class that calls search)
- (void)fooBar: {
    Search *search = [[[Search alloc] init] autorelease];
    //WARNING HAPPENS AT LINE BELOW
    [[SearchViewController alloc] initWithSearch:search] autorelease];
}

//SearchViewController.h
@interface SearchViewController : UIViewController
{...}
@property (nonatomic,retain) id<SearchProtocol, UITableViewDataSource> search;
@property (nonatomic,retain) ResultsViewController *resultsViewController;
- (id)initWithSearch:(id<SearchProtocol,UITableViewDataSource>)search;
@end
//SearchViewController.m
@implementation SearchViewController
- (id)initWithSearch:(id<SearchProtocol,UITableViewDataSource>)search {
    if (self = [super init]) {
        [self setSearch:search];
    }
    return self;
}
@end
I'm not sure if this was too much or not enough details, so please let me know if you need to see anything else. Every class does implement the functions of its protocol. Maybe the warning is propagating from a lower level like Results or Result. I just don't know where to look anymore.
 

walty

macrumors member
Jul 15, 2008
33
0
hi,

this seems to be an interesting problem, and I tried copy & paste the code and compile it in my machine. I replaced {...} into empty implementations, and removed the property about "ResultsViewController", which is not included in the post.

And the program basically compiles fine, yes, it does give warning about imcomplete impementation of tableview and tablecell and etc, which is normal, but I did not get ur mentioned warning.

However, I do think the foobar: method in the post has essentially wrong syntax, it should be at least of the following format(?)


Code:
//no colon after foobar
- (void)fooBar { 
    Search *search = [[[Search alloc] init] autorelease]; 
    //WARNING HAPPENS AT LINE BELOW 
//missing open bracket
    [[[SearchViewController alloc] initWithSearch:search] autorelease]; 
}


Hm.., I think the problem may be due to some kind of warning cacheing in XCode (as I tried that before), just curious, have u ever tried to restart your xcode or even your machine?



I am getting the warning "warning: class 'Search' does not implement the 'ResultProtocol' protocol" even though Search is not suppose to implement ResultProtocol.

I have three protocols: SearchProtocol, ResultsProtocol, and ResultProtocol. SearchProtocol defines a method that returns id<ResultsProtocol>, and ResultsProtocol defines a method that returns id<ResultProtocol>. I am having a tough time getting to the bottom of this.
PHP:
//SearchProtocol.h
#import "ResultsProtocol.h"
@protocol SearchProtocol <NSObject>
- (id<ResultsProtocol, UITableViewDataSource>)results;
@end

//ResultsProtocol.h
#import "ResultProtocol.h"
@protocol ResultsProtocol <NSObject>
- (id<ResultProtocol,UITableViewDataSource>)resultAtIndexPath:(NSIndexPath *)indexPath;
@end

//ResultProtocol.h
@protocol ResultProtocol <NSObject>
+ (NSArray *)doSomething:(NSString *)foo;
- (void)doSomethingElse:(NSString *)bar;
@end
These classes implement the protocols and make calls
PHP:
//Search.h
@interface Search : NSObject <SearchProtocol,UITableViewDataSource>
{...}
@end
//Search.m
@implementation Search
- (id<ResultsProtocol,UITableViewDataSource>)results {
    Results *results = [[[Results alloc] init] autorelease];
    return results;
}
@end

//Results.h
@interface Results : NSObject <ResultsProtocol,UITableViewDataSource>
{...}
@end
//Results.m
@implementation Results
- (id<ResultProtocol, UITableViewDataSource>)resultAtIndexPath:(NSIndexPath *)indexPath {
    Result *result = [[[Result alloc] init] autorelease];
    return self result;
}
@end

//Result.h
@interface Result : NSObject <ResultProtocol,UITableViewDataSource>
{...}
@end
//Result.m
@implementation Result
//Implements functions in protocol
@end
And this is the main page that gives the warning "warning: class 'Search' does not implement the 'ResultProtocol' protocol".
PHP:
//implementation of MainDataSource.m (a root class that calls search)
- (void)fooBar: {
    Search *search = [[[Search alloc] init] autorelease];
    //WARNING HAPPENS AT LINE BELOW
    [[SearchViewController alloc] initWithSearch:search] autorelease];
}

//SearchViewController.h
@interface SearchViewController : UIViewController
{...}
@property (nonatomic,retain) id<SearchProtocol, UITableViewDataSource> search;
@property (nonatomic,retain) ResultsViewController *resultsViewController;
- (id)initWithSearch:(id<SearchProtocol,UITableViewDataSource>)search;
@end
//SearchViewController.m
@implementation SearchViewController
- (id)initWithSearch:(id<SearchProtocol,UITableViewDataSource>)search {
    if (self = [super init]) {
        [self setSearch:search];
    }
    return self;
}
@end
I'm not sure if this was too much or not enough details, so please let me know if you need to see anything else. Every class does implement the functions of its protocol. Maybe the warning is propagating from a lower level like Results or Result. I just don't know where to look anymore.
 

ace2600

macrumors member
Original poster
Mar 16, 2008
71
0
Austin, Texas
Thank you Walty for taking the time on it. Admittedly, this code I provided was just the essence of the actual code. This was to make things easier to read, but I introduced typos in the mock up code like the missing open brackets.

I "solved" the problem by casting to id when sending the value. There is no longer any warnings. I'm still not sure the root of this problem, though.
Code:
- (void)fooBar: {
    Search *search = [[[Search alloc] init] autorelease];
    //Casts below where warning was happening
    [[[SearchViewController alloc] initWithSearch:(id)search] autorelease];
}
An important fact I forgot to mention, the program compiled and ran fine before, despite the warnings.

Also, yes, I restart my computer regularly and when in XCode, I clean the target often.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.