2012-04-09 10 views
13

ho questo codice (snippet) da un file .h:__unsafe_unretained per un delegato non costruire

#import <UIKit/UIKit.h> 
#import "ILView.h" 

/** 
* Controls the orientation of the picker 
*/ 
typedef enum { 
    ILHuePickerViewOrientationHorizontal  = 0, 
    ILHuePickerViewOrientationVertical  = 1 
} ILHuePickerViewOrientation; 

@class ILHuePickerView; 

/** 
* Hue picker delegate 
*/ 
@protocol ILHuePickerViewDelegate 

/** 
* Called when the user picks a new hue 
* 
* @param hue 0..1 The hue the user picked 
* @param picker The picker used 
*/ 
-(void)huePicked:(float)hue picker:(ILHuePickerView *)picker; 

@end 

/** 
* Displays a gradient allowing the user to select a hue 
*/ 
@interface ILHuePickerView : ILView { 
    id<ILHuePickerViewDelegate> delegate; 
    float hue; 
    ILHuePickerViewOrientation pickerOrientation; 
} 

/** 
* Delegate 
*/ 
//@property (assign, nonatomic) IBOutlet id<ILHuePickerViewDelegate> delegate; 
@property (assign, nonatomic) IBOutlet __unsafe_unretained id<ILHuePickerViewDelegate> delegate; 

/** 
* The current hue 
*/ 
@property (assign, nonatomic) float hue; 

Il file .m si presenta così:

#import "ILHuePickerView.h" 
#import "UIColor+GetHSB.h" 

@interface ILHuePickerView(Private) 

-(void)handleTouches:(NSSet *)touches withEvent:(UIEvent *)event; 

@end 

@implementation ILHuePickerView 

@synthesize color, delegate, hue, pickerOrientation; 

#pragma mark - Setup 

-(void)setup 
{ 
    [super setup]; 

ho guardato su SO per casi simili, e ho visto che avevo bisogno di mettere "__unsafe_unretained" nella proprietà ... L'ho fatto (spero corretto), ma non riesce ancora nella build. Il messaggio di errore completo è: esistente ivar 'delegato' per la proprietà 'delegato' con l'attributo di assegnazione deve essere __unsafe_unretained

Screenshot

Che cosa sto facendo di sbagliato?

+0

Come è una buona domanda, ho votato. – user3182143

risposta

33

Come il messaggio di errore sta dicendo, il ivar:

@interface ILHuePickerView : ILView { 
    id<ILHuePickerViewDelegate> delegate; // <-- This is the ivar 

deve essere dichiarato __unsafe_unretained:

__unsafe_unretained id<ILHuePickerViewDelegate> delegate; 

non la proprietà:

@property (assign, nonatomic) IBOutlet id<ILHuePickerViewDelegate> delegate; 

perché il I qualificatori di proprietà ARC non si applicano alle proprietà; si applicano solo alle variabili.

Poiché la direttiva @synthesize crea l'Ivar per voi (con il qualificatore ARC corretto), tuttavia, è possibile saltare la sua dichiarazione:

@interface ILHuePickerView : ILView 

/** 
* Delegate 
*/ 
@property (assign, nonatomic) IBOutlet id<ILHuePickerViewDelegate> delegate; 

// etc. 

Che è, di fatto, ora il raccomandato procedura; vedi Defining Classes in TOCPL.

+0

Grazie ... Ho provato a commentare @property, ma non ha funzionato, quindi ho solo aggiunto __unsafe_unretained alla dichiarazione ... ripulito la build per quell'errore ... grazie. – SpokaneDude

+0

Ottima risposta. L'ho svalutato. – user3182143

2

Ho utilizzato ILColorPicker in passato e non è sicuramente ARC pronto. Impostare -fno-objC-arc nelle impostazioni del flag del compilatore per le classi ILColorPicker.