简体   繁体   中英

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: incompatible 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

只是一种预感,但是请尝试在WordService.m中的其他#import语句附近添加以下语句:

#import "Definition.h"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM