Skip to content

Instantly share code, notes, and snippets.

@dblandin
Created February 10, 2014 21:26
Show Gist options
  • Save dblandin/8924484 to your computer and use it in GitHub Desktop.
Save dblandin/8924484 to your computer and use it in GitHub Desktop.
RubyMotion Throttler *currently not working*
class Alerter
def alert(message)
NSLog("#{message}!")
end
end
class Throttler
attr_reader :object, :seconds
def initialize(object, seconds)
@object = object
@seconds = seconds
end
def call(selector, *args)
unless blocked[selector]
blocked[selector] = true
method_signature = object.methodSignatureForSelector(selector)
NSInvocation.invocationWithMethodSignature(method_signature).tap do |invocation|
invocation.setSelector(selector)
invocation.setTarget(object)
args.each_with_index do |object, index|
pointer = Pointer.new('@')
pointer[0] = argument
invocation.setArgument(pointer, atIndex: index)
end
invocation.invoke
end
performSelector('unblock:', withObject: selector, afterDelay: seconds)
end
end
private
def unblock(selector)
blocked.delete(selector)
end
def blocked
@blocked ||= {}
end
end
Build ./build/iPhoneSimulator-7.0-Development
Compile ./app/throttler.rb
Link ./build/iPhoneSimulator-7.0-Development/debounce.app/debounce
Create ./build/iPhoneSimulator-7.0-Development/debounce.app/Info.plist
Create ./build/iPhoneSimulator-7.0-Development/debounce.dSYM
Simulate ./build/iPhoneSimulator-7.0-Development/debounce.app
2014-02-10 15:22:51.496 debounce[62164:80b] Cannot find executable for CFBundle 0x8b674e0 </Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator7.0.
sdk/System/Library/AccessibilityBundles/CertUIFramework.axbundle> (not loaded)
2014-02-10 15:22:51.563 debounce[62164:80b] -[String alert]: unrecognized selector sent to instance 0x8b44850
(main)> 2014-02-10 15:22:51.857 debounce[62164:80b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[String alert]: unrecognized selector sent to instance 0x8b44850'
*** First throw call stack:
(
0 CoreFoundation 0x01d885e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x001d08b6 objc_exception_throw + 44
2 CoreFoundation 0x01e25903 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x01d7890b ___forwarding___ + 1019
4 CoreFoundation 0x01d784ee _CF_forwarding_prep_0 + 14
5 CoreFoundation 0x01d7cd1d __invoking___ + 29
6 CoreFoundation 0x01d7cc2a -[NSInvocation invoke] + 362
7 debounce 0x00014713 __unnamed_96 + 67
8 debounce 0x00108491 rb_vm_dispatch + 4577
9 debounce 0x0000bbdc vm_dispatch + 1100
10 debounce 0x00012dc7 rb_scope__call:__block__ + 727
11 debounce 0x001161bf _ZL20dispatch_bimp_callerPFP11objc_objectS0_P13objc_selectorzEmS1_mP11rb_vm_blockiPKm + 46351
12 debounce 0x00109acc _ZL13vm_block_evalP7RoxorVMP11rb_vm_blockP13objc_selectormiPKm + 1244
13 debounce 0x00109cc4 rb_vm_yield_args + 84
14 debounce 0x000fe753 rb_yield + 67
15 debounce 0x00082640 rb_obj_tap + 16
16 debounce 0x0012183f _ZL20dispatch_rimp_callerPFP11objc_objectS0_P13objc_selectorzEmS1_iPKm + 46303
17 debounce 0x00108773 rb_vm_dispatch + 5315
18 debounce 0x0000bbdc vm_dispatch + 1100
19 debounce 0x00012990 rb_scope__call:__ + 896
20 debounce 0x0012183f _ZL20dispatch_rimp_callerPFP11objc_objectS0_P13objc_selectorzEmS1_iPKm + 46303
21 debounce 0x00108773 rb_vm_dispatch + 5315
22 debounce 0x0001575c vm_dispatch + 1100
23 debounce 0x0001c0ce rb_scope__viewDidLoad__ + 558
24 debounce 0x0001c108 __unnamed_9 + 24
25 UIKit 0x0070b318 -[UIViewController loadViewIfRequired] + 696
26 UIKit 0x0070b5b4 -[UIViewController view] + 35
27 UIKit 0x006339fd -[UIWindow addRootViewControllerViewIfPossible] + 66
28 UIKit 0x00633d97 -[UIWindow _setHidden:forced:] + 312
29 UIKit 0x0063402d -[UIWindow _orderFrontWithoutMakingKey] + 49
30 UIKit 0x0e378c66 -[UIWindowAccessibility(SafeCategory) _orderFrontWithoutMakingKey] + 77
31 UIKit 0x0063e89a -[UIWindow makeKeyAndVisible] + 65
32 debounce 0x00014713 __unnamed_96 + 67
33 debounce 0x00108491 rb_vm_dispatch + 4577
34 debounce 0x0001d54c vm_dispatch + 1100
35 debounce 0x000243c1 rb_scope__initialize_main_controller__ + 913
36 debounce 0x0012183f _ZL20dispatch_rimp_callerPFP11objc_objectS0_P13objc_selectorzEmS1_iPKm + 46303
37 debounce 0x00108773 rb_vm_dispatch + 5315
38 debounce 0x0001d54c vm_dispatch + 1100
39 debounce 0x00023da7 rb_scope__application:didFinishLaunchingWithOptions:__ + 119
40 debounce 0x00023e1f __unnamed_11 + 95
41 UIKit 0x005f1355 -[UIApplication _handleDelegateCallbacksWithOptions:isSuspended:restoreState:] + 309
42 UIKit 0x005f1b95 -[UIApplication _callInitializationDelegatesForURL:payload:suspended:] + 1536
43 UIKit 0x005f63a8 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 824
44 UIKit 0x0060a87c -[UIApplication handleEvent:withNewEvent:] + 3447
45 UIKit 0x0060ade9 -[UIApplication sendEvent:] + 85
46 UIKit 0x005f8025 _UIApplicationHandleEvent + 736
47 GraphicsServices 0x03a0e2f6 _PurpleEventCallback + 776
48 GraphicsServices 0x03a0de01 PurpleEventCallback + 46
49 CoreFoundation 0x01d03d65 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 53
50 CoreFoundation 0x01d03a9b __CFRunLoopDoSource1 + 523
51 CoreFoundation 0x01d2e77c __CFRunLoopRun + 2156
52 CoreFoundation 0x01d2dac3 CFRunLoopRunSpecific + 467
53 CoreFoundation 0x01d2d8db CFRunLoopRunInMode + 123
54 UIKit 0x005f5add -[UIApplication _run] + 840
55 UIKit 0x005f7d3b UIApplicationMain + 1225
56 debounce 0x00002d9c main + 156
57 libdyld.dylib 0x02fd570d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
class ViewController < UIViewController
def viewDidLoad
super
alerter = Alerter.new
throttler = Throttler.new(alerter, 0.5).call(:alert, 'Error')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment