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

Chirone

macrumors 6502
Original poster
Mar 2, 2009
279
0
NZ
i get this warning
warning: initialization from distinct Objective-C type

i googled this and i found out that it's caused when the returning type is no the same as the type it's being assigned too

however how is this possible when the two types match?

the initializer is like this:
Code:
-(ObjectOne*) initWithString: (NSString*) s {
    self = [super init];
    if(self) {
        ....
    }
    return self;
}
the making of an instance is like this:
Code:
ObjectOne* oo = [[ObjectOne alloc] initWithString: @"bleh"];
it's no different to any other initializing code yet it generates warnings and things that should happen never do... yet the object still exist when initialized....
:confused:
 
i get this warning
warning: initialization from distinct Objective-C type

i googled this and i found out that it's caused when the returning type is no the same as the type it's being assigned too

however how is this possible when the two types match?

. . .

the making of an instance is like this:
Code:
ObjectOne* oo = [[ObjectOne alloc] initWithString: @"bleh"];
it's no different to any other initializing code yet it generates warnings and things that should happen never do... yet the object still exist when initialized....
:confused:

I could be totally wrong as I don't know Obj-C, but maybe the @"bleh" is a const NSString? I don't know if a "const" would generate that warning.

Another thing to try is to split the alloc to temporary variable and then call the initWithString (on separate lines) to see if you only get the warning on one line.
 
Normally you return type id from initializers, not a static type. Try this:

Code:
- (id)initWithString:(NSString*) s {

What kind of object is ObjectOne? A subclass of NSObject?
 
thanks jpyc7, sorry, i didn't try your second suggestion, i don't think it would have worked if i did any of those anyway.
i didn't think that passing a literal would make a difference as it never has before...

HiRez, thanks... it's strange though, because i've always done it that way and it's never caused warnings or errors :confused: if it comes up again i'll try returning an id type instead (or am i meant to return a type id anyway? the first tutorial i ever saw never did.... so i assumed i didn't have to)
ObjectOne is a subclass of NSObject

the now confusing thing is... after compiling a lot of times and playing with the code inside ObjectOne's implementation file the warning disappeared...
did i alter the constructor method? NOPE
am i mystified by it? YES

very very odd.....
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.