Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-24-2010, 01:20 PM   #1 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Orange County, CA
Posts: 20
dannys42 is on a distinguished road
Default ObjC matching the wrong class?

This is really baffling me...

I've got a class like so:

Code:
@interface DColor : NSObject {
    CGFloat _red, _green, _blue;
    CGFloat _alpha;
}
@property (readwrite, assign) CGFloat red;
@property (readwrite, assign) CGFloat green;
@property (readwrite, assign) CGFloat blue;
@property (readwrite, assign) CGFloat alpha;

-(DColor *)initWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
@end
However, later on, I have an initializer for another class like so:
Code:
#import "DColor.h"
@interface TimelineSection : NSObject {
    DColor *_dcolor;
}
@property (retain, readwrite) DColor *dcolor;
@end

@implementation UseDColor
@synthesize dcolor=_dcolor;
-(id)init {
    self = [super init];
    if( self ) {
        /* Attempt 1 */
        d = [[DColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f];

        /* Attempt 2 */
        [self setDcolor:[[DColor alloc] initWithRed:1.0f
                                            green:1.0f
                                             blue:1.0f 
                                            alpha:1.0f]];
        /* Attempt 3 */
        self.dcolor = [[DColor alloc] initWithRed:1.0f
                                            green:1.0f
                                             blue:1.0f 
                                            alpha:1.0f];

        /* Attempt 4 */
        self.dcolor = [[[DColor alloc] initWithRed:1.0f
                                            green:1.0f
                                             blue:1.0f 
                                            alpha:1.0f] autorelease];
    }
}
@end

Here's the strange thing... both Attempt 1-3 are issuing me compiler warnings:
Quote:
warning: incompatible Objective-C types assigning 'struct UIColor *', expected 'struct DColor *'
I end up having to do something weird like this to remove it:

Code:
        DColor *d;
        d = [DColor alloc];
        d = [d initWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f];
Or I just realized, Attempt #4 resolves the compiler warning as well. Is this normal behavior? Should I always be assigning with autorelease there?

Clearly it's conflicting with the UIColor implementation of initWithRed.. But why would it be confused like that? Can anyone explain what's going on and the proper fix for this?

Incidentally, if I put an NSLog() in the actual initWithRed method, it does get invoked. So clearly it's calling the right thing, even if it's a bit confused about it.

Thanks

Last edited by dannys42; 04-24-2010 at 02:14 PM.
dannys42 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 464
14 members and 450 guests
7twenty7, AlanFloyd, David-T, imac74, Jaxen66, logan, lovoyl, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:08 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0