注意:有发布超过Objective C的一个类似的问题在这里,但我想实现它迅速.
我有一个像swift一样声明的类:
import UIKit
class EachDayCell : UITableViewCell
{
@IBOutlet var dateDisplayLabel : UITextField
@IBOutlet var nameDisplayLabel : UITextField
@IBAction func goToPendingItems(sender : AnyObject) {
}
@IBAction func showDateSelectionPicker(sender : AnyObject) {
}
init(style: UITableViewCellStyle, reuseIdentifier: String!)
{
super.init(style: style, reuseIdentifier: reuseIdentifier)
}
}
Run Code Online (Sandbox Code Playgroud)
现在我想在swift中获取一个数组:dateDisplayLabel,nameDisplayLabel.
我怎样才能做到这一点?
我试图列出Objective-C类的所有属性,如Objective-C 2.0运行时编程指南中所述:
id LenderClass = objc_getClass("UIView");
unsigned int outCount, i;
objc_property_t *properties = class_copyPropertyList(LenderClass, &outCount);
for (i = 0; i < outCount; i++) {
objc_property_t property = properties[i];
fprintf(stdout, "%s %s\n", property_getName(property), property_getAttributes(property));
}
Run Code Online (Sandbox Code Playgroud)
但是这只列出了三个属性:
userInteractionEnabled Tc,GisUserInteractionEnabled
layer T@"CALayer",R,&,V_layer
tag Ti,V_tag
Run Code Online (Sandbox Code Playgroud)
查看UIView.h的头文件,这些是在类中直接声明的三个属性.其他UIView属性通过类别添加.
如何获取课程的所有属性,包括来自类别的属性?
我尝试使用iPhone模拟器(iPhone SDK 2.2.1),顺便说一句.(如果这很重要).
我正在我的项目上设置单元测试,以确保所有UIViewController IBOutlets都连接到它们各自的Xib对象(即,在viewDidLoad之后不为零)。我正在考虑将协议与这些UIViewControllers一起使用所需的函数“ getAllOutletNames”,像这样:
-(NSArray*)getAllOutletNames
{
return @[ @"outletproperty1", @"outletProperty2", ...];
}
Run Code Online (Sandbox Code Playgroud)
...然后使用[viewController valueForKey:outletName]确保所有这些都不为零。问题在于它有点笨拙。必须为添加到xib的每个插座更新“ getAllOutletNames”,这很容易被忽略。我希望以编程方式进行此操作,以便可以自动检测并迭代所有IBOutlet属性。
我在NSHipster的这篇文章(“属性支持的属性”的cmd + f)中读到了一个属性应用于IBOutlets(或者我不太理解的“属性支持的属性”)。
看来我可以使用此答案的一部分获取类中所有属性的列表,而我可以使用此答案的一部分获取其属性。但是,使用以下代码从IBOutlet属性与非IBOutlet属性输出属性,我没有发现任何区别:
const char * type = property_getAttributes(class_getProperty([self class], [outletName UTF8String]));
NSString * typeString = [NSString stringWithUTF8String:type];
NSArray * attributes = [typeString componentsSeparatedByString:@","];
NSLog(@"%@",attributes);
Run Code Online (Sandbox Code Playgroud)
IB插座
(
"T@\"UILabel\"",
"&",
N,
"V_titleLabel"
)
Run Code Online (Sandbox Code Playgroud)
非IB插座
(
"T@\"UIView\"",
"&",
N,
"V_programmaticallySetupView"
)
Run Code Online (Sandbox Code Playgroud)
是否有任何方法可以访问NSHipster文章中提到的“属性支持的属性”,或者以其他方式确定某个属性是否以编程方式是IBOutlet,还是我在这里吠叫了错误的树?
我有一个NSArray对象,这些对象有10个属性.我想对这些对象进行文本搜索.
我知道如何一次搜索1个属性,但有一种简单的方法可以一次搜索所有属性吗?
以下是我的对象具有的属性列表:
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSString * phone;
@property (nonatomic, retain) NSString * secondaryPhone;
@property (nonatomic, retain) NSString * address;
@property (nonatomic, retain) NSString * email;
@property (nonatomic, retain) NSString * url;
@property (nonatomic, retain) NSString * category;
@property (nonatomic, retain) NSString * specialty;
@property (nonatomic, retain) NSString * notes;
@property (nonatomic, retain) NSString * guid;
Run Code Online (Sandbox Code Playgroud)
如果我搜索"医生",我希望看到所有结果,其中一个或多个这些属性中有"医生"一词.例如,如果1个对象的类别为"doctor",而另一个对象的电子邮件地址为"smith@doctorsamerica.com",则它们都应显示在结果中.