-
-
Save nerdo/e0cdc89aad27fbb43d98b21e8ef80c65 to your computer and use it in GitHub Desktop.
Revisions
-
cprovatas revised this gist
Jan 30, 2018 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,6 +7,7 @@ // import Foundation import UIKit // swiftlint:disable identifier_name func Selector(_ block: @escaping () -> Void) -> Selector { let selector = NSSelectorFromString("\(CACurrentMediaTime())") -
cprovatas revised this gist
Dec 7, 2017 . 3 changed files with 31 additions and 7 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,7 +11,8 @@ @end typedef void (^OBJCBlock)(id PPSelector); typedef void (^OBJCBlockWithSender)(id PPSelector, id sender); void class_addMethodWithBlock(Class class, SEL newSelector, OBJCBlock block); void class_addMethodWithBlockAndSender(Class class, SEL newSelector, OBJCBlockWithSender block); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,9 +12,15 @@ @implementation BlockBasedSelector @end void class_addMethodWithBlock(Class class, SEL newSelector, OBJCBlock block) { IMP newImplementation = imp_implementationWithBlock(block); Method method = class_getInstanceMethod(class, newSelector); class_addMethod(class, newSelector, newImplementation, method_getTypeEncoding(method)); } void class_addMethodWithBlockAndSender(Class class, SEL newSelector, OBJCBlockWithSender block) { IMP newImplementation = imp_implementationWithBlock(block); Method method = class_getInstanceMethod(class, newSelector); class_addMethod(class, newSelector, newImplementation, method_getTypeEncoding(method)); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,11 +1,28 @@ // // BlockBasedSelector.swift // Parking // // Created by Charlton Provatas on 11/9/17. // Copyright © 2017 Passport Parking. All rights reserved. // import Foundation // swiftlint:disable identifier_name func Selector(_ block: @escaping () -> Void) -> Selector { let selector = NSSelectorFromString("\(CACurrentMediaTime())") class_addMethodWithBlock(PPSelector.self, selector) { _ in block() } return selector } /// used w/ callback if you need to get sender argument func Selector(_ block: @escaping (Any?) -> Void) -> Selector { let selector = NSSelectorFromString("\(CACurrentMediaTime())") class_addMethodWithBlockAndSender(PPSelector.self, selector) { (_, sender) in block(sender) } return selector } // swiftlint:disable identifier_name let Selector = PPSelector.shared @objc class PPSelector: NSObject { static let shared = PPSelector() } -
cprovatas revised this gist
Nov 2, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // // BlockBasedSelector.h // // Created by Charlton Provatas on 11/2/17. // Copyright © 2017 CharltonProvatas. All rights reserved. -
cprovatas revised this gist
Nov 2, 2017 . No changes.There are no files selected for viewing
-
cprovatas revised this gist
Nov 2, 2017 . No changes.There are no files selected for viewing
-
cprovatas revised this gist
Nov 2, 2017 . 3 changed files with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -14,3 +14,4 @@ typedef void (^OBJCBlock)(id foo); void class_addMethodWithBlock(Class class, SEL newSelector, OBJCBlock block); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -17,3 +17,4 @@ void class_addMethodWithBlock(Class class, SEL newSelector, OBJCBlock block) Method method = class_getInstanceMethod(class, newSelector); class_addMethod(class, newSelector, newImplementation, method_getTypeEncoding(method)); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,3 +8,4 @@ let Selector = _Selector.shared @objc class _Selector: NSObject { static let shared = _Selector() } -
cprovatas created this gist
Nov 2, 2017 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ // // RunTimeWrapper.h // // Created by Charlton Provatas on 11/2/17. // Copyright © 2017 CharltonProvatas. All rights reserved. // #import <Foundation/Foundation.h> @interface BlockBasedSelector : NSObject @end typedef void (^OBJCBlock)(id foo); void class_addMethodWithBlock(Class class, SEL newSelector, OBJCBlock block); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ // // BlockBasedSelector.m // // Created by Charlton Provatas on 11/2/17. // Copyright © 2017 CharltonProvatas. All rights reserved. // #import "BlockBasedSelector.h" #import <objc/runtime.h> @implementation BlockBasedSelector @end void class_addMethodWithBlock(Class class, SEL newSelector, OBJCBlock block) { IMP newImplementation = imp_implementationWithBlock(block); Method method = class_getInstanceMethod(class, newSelector); class_addMethod(class, newSelector, newImplementation, method_getTypeEncoding(method)); } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ func Selector(_ block: @escaping () -> Void) -> Selector { let selector = NSSelectorFromString("\(CACurrentMediaTime())") class_addMethodWithBlock(_Selector.self, selector) { (_) in block() } return selector } let Selector = _Selector.shared @objc class _Selector: NSObject { static let shared = _Selector() }