2012-04-09 11 views
13

mam ten kod (urywek) od pliku .h:__unsafe_unretained dla delegata nie zbuduje

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

Plik .m wygląda następująco:

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

Spojrzałem na SO w podobnych przypadkach zauważyłem, że muszę umieścić "__unsafe_unretained" w nieruchomości ... Zrobiłem to (mam nadzieję, że było poprawne), ale nadal nie udało się go skompilować. Pełny komunikat o błędzie: Istniejący Ivar „delegata” nieruchomości „delegata” z atrybutem przypisać należy __unsafe_unretained

Screenshot

Co robię źle?

+0

Jak to jest dobre pytanie, przegłosowałem. – user3182143

Odpowiedz

33

jako komunikat o błędzie mówi ciebie, Ivar:

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

musi być zadeklarowana __unsafe_unretained:

__unsafe_unretained id<ILHuePickerViewDelegate> delegate; 

nie własność:

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

ponieważ Kwalifikatory własności ARC nie mają zastosowania do właściwości; odnoszą się tylko do zmiennych.

Ponieważ dyrektywa @synthesize tworzy Ivar dla Ciebie (z prawidłowym ARC eliminacjach), jednak można po prostu pominąć jego oświadczenie:

@interface ILHuePickerView : ILView 

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

// etc. 

Który jest, w rzeczywistości, teraz zalecanej procedura; patrz Defining Classes w TOCPL.

+0

Dziękuję ... Próbowałem komentować @property, ale to nie zadziałało, więc właśnie dodałem __unsafe_unretained do deklaracji ... wyczyściłem kompilację z powodu tego błędu ... dziękuję. – SpokaneDude

+0

Bardzo dobra odpowiedź. Przejrzałem to. – user3182143

2

Użyłem ILColorPicker w przeszłości i zdecydowanie nie jest to ARC. Ustaw -fno-objC-arc w ustawieniach flagi kompilatora dla klas ILColorPicker.

Powiązane problemy