[MacRuby-devel] Setting properties on a dereferenced NSRangePointer has no effect
Caio Chassot
lists at caiochassot.com
Fri Jan 21 13:37:56 PST 2011
Hi all,
NSFormatter defines a method with the following selector:
isPartialStringValid:proposedSelectedRange:originalString:originalSelectedRange:errorDescription:
This is its signature:
- (BOOL)isPartialStringValid:(NSString **)partialStringPtr
proposedSelectedRange:(NSRangePointer)proposedSelRangePtr
originalString:(NSString *)origString
originalSelectedRange:(NSRange)origSelRange
errorDescription:(NSString **)error
The relevant bit here is the proposedSelRangePtr argument, which is a NSRangePointer.
When subclassing NSFormatter in ruby, I define the method as:
def isPartialStringValid(partialStringPtr,
proposedSelectedRange:proposedSelRangePtr,
originalString:origString,
originalSelectedRange:origSelRange,
errorDescription:error)
When implementing the Cocoa Programming exercises in MacRuby, I ran across the following situation:
At some point in that method definition, in the original code, Aaron sets the range properties directly:
proposedSelRangePtr->location = [*partialStringPtr length];
proposedSelRangePtr->length = [match length] - proposedSelRangePtr->location;
Initially, I did similar in MacRuby
proposedSelRangePtr[0].location = partialStringPtr[0].length
proposedSelRangePtr[0].length = match.length - proposedSelRangePtr[0].location
This has no effect. It does not raise, but the values go unchanged. I can NSLog the range values before and after and they're the same.
My final solution was to assign a new range to that location:
proposedSelRangePtr[0] = NSRange.new(partialStringPtr[0].length, match.length - partialStringPtr[0].length)
But I wonder why setting the range properties had no effect. MacRuby bug?
More information about the MacRuby-devel
mailing list