MacRuby pointers and Obj-C function returning a value by reference
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
I've only ever made ranges in the past using this syntax: range = NSMakeRange(0,1) Which allows you to set the start point and length. On 21/01/2013, at 22:08, "kwicher@wichry.net" <kwicher@wichry.net> wrote:
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@lists.macosforge.org http://lists.macosforge.org/mailman/listinfo/macruby-devel
-- Stephen Horne
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@lists.macosforge.org (mailto:MacRuby-devel@lists.macosforge.org) http://lists.macosforge.org/mailman/listinfo/macruby-devel
Hi, First, thank you Watson and Mark for finding the time to keep MacRuby alive. Now that I’ve basked in its beauty for a while, just the thought of going back to Obj-C seems unbearable. Until recently, I have only programmed tools in support of my academic research. My developer ambitions have grown somewhat over time so I am now thinking of building a version of my little knowledge management system for App Store. This, of course, implies a much more dedicated workflow than my usual hackety-hack. I gave a serious go at using various editors (vim, TextMate, Sublime Text), testing frameworks (RSpec, MacBacon, Minitest), and various building options. I am however yet to find a painless combination… I would be therefore very grateful if you could share a little about the way you develop MacRuby apps, or at least they way you would recommend it to a lonely amateur developer (i.e. no provision for a developer team necessary). In case it is relevant: I am/will be using WebKit (html, css and svg via d3), ScriptingBridge, LatentSemanticMapping, CoreData, and will have to process, visualise and store data concurrently. Other than designing the managed object model, I would like to stay clear of Xcode as much as possible. Many thanks! milos
participants (4)
-
kwicher@wichry.net
-
Milos Rankovic
-
stephen horne
-
Watson