How to remove this warning from wordnik sample for iPhone?
I am using an example from WordNik samples-sdk, I killed most memory leaks but there's a warning that I can't understand what it is and how to fix it!
I have asked help on their Google group but while they answered to pretty much to every question that I asked, they keep ignoring this one, I am hopeful that the collective brain of stackoverflow solves the problem.
This file generates a warning on iPad/iPhone - file where the warning is generated.
Wordnik/WordService.m: In function '-[WordService fetchDefinitions:useCanonical:]':
Wordnik/WordService.m:52: warning: incompatibl开发者_运维百科e Objective-C types initializing 'struct Word *', expected 'struct Definition *'
The whole sdk-sample is here.
I think you meant to link to this file. On line 52 we find this:
Definition * def = [[Definition alloc]init:dict];
The compiler can't work out whether the init:
method refers to (Word *)init:
from the Word class or (Definition *)init:
from the Definition class. It's incorrectly guessing that it's the method from the Word class and therefore giving you a warning that you're initialising a Definition* variable with a Word* object.
It's solvable with a cast like so:
Definition * def = [((Definition *)[Definition alloc]) init:dict];
Or even:
Definition * def = (Definition *) [[Definition alloc]init:dict];
And no, the compiler isn't smart enough to realise that [Definition alloc]
probably returns a Definition object.
(I can't help but mention that whoever wrote that sample code has a very casual attitude to releasing/autoreleasing objects and an apparent love of memory leaks. In that one file word
is never releaed, none of the values stored in def
are ever released and nor is definitions
)
The sample code is just that, sample code, not intended for real-world use. But Wordnik (for which I work) is working on an official Objective-C SDK. It fully supports the Wordnik API, and has some nice features like request batching. If you're interested in early access, there's information in this thread:
http://groups.google.com/group/wordnik-api/browse_thread/thread/13bcfb6b53c7eaee
Just a hunch, but try adding the following statement near the other #import statements in WordService.m:
#import "Definition.h"
精彩评论