Use NSLog when printing on the device#10
Conversation
|
Thanks for this! Would would you think about adding a class method to MotionPrint that would enable this functionality? I'd prefer for my logs on device not to get cluttered when in production (since i leave all my Something like: def def application(application, didFinishLaunchingWithOptions:launchOptions)
#...
MotionPrint.enable_nslog
#...
endand then only print to NSLog if enabled? |
|
Ok, I added the opt-in stuff and took a stab at updating the README. |
|
👍 |
|
@mwise Looks like there are merge conflicts in your branch. Do you mind fixing those? |
|
@andrewhavens wow talk about a blast from the past! I'm not using RubyMotion these days and have limited time to look at this. I'll take a look as soon as I can - if a) my RubyMotion setup still works and b) the conflicts are easily resolved, then I'd be happy to update this PR. If it's being difficult, I may have to punt on it, since it's not something that I need right now. |
|
I created a pull request based on the original pull request from @mwise This one is based on the latest master so there shouldn't be any conflicts. Please review and merge. Thanks guys |
|
@hgani thanks for doing that. As it turns out, my RubyMotion environment is completely hosed, and not likely to come alive again anytime soon. Good luck! |
This PR updates
Kernel#mp()to use NSLog when running on the device as discussed in #6It basically just splits on newlines the output that would have been printed using
putson the simulator and prints each line using NSLog. I was skeptical this would work initially, but it seems to work pretty well in my limited testing.I took the guts of
MotionPrint.simulator?directly from BubbleWrap::Device, and it should be cached as a class instance variable and thus be pretty lightweight to call in repeated calls toKernel#mp(). I added a spec forMotionPrint.simulator?that passes on both the simulator and the device. However, I have no idea how to test the actual NSLog part. I didn't want to add a mocking/stubbing library, and I'm pretty sure NSLog would be a hard thing to stub/spy on, regardless. Suggestions welcome on that front.Anyway, please take a look and let me know if this is something worth pursuing.
Cheers,
Mark