多个分配在属性中返回意外值

时间:2014-08-31 14:19:05

标签: objective-c

当我跑步时,我对此感到很疯狂:

Chord *chordA = [[Chord alloc] initWithLetter: @"A"];
Chord *chordC = [[Chord alloc] initWithLetter: @"C"];
Chord *chordE = [[Chord alloc] initWithLetter: @"E"];
NSLog(@"Letter: %@", chordC.letter);

NSLog输出“Letter:E”,但我期待字母C!

这是我的Chord.m:

#import "Chord.h"

@implementation Chord
NSString *_letter;
- (id) initWithLetter:(NSString *) letter{
    self = [super init];
    if(self){
        _letter = letter;
    }
    return self;
}

- (NSString*) letter{
    return _letter;
}

@end

0 个答案:

没有答案