[MacRuby-devel] Accessing bytes within NSData

Pete Yandell pete at notahat.com
Sun Mar 22 15:18:09 PDT 2009


I'd like to use something like Ruby's String#unpack to pull some info  
out of an NSData, but I'm stumped as to how to do it.

NSData.bytes returns a Pointer object, but trying to use [] to  
dereference it gives me:

	ArgumentError: can't convert C/Objective-C value `0x800059800' of  
type `?_?' to Ruby object

I've done a lot of digging around, reading of forum posts, playing  
(unsuccessfully) with BridgeSupport, etc., but it hasn't got me any  
closer. Any hints?

The broader context is that I'm trying to extract the TCP port number  
from an NSSocketPort. NSSocketPort's address method returns an NSData,  
which should contain a sockaddr_in, out of which I should be able to  
pull the port.

Thanks,

Pete Yandell
http://notahat.com/


More information about the MacRuby-devel mailing list