forked from 343max/NSObject-Expectation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSObject+Expectation.m
63 lines (47 loc) · 1.32 KB
/
NSObject+Expectation.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
//
// NSObject+SafeObject.m
//
// Created by Max Winde on 15.05.13.
// Copyright (c) 2013 Max Winde. All rights reserved.
//
#import "NSObject+Expectation.h"
@implementation NSObject (Expectation)
- (id)nilUnlessKindOfClass:(Class)aClass;
{
return ([self isKindOfClass:aClass] ? self : nil);
}
- (id)nilUnlessRespondsToSelector:(SEL)selector;
{
return ([self respondsToSelector:selector] ? self : nil);
}
- (id)nilUnlessConformsToProtocol:(Protocol *)aProtocol;
{
return ([self conformsToProtocol:aProtocol] ? self : nil);
}
#pragma mark - Default Values
- (id)unless:(NSObject *)object isKindOfClass:(Class)aClass;
{
return ([object nilUnlessKindOfClass:aClass] ? object : self);
}
- (id)unless:(NSObject *)object respondsToSelector:(SEL)selector;
{
return ([object nilUnlessRespondsToSelector:selector] ? object : self);
}
- (id)unless:(NSObject *)object conformsToProtocol:(Protocol *)aProtocol;
{
return ([object nilUnlessConformsToProtocol:aProtocol] ? object : self);
}
#pragma mark - Deprecated
- (id)ifIsKindOfClass:(Class)aClass;
{
return [self nilUnlessKindOfClass:aClass];
}
- (id)IfRespondsToSelector:(SEL)selector;
{
return [self nilUnlessRespondsToSelector:selector];
}
- (id)IfConformsToProtocol:(Protocol *)aProtocol;
{
return [self nilUnlessConformsToProtocol:aProtocol];
}
@end