OLD | NEW |
1 //------------------------------------------------------------------------------
--------- | 1 /* |
2 // $Id$ | 2 * Copyright (c) 2009-2015 Erik Doernenburg and contributors |
3 // Copyright (c) 2009 by Mulle Kybernetik. See License file for details. | 3 * |
4 //------------------------------------------------------------------------------
--------- | 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 5 * not use these files except in compliance with the License. You may obtain |
| 6 * a copy of the License at |
| 7 * |
| 8 * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 * |
| 10 * Unless required by applicable law or agreed to in writing, software |
| 11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 * License for the specific language governing permissions and limitations |
| 14 * under the License. |
| 15 */ |
5 | 16 |
6 #import "NSMethodSignature+OCMAdditions.h" | 17 #import "NSMethodSignature+OCMAdditions.h" |
7 #import "OCMReturnValueProvider.h" | 18 #import "OCMReturnValueProvider.h" |
| 19 #import "OCMFunctions.h" |
8 | 20 |
9 | 21 |
10 @implementation OCMReturnValueProvider | 22 @implementation OCMReturnValueProvider |
11 | 23 |
12 - (id)initWithValue:(id)aValue | 24 - (instancetype)initWithValue:(id)aValue |
13 { | 25 { |
14 » self = [super init]; | 26 if ((self = [super init])) |
15 » returnValue = [aValue retain]; | 27 { |
| 28 returnValue = [aValue retain]; |
| 29 } |
| 30 » |
16 return self; | 31 return self; |
17 } | 32 } |
18 | 33 |
19 - (void)dealloc | 34 - (void)dealloc |
20 { | 35 { |
21 [returnValue release]; | 36 [returnValue release]; |
22 [super dealloc]; | 37 [super dealloc]; |
23 } | 38 } |
24 | 39 |
25 - (void)handleInvocation:(NSInvocation *)anInvocation | 40 - (void)handleInvocation:(NSInvocation *)anInvocation |
26 { | 41 { |
27 » const char *returnType = [[anInvocation methodSignature] methodReturnTyp
eWithoutQualifiers]; | 42 if(!OCMIsObjectType([[anInvocation methodSignature] methodReturnType])) |
28 » if(strcmp(returnType, @encode(id)) != 0) | 43 { |
29 » » @throw [NSException exceptionWithName:NSInvalidArgumentException
reason:@"Expected invocation with object return type. Did you mean to use andRe
turnValue: instead?" userInfo:nil]; | 44 @throw [NSException exceptionWithName:NSInvalidArgumentException reason:
@"Expected invocation with object return type. Did you mean to use andReturnValu
e: instead?" userInfo:nil]; |
30 » [anInvocation setReturnValue:&returnValue];» | 45 } |
| 46 NSString *sel = NSStringFromSelector([anInvocation selector]); |
| 47 if([sel hasPrefix:@"alloc"] || [sel hasPrefix:@"new"] || [sel hasPrefix:@"co
py"] || [sel hasPrefix:@"mutableCopy"]) |
| 48 { |
| 49 // methods that "create" an object return it with an extra retain count |
| 50 [returnValue retain]; |
| 51 } |
| 52 » [anInvocation setReturnValue:&returnValue]; |
31 } | 53 } |
32 | 54 |
33 @end | 55 @end |
OLD | NEW |