Does not implement the protocol and not suppose to

Discussion in 'iOS Programming' started by ace2600, Oct 15, 2008.

  1. ace2600 macrumors member

    Joined:
    Mar 16, 2008
    Location:
    Austin, Texas
    #1
    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<ResultsProtocolUITableViewDataSource>)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 allocinitautorelease];
        return 
    results;
    }
    @
    end

    //Results.h
    @interface Results NSObject <ResultsProtocol,UITableViewDataSource>
    {...}
    @
    end
    //Results.m
    @implementation Results
    - (id<ResultProtocolUITableViewDataSource>)resultAtIndexPath:(NSIndexPath *)indexPath {
        
    Result *result = [[[Result allocinitautorelease];
        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 allocinitautorelease];
        
    //WARNING HAPPENS AT LINE BELOW
        
    [[SearchViewController allocinitWithSearch:searchautorelease];
    }

    //SearchViewController.h
    @interface SearchViewController UIViewController
    {...}
    @
    property (nonatomic,retainid<SearchProtocolUITableViewDataSourcesearch;
    @
    property (nonatomic,retainResultsViewController *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.
     
  2. walty macrumors member

    Joined:
    Jul 15, 2008
    #2
    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?



     
  3. ace2600 thread starter macrumors member

    Joined:
    Mar 16, 2008
    Location:
    Austin, Texas
    #3
    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.
     

Share This Page