3 * Copyright (c) 2013, Blue Static <http://www.bluestatic.org>
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
17 #import "ThreadSafeDeleage.h"
19 @implementation ThreadSafeDeleage
{
26 @synthesize object
= _object
;
28 - (id)initWithObject
:(NSObject
*)object
29 protocol
:(Protocol
*)protocol
30 thread
:(NSThread
*)thread
{
31 return [self initWithObject
:object
34 modes
:@
[ NSRunLoopCommonModes
]];
37 - (id)initWithObject
:(NSObject
*)object
38 protocol
:(Protocol
*)protocol
39 thread
:(NSThread
*)thread
40 modes
:(NSArray
*)runLoopModes
{
41 if ((self = [super init
])) {
45 _modes
= [runLoopModes retain
];
55 - (BOOL)conformsToProtocol
:(Protocol
*)protocol
{
56 return [_protocol isEqual
:protocol
];
59 - (NSMethodSignature
*)methodSignatureForSelector
:(SEL)aSelector
{
61 return [_protocol methodSignatureForSelector
:aSelector
];
62 return [_object methodSignatureForSelector
:aSelector
];
65 - (BOOL)respondsToSelector
:(SEL)aSelector
{
67 return [_protocol respondsToSelector
:aSelector
];
68 return [_object respondsToSelector
:aSelector
];
71 - (void)forwardInvocation
:(NSInvocation
*)invocation
{
72 if ([_object respondsToSelector
:[invocation selector
]]) {
73 [self performSelector
:@selector(dispatchInvocation
:)
81 - (void)dispatchInvocation
:(NSInvocation
*)invocation
{
82 [invocation invokeWithTarget
:_object
];