Skip to content

Instantly share code, notes, and snippets.

@Cosmo
Last active August 29, 2015 13:56
Show Gist options
  • Save Cosmo/9066274 to your computer and use it in GitHub Desktop.
Save Cosmo/9066274 to your computer and use it in GitHub Desktop.
translate obj-c code to ruby (rubymotion)
// Objective-C
uuid_t myAppUUIDbytes;
NSUUID *myAppUUID = [[NSUUID alloc] initWithUUIDString:@"226834ae-786e-4302-a52f-6e7efc9f990b"];
[myAppUUID getUUIDBytes:myAppUUIDbytes];
# Ruby
myAppUUIDbytes = Array.new(16, 0)
myAppUUID = NSUUID.alloc.initWithUUIDString("226834ae-786e-4302-a52f-6e7efc9f990b")
myAppUUID.getUUIDBytes(myAppUUIDbytes)
-------
With Array.new(16, 0)
(main)> myAppUUIDbytes = Array.new(16, 0)
=> [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
(main)> myAppUUID = NSUUID.alloc.initWithUUIDString("93ad3e1c-7a52-434f-bfaf-efcc4f842474")
=> #<__NSConcreteUUID:0xca38b20>
(main)> myAppUUID.getUUIDBytes(myAppUUIDbytes)
=> #<__NSConcreteUUID:0xca38b20>
(main)> NSData.dataWithBytes(myAppUUIDbytes, length:16)
dyld: lazy symbol binding failed: Symbol not found: __ZN9RoxorCore14find_bs_cftypeESs
Referenced from: /Library/RubyMotion/data/ios/librubymotion-repl.dylib
Expected in: flat namespace
dyld: Symbol not found: __ZN9RoxorCore14find_bs_cftypeESs
Referenced from: /Library/RubyMotion/data/ios/librubymotion-repl.dylib
Expected in: flat namespace
cosmos-macbook-pro:PebbleFun Cosmo$
With Pointer.new(:uint, 16)
(main)> myAppUUIDbytes = Pointer.new(:uint, 16)
=> #<Pointer:0xbb7e890>
(main)> myAppUUID = NSUUID.alloc.initWithUUIDString("93ad3e1c-7a52-434f-bfaf-efcc4f842474")
=> #<__NSConcreteUUID:0xb812030>
(main)> myAppUUID.getUUIDBytes(myAppUUIDbytes)
2014-02-18 09:22:51.422 OnTellyPebble[3172:80b] expected Array (TypeError)
=> #<TypeError: expected Array>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment