[swift-users] NSInvocation equivalent

Bob Miller robert.miller at apple.com
Wed Oct 5 15:50:24 CDT 2016

Hello Swift Users,

	This is a Swift3 newbie question that I’ve not found a solution to. Has there been any consensus reached on an equivalent approach to the AppKit class NSInvocation ? Here’s a simple objC example.

    NSInteger totalCount = -1;
    if ([self.representedObject respondsToSelector:@selector(totalCount)])
       SEL selector = @selector(totalCount);
        NSMethodSignature  *aSignature = [[self.representedObject class] instanceMethodSignatureForSelector:selector];

        if (aSignature != nil)
            NSInvocation  *anInvocation = [NSInvocation invocationWithMethodSignature:aSignature];
            [anInvocation setSelector:selector];
            [anInvocation setTarget:self.representedObject];
            [anInvocation invoke];
            [anInvocation getReturnValue:&totalCount];
    return totalCount;

Thanks and regards,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20161005/00d47251/attachment.html>

More information about the swift-users mailing list