I make a few assumptions here, so if I am in the database let me know.
1) You have a list of objects that will be connected to outlets, and a list of these points. (e.g., file owner is a class MyViewControllerand has exits view, label, buttonetc. have UITableViewthe outputs delegateand dataSourceetc.).
2) , 1. , - UIControl -, viewWithTag:
, , , , ( )
for each referencingObject in nibObjects
{
for each outletName in referencingObject.outletNames
{
assertExistence()
assertProperties()
}
}
. iOS nibs , , , . nib, , , .
, SenTestCase:
ViewController *vc = [[ViewController alloc] init];
UINib *nib1 = [UINib nibWithNibName:@"ViewController1" bundle:nil];
NSArray *topLevelObjects = [nib1 instantiateWithOwner:vc options:nil];
ReferencingObject *filesOwnerReferencingObject = [[ReferencingObject alloc] init];
filesOwnerReferencingObject.object = vc;
ReferencedOutlet *viewOutlet = [[ReferencedOutlet alloc] init];
viewOutlet.name = @"view";
viewOutlet.propertyAssertionBlock = ^(id object) {
UIView *theView = (UIView *)object;
STAssertEquals(1.0f, theView.alpha, @"shouldn't have any transparency");
};
ReferencedOutlet *labelOutlet = [[ReferencedOutlet alloc] init];
labelOutlet.name = @"label";
labelOutlet.propertyAssertionBlock = ^(id object) {
UILabel *theLabel = (UILabel *)object;
NSString *expectedLabelText = @"ViewController1.xib";
STAssertTrue([expectedLabelText isEqualToString:theLabel.text], nil);
};
filesOwnerReferencingObject.outlets = @[ viewOutlet, labelOutlet ];
NSArray *referencingObjects = @[ filesOwnerReferencingObject ];
for (ReferencingObject *referencingObject in referencingObjects)
{
for (ReferencedOutlet *outlet in referencingObject.outlets)
{
id object = [filesOwnerReferencingObject.object valueForKey:outlet.name];
STAssertNotNil(object, nil);
outlet.propertyAssertionBlock(object);
}
}
/ ReferencingObject ReferencedOutlet.
@interface ReferencingObject : NSObject
@property (nonatomic, strong) id object;
@property (nonatomic, strong) NSArray *outlets;
@end
@implementation ReferencingObject
@end
typedef void (^ReferencedOutletPropertyAssertionBlock)(id);
@interface ReferencedOutlet : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) ReferencedOutletPropertyAssertionBlock propertyAssertionBlock;
@end
@implementation ReferencedOutlet
@end
, - . , .