Semantic Issue of 'weak' property allowed in GC/ARC mode


#1

Hello,
When I try to run the code, it says on line 14 (@implementation BNRQuizViewController) “@synthesize of ‘weak’ property is only allowed in ARC or GC mode”

Here is a bulk of code where the problem could potentially lay:

[code]#import “BNRQuizViewController.h”

@interface BNRQuizViewController ()

@property (nonatomic) int currentQuestionIndex;

@property (nonatomic, copy) NSArray *questions;
@property (nonatomic, copy) NSArray *answers;

@property (nonatomic, weak) IBOutlet UILabel *questionLabel;
@property (nonatomic, weak) IBOutlet UILabel *answerLabel;
@end

@implementation BNRQuizViewController

  • (instancetype)initWithNibName:(NSString *)nibNameOrNil
    bundle:(NSBundle *)nibBundleOrNil

{
// Call the init method implemented by the superclass
self = [super initWithNibName: nibNameOrNil bundle:nibBundleOrNil];

if (self) {
    //Create two arrays filled with questions and answers
    // and make pointers point to them
    
    self.questions = @[@"What is my name?",
                       @"What color is the Sun?",
                       @"What is the capital of Massaschussetts?"];
    self.answers = @[@"I forgot!",
                     @"Yellow",
                     @"Boss-ton",];
}
// Return the address of the new object
return self;

}

[/code]

Thanks!
You guys rock.


#2

Do you have ARC enabled?

To double check:

[ul]- Click on your Quiz in the organizer on the left

  • Select your Quiz target, in the next column over
  • Choose “Build Settings” column at the top
  • Scroll down to the Apple LLVM 6.0 -Language - Objective-C section
  • Make sure that “Objective-C Automatic Reference Counting” is set to Yes[/ul]

{modified from a Stackoverflow answer here: http://stackoverflow.com/questions/7837024/how-to-disable-xcode4-2-automatic-reference-counting