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 > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 02-08-2012, 09:08 AM   #1 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default Delegate confusion...

The error:
Code:
Existing ivar 'delegate' for unsafe_unretained property 'delegate' must be_unsafe_unretained
The code:
Code:
@interface HRColorPickerViewController : UIViewController
{
    id<HRColorPickerViewControllerDelegate> delegate;
    HRColorPickerView* colorPickerView;
    
    UIColor *_color;
    BOOL _fullColor;
    HCPCSaveStyle _saveStyle;
}

@property (assign, nonatomic) id<HRColorPickerViewControllerDelegate> delegate;
...
@end
Code:
@implementation HRColorPickerViewController

@synthesize delegate;
...
@end
It seems i can't find any errors.
__________________
iDamaged Hands-On Preview. I like this game check it out.
nick.keroulis is offline   Reply With Quote
Old 02-08-2012, 09:51 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by nick.keroulis View Post
The error:
Code:
Existing ivar 'delegate' for unsafe_unretained property 'delegate' must be_unsafe_unretained
The code:
Code:
@interface HRColorPickerViewController : UIViewController
{
    id<HRColorPickerViewControllerDelegate> delegate;
    HRColorPickerView* colorPickerView;
    
    UIColor *_color;
    BOOL _fullColor;
    HCPCSaveStyle _saveStyle;
}

@property (assign, nonatomic) id<HRColorPickerViewControllerDelegate> delegate;
...
@end
Code:
@implementation HRColorPickerViewController

@synthesize delegate;
...
@end
It seems i can't find any errors.

You are tripping the peculiarities of ARC.

Properties that are declared as assign are not tracked by ARC. For properties, you use the settings strong, weak, and assign. These equate to __strong, __weak, and __unsafe_unretained for instance variables.

Here is a table of the way you declare properties, and the way you need to declare their instance variables to match

Property declaration............iVar declaration
strong...............................__strong
weak................................__weak
assign ..............................__unsafe_unretained


so, change the declaration of your delegate iVar to look like this:

Code:
    __unsafe_unretained id<HRColorPickerViewControllerDelegate> delegate;
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 02-08-2012 at 09:53 AM.
Duncan C is offline   Reply With Quote
Old 02-08-2012, 04:00 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default

Code:
@property (assign, nonatomic) __unsafe_unretained id<HRColorPickerViewControllerDelegate> delegate;
Tried that and it still doesn't work...
__________________
iDamaged Hands-On Preview. I like this game check it out.
nick.keroulis is offline   Reply With Quote
Old 02-08-2012, 04:33 PM   #4 (permalink)
Registered Member
 
ebender001's Avatar
 
Join Date: Mar 2010
Location: Missouri
Age: 57
Posts: 70
ebender001 is on a distinguished road
Default

Quote:
Originally Posted by nick.keroulis View Post
Code:
@property (assign, nonatomic) __unsafe_unretained id<HRColorPickerViewControllerDelegate> delegate;
Tried that and it still doesn't work...
That's not what he recommended. Not the property, the ivar.

Code:
@interface HRColorPickerViewController : UIViewController
{
    __unsafe_unretained id<HRColorPickerViewControllerDelegate> delegate;
    HRColorPickerView* colorPickerView;
    
    UIColor *_color;
    BOOL _fullColor;
    HCPCSaveStyle _saveStyle;
}
Why use an ivar, anyway?
Why not just use the recommended property declaration:
Code:
@property (nonatomic, weak) id <HRColorPickerViewControllerDelegate> delegate;
Ed
ebender001 is offline   Reply With Quote
Old 02-08-2012, 04:46 PM   #5 (permalink)
Registered Member
 
Join Date: Dec 2010
Posts: 498
nick.keroulis is on a distinguished road
Default

Quote:
Originally Posted by ebender001 View Post
That's not what he recommended. Not the property, the ivar.

Code:
@interface HRColorPickerViewController : UIViewController
{
    __unsafe_unretained id<HRColorPickerViewControllerDelegate> delegate;
    HRColorPickerView* colorPickerView;
    
    UIColor *_color;
    BOOL _fullColor;
    HCPCSaveStyle _saveStyle;
}
Why use an ivar, anyway?
Why not just use the recommended property declaration:
Code:
@property (nonatomic, weak) id <HRColorPickerViewControllerDelegate> delegate;
Ed
Dunno, not my code...
__________________
iDamaged Hands-On Preview. I like this game check it out.
nick.keroulis 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: 386
12 members and 374 guests
7twenty7, chiataytuday, fiftysixty, gmarro, iOS.Lover, KennyChong, kilobytedump, Leslie80, Matrix23, ryantcb, stanny, xerohuang
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,669
Threads: 94,121
Posts: 402,903
Top Poster: BrianSlick (7,990)
Welcome to our newest member, dedeys78
Powered by vBadvanced CMPS v3.1.0

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