lib/NSObject+DDExtensions.m
author Dave Dribin <dave@dribin.org>
Thu Jan 21 23:03:04 2010 -0600 (2010-01-21)
changeset 167 de4178bcaacf
parent 158 14076243f425
permissions -rw-r--r--
Add NSDictionary+DDExtensions
dave@39
     1
/*
dave@158
     2
 * Copyright (c) 2007-2009 Dave Dribin
dave@39
     3
 * 
dave@39
     4
 * Permission is hereby granted, free of charge, to any person
dave@39
     5
 * obtaining a copy of this software and associated documentation
dave@39
     6
 * files (the "Software"), to deal in the Software without
dave@39
     7
 * restriction, including without limitation the rights to use, copy,
dave@39
     8
 * modify, merge, publish, distribute, sublicense, and/or sell copies
dave@39
     9
 * of the Software, and to permit persons to whom the Software is
dave@39
    10
 * furnished to do so, subject to the following conditions:
dave@39
    11
 * 
dave@39
    12
 * The above copyright notice and this permission notice shall be
dave@39
    13
 * included in all copies or substantial portions of the Software.
dave@39
    14
 *
dave@39
    15
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
dave@39
    16
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
dave@39
    17
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
dave@39
    18
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
dave@39
    19
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
dave@39
    20
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
dave@39
    21
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
dave@39
    22
 * SOFTWARE.
dave@39
    23
 */
dave@38
    24
dave@38
    25
#import "NSObject+DDExtensions.h"
dave@38
    26
#import "DDInvocationGrabber.h"
dave@38
    27
dave@38
    28
@implementation NSObject (DDExtensions)
dave@38
    29
dave@38
    30
- (id)dd_invokeOnMainThread;
dave@38
    31
{
dave@47
    32
    return [self dd_invokeOnMainThreadAndWaitUntilDone:NO];
dave@38
    33
}
dave@38
    34
dave@38
    35
- (id)dd_invokeOnMainThreadAndWaitUntilDone:(BOOL)waitUntilDone;
dave@38
    36
{
dave@38
    37
    DDInvocationGrabber * grabber = [DDInvocationGrabber invocationGrabber];
dave@38
    38
    [grabber setForwardInvokesOnMainThread:YES];
dave@41
    39
    [grabber setWaitUntilDone:waitUntilDone];
dave@38
    40
    return [grabber prepareWithInvocationTarget:self];
dave@38
    41
}
dave@38
    42
dave@160
    43
#if (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
dave@160
    44
dave@160
    45
- (id)dd_invokeOnThread:(NSThread *)thread;
dave@160
    46
{
dave@160
    47
    return [self dd_invokeOnThread:thread waitUntilDone:NO];
dave@160
    48
}
dave@160
    49
dave@160
    50
- (id)dd_invokeOnThread:(NSThread *)thread waitUntilDone:(BOOL)waitUntilDone;
dave@160
    51
{
dave@160
    52
    DDInvocationGrabber * grabber = [DDInvocationGrabber invocationGrabber];
dave@160
    53
    [grabber setInvokesOnThread:thread];
dave@160
    54
    [grabber setWaitUntilDone:waitUntilDone];
dave@160
    55
    return [grabber prepareWithInvocationTarget:self];
dave@160
    56
}
dave@160
    57
dave@160
    58
#endif
dave@160
    59
dave@38
    60
@end