doc*_*ang 3 objective-c instance-variables private-members categories ios
正如它在Apple的文档中所述:http://developer.apple.com/library/mac/#documentation/cocoa/Conceptual/ObjectiveC/Chapters/ocCategories.html#//apple_ref/doc/uid/TP30001163-CH20-SW1
Note that a category can’t declare additional instance variables for the class; it includes only methods. However, all instance variables within the scope of the class are also within the scope of the category. That includes all instance variables declared by the class, even ones declared @private.
但是,当我尝试访问UITextField"_selectionRange"的私有实例变量时,我得到符号未找到错误.以下是我的源代码和错误消息供您参考.我为那些阅读我最后一个例子"NSString"的人道歉.这不是一个很好的例子,因为NSString类中没有任何@private实例变量.
的NSString + Utilities.h
#import <Foundation/Foundation.h>
@interface UITextField (Editing)
- (void)deleteBkw;
@end
Run Code Online (Sandbox Code Playgroud)
的NSString + Utilities.m
@implementation UITextField (Editing)
- (void)deleteBkw {
NSLog(@"%d:%d", _selectionRange.location, _selectionRange.length);
}
@end
Run Code Online (Sandbox Code Playgroud)
错误:架构i386的未定义符号:"_ OBJC_IVAR _ $ _ UITextField._selectionRange",引自: - NSString + Utilities.o中的[UITextField(Editing)deleteBkw] ld:找不到架构i386的符号collect2:ld返回1退出状态
NSString没有变量名称长度:
NSString类有两个原始方法-length和characterAtIndex: - 为其接口中的所有其他方法提供基础.length方法返回字符串中Unicode字符的总数.characterAtIndex:通过索引访问字符串中的每个字符,索引值从0开始.
因此,您可以通过调用[self length]来访问length方法(而不是变量),并且只能通过这种方式访问.
| 归档时间: |
|
| 查看次数: |
2297 次 |
| 最近记录: |