新手到目標C ...目標C - 從公共職能訪問私有變種
注意:這是一個概念性的問題,因爲我想翻譯「公共和私人」從我瞭解的其他語言。
如何通過「public」方法訪問「stringB」ivar?
myClass.h
@interface myClass : UIViewController {
}
@property (nonatomic, retain) NSString *stringA;
@property (nonatomic, retain) NSString *stringB;
- (void)dealWithStringA;
+ (void)dealWithStringB;
myClass.m
#import "myClass.h"
@interface myClass() {
}
@end
@implementation myClass
// My "private" function
- (void)dealWithStringA
{
return _stringA;
}
// My "public" function
+ (void)dealWithStringB
{
// Errors with: Instance variable "stringB" accessed in class method
return _stringB;
}
感謝Grzegorz,你清除了我的想法....只是試圖根據我從其他語言瞭解的情況掌握一些信息。 – bob