[MacRuby-devel] Accessing bytes within NSData

Pete Yandell pete at notahat.com
Tue Mar 31 17:58:07 PDT 2009


On 25/03/2009, at 6:03 AM, Brian Chapados wrote:

> Since you have an NSData object, you should be able to convert it to a
> String (NSString) and then use unpack.  For example:
>
> socket_port = NSSocketPort.alloc.initWithTCPPort(11111)
> addr = socket_port.address
> addr_str = NSString.alloc.initWithData(addr,
> encoding:NSString.defaultCStringEncoding)
> port = addr_str.unpack("nn")[1]  # seems to work - not sure what  
> this should be

Thanks, Brian. That was just the ticket. Not sure why I didn't think  
of it!

- Pete


More information about the MacRuby-devel mailing list