G. Ramistella
G. Ramistella

Reputation: 1407

Property not found although it should be

This is a weird bug.

I have this in the header:

#import "UIKit/UIKit.h"

@interface ProxyProfileObject : NSObject <NSCoding> {
    NSString *profileName;
    NSString *ipAddress;
    NSString *port;
}

-(void) setProfileName:(NSString *)string;
-(NSString*) getProfileName;
-(void) setIP:(NSString *)string;
-(NSString*) getIP;
-(void) setPort:(NSString *)string;
-(NSString*) getPort;

@end

And this in the implementation:

#import "ProxyProfileObject.h"

@interface ProxyProfileObject()

@end

@implementation ProxyProfileObject

-(void) setProfileName:(NSString *)string{
    profileName = string;
}

-(NSString*) getProfileName{
    return profileName;
}

-(void) setIP:(NSString *)string{
    ipAddress = string;
}

-(NSString*) getIP{
    return ipAddress;
}

-(void) setPort:(NSString *)string{
    port = string;
}

-(NSString*) getPort{
    return port;
}

// Encoding stuff
- (id)initWithCoder:(NSCoder *)decoder {
    if (self = [super init]) {
        self.profileName = [decoder decodeObjectForKey:@"profileName"];
        self.port = [decoder decodeObjectForKey:@"port"];
        self.ipAddress = [decoder decodeObjectForKey:@"ip"];

    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeObject:profileName forKey:@"profileName"];
    [encoder encodeObject:ipAddress forKey:@"ip"];
    [encoder encodeObject:port forKey:@"port"];

}

@end

I am not sure why it does this. It shouldn't do it as ipAddress is the same thing as port or profile name.

Those are the two files. You can now see by yourself how ipAddress doesn't work.

Upvotes: 0

Views: 40

Answers (2)

vadian
vadian

Reputation: 285064

You are declaring instance variables, not properties. Just put the @property directive in front of the lines.

@interface ProxyProfileObject : NSObject <NSCoding> {}
@property NSString *profileName;
@property NSString *ipAddress;
@property NSString *port;

Edit: Don't write explicit getters and setters. Use the (error-free) synthesized accessors provided by the @property declaration.

Upvotes: 1

Nikolai Ruhe
Nikolai Ruhe

Reputation: 81868

  • In your header NSString *ipAddress declares an ivar.
  • I the implementation self.ipAddress refers to a property.
  • You declared no such property. Hence the error.

After the edit your problem becomes apparent:

You do not declare a method -(void)setIpAddress:(NSString *)address;

That's what would make Xcode allow you to use property syntax (dot notation) for the setter—even though it's not an actual property.

Upvotes: 1

Related Questions