[MacRuby-devel] MacRuby pointers and Obj-C function returning a alue by reference
Watson
watson1978 at gmail.com
Mon Jan 21 14:30:47 PST 2013
Hi
Maybe, you could write your code as following:
$ macirb --simple-prompt
>> framework 'AppKit'
=> true
>> range = Pointer.new(NSRange.type)
=> #<Pointer:0x40122e760>
>> range.assign NSMakeRange(0,1)
=> #<NSRange location=0 length=1>
>> str = NSAttributedString.alloc.initWithString("hello")
=> hello{
}
>> str.attribute(NSUnderlineStyleAttributeName, atIndex:0, effectiveRange:range)
=> nil
Cheers.
Watson
> I am trying to implement the following method of NSAttributedString in Macruby:
>
> - (id)attribute:(NSString *)attributeName atIndex:(NSUInteger)index effectiveRange:(NSRangePointer)aRange
>
> As by definition, it `Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.`
>
> OK, so I need a pointer to NSRange, which I set up as follows:
>
> range=Pointer.new("{_NSRange=QQ}")[0]
>
> It seems to be fine as `range.class` => `NSRange`.
>
> However, when I execute the method:
>
> font=txtStor.attribute(NSFontAttributeName,atIndex:index,effectiveRange:range)
>
> my `range` is always `#<NSRange location=0 length=0>`. Also, `p range` gives me `#<NSRange location=0 length=0>`.
>
> Any ideas how to implement this correctly?
>
> Thanks
> K
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org (mailto:MacRuby-devel at lists.macosforge.org)
> http://lists.macosforge.org/mailman/listinfo/macruby-devel
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20130122/b0b273ca/attachment.html>
More information about the MacRuby-devel
mailing list