2012-04-09 9 views
13

tengo este código (fragmento) de un archivo .h:__unsafe_unretained por un delegado no construirá

#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; 

El archivo .m se ve así:

#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]; 

Miré yo SO para casos similares, y vi que necesitaba poner "__unsafe_unretained" en la propiedad ... Hice eso (espero que sea correcto), pero aún falla en la compilación. El mensaje de error completo es: Existente Ivar 'delegado' para la propiedad 'delegado' con el atributo de asignación debe ser __unsafe_unretained

Screenshot

¿Qué estoy haciendo mal?

+0

Como es una buena pregunta que voté. – user3182143

Respuesta

33

Como el mensaje de error que le está diciendo, el Ivar:

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

necesidades a ser declarada __unsafe_unretained:

__unsafe_unretained id<ILHuePickerViewDelegate> delegate; 

no la propiedad:

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

porque el Los calificadores de propiedad de ARC no se aplican a las propiedades; solo se aplican a las variables.

Desde el @synthesize Directiva crea la Ivar para usted (con la correcta clasificación ARC), sin embargo, puede saltarse su declaración:

@interface ILHuePickerView : ILView 

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

// etc. 

¿Qué es, de hecho, ahora el recomienda procedimiento; ver Defining Classes en TOCPL.

+0

Gracias ... Intenté comentar @property, pero eso no funcionó, así que simplemente agregué __unsafe_unretenido a la declaración ... limpié la compilación de ese error ... gracias. – SpokaneDude

+0

Muy buena respuesta. Yo lo voté. – user3182143

2

He usado ILColorPicker en el pasado, y definitivamente no está listo para ARC. Establezca -fno-objC-arc en la configuración del indicador del compilador para las clases ILColorPicker.

Cuestiones relacionadas