Compiler errors related to Property attributes


#1

In Chapter 19 (under “Creating the Asset class”) and in Chapter 20 (“Preventing Memory Leaks”) we are introduced to modifiers on Property declarations.

However, these properties don’t work for me. I’m thinking that perhaps something has changed in a later version of Objective-C, SDKs or XCode, but I’m unable to find this information in Apple’s documentation or elsewhere, so I’m thinking that maybe I’m just doing it wrong? I am using XCode 4.1 and everything else that came with it.

Asset.h

#import <Foundation/Foundation.h>
@class Employee;

@interface Asset : NSObject
{
    NSString *label;
    __weak Employee *holder;
    unsigned int resaleValue;
}

@property (strong) NSString *label; // '(strong)' causes a compiler error
@property (weak) Employee *holder; // '(weak)' causes a compiler error
@property unsigned int resaleValue;

@end

Asset.m

#import "Asset.h"
#import "Employee.h"

@implementation Asset

@synthesize label, resaleValue, holder;

- (NSString *)description
{
    if ([self holder]) {
        return [NSString stringWithFormat:@"<%@: $%d, assigned to %@>",
                [self label], [self resaleValue], [self holder]];
    } else {
    return [NSString stringWithFormat:@"<%@: $%d unassigned>",
            [self label], [self resaleValue]];
    }
}

- (void)dealloc
{
    NSLog(@"Deallocating %@", self);
}

@end

When I compile, I get these errors:

In file included from /Users/<MyUser>/Code/BMITime/BMITime/Asset.m:9:
/Users/Fredheim/Code/BMITime/BMITime/Asset.h:19:12: error: unknown property attribute 'strong' [1]
 @property (strong) NSString *label;
/Users/<MyUser>/Code/BMITime/BMITime/Asset.h:20:12: error: unknown property attribute 'weak' [1]
 @property (weak) Employee *holder;

If I remove (strong) and (weak), then everything compiles.

Also, the auto-complete feature in XCode does not suggest (strong) and (weak) as I’m typing it (although it does suggest a bunch of other attributes, but none of them seem to be the same as “strong” and “weak”), so I think something’s wrong with the code, or that something has changed, but I’m not sure how to resolve this. Any help here would be greatly appreciated!


#2

Ah! I seems like the Mac OS X App Store didn’t manage to update XCode and all the libraries to the latest versions, which might explain this (and some other problems I was experiencing with @autoreleasepool etc.). I’m trying to update manually to the latest versions now, and I’ll let people know if this fixed the issue later. Cheers!

Edit:

Indeed! Now it’s working. The App Store had downloaded and installed the installer, but it hadn’t actually updated the files to 4.2. After running the installer manually, everything got updated to the correct, latest version. And now everything is working as it should. My apologies for not noticing this before posting.


#3

I also had expected, that the Xcode Update is done automatically - it’s an unexpected behavior of an app store :frowning: I hope they will fix it.