On 8 May 2012, at 19:01, Jens Alfke wrote:
> On May 8, 2012, at 9:15 AM, Antonio Nunes wrote:
>
>> I have a text field that when I try to set it to a literal string fails:
>> This is the code:
>> self.myTextField.stringValue = @""; (It also fails if the literal string is
>> not empty).
>
> That is quite bizarre. So much so that I’m assuming that this isn’t the
> actual problem, that there’s a mixup about which line is raising the
> exception.
I don't think so. I set a break point and then step over the line in question
which immediately causes the assertion failure.
>> This is the (partial) backtrace:
>> 2012-05-08 18:09:28.516 MyApp[18775:507] *** Assertion failure in
>> -[NSTextFieldCell _objectValue:forString:errorDescription:],
>> /SourceCache/AppKit/AppKit-1138.32/AppKit.subproj/NSCell.m:1564
>>
>> Catchpoint 7 (exception thrown).2012-05-08 18:09:31.742 MyApp[18775:507]
>> Invalid parameter not satisfying: aString != nil
>> 2012-05-08 18:09:31.845 MyApp[18775:507] (
>> 0 CoreFoundation 0x00007fff90d12fc6
>> __exceptionPreprocess + 198
>> 1 libobjc.A.dylib 0x00007fff8c3f4d5e
>> objc_exception_throw + 43
>> 2 CoreFoundation 0x00007fff90d12dfa
>> +[NSException raise:format:arguments:] + 106
>> 3 Foundation 0x00007fff92db1743
>> -[NSAssertionHandler
>> handleFailureInMethod:object:file:lineNumber:description:] + 169
>> 4 AppKit 0x00007fff8a9495a5 -[NSCell
>> _objectValue:forString:errorDescription:] + 160
>> 5 AppKit 0x00007fff8a9494ff -[NSCell
>> _objectValue:forString:] + 19
>> 6 AppKit 0x00007fff8a949465 -[NSCell
>> setStringValue:] + 41
>> 7 AppKit 0x00007fff8aa4a5e8 -[NSControl
>> setStringValue:] + 115
>
> So, what’s line 8? Are you *certain* that it’s the line you quoted above, and
> not some other -setStringValue: call in your code?
> If you set a breakpoint on the line in question, and then step over the call,
> does the exception trigger?
Yes. This is the surrounding code:
if (self.toolbarPageNumberTextField.integerValue !=
self.pageListController.selectionIndex + 1) {
if (self.toolbarPageNumberTextField.integerValue ==
NSNotFound) {
self.toolbarPageNumberTextField.stringValue =
@"";
} else {
NSUInteger idx =
self.pageListController.selectionIndex;
if ( idx != NSNotFound ) {
self.toolbarPageNumberTextField.integerValue = idx + 1;
} else {
self.toolbarPageNumberTextField.stringValue = @"";
}
}
}
> The only other explanation I can think of is that some previous bug in the
> code has messed up the predefined NSString instance that @“” points to. But
> that would be hard to do — IIRC, the compile-time-constant NSStrings are
> somewhat magical and don’t track refcounts, so you can’t over-release them.
I don't release @"" anywhere, so that is indeed very, very unlikely. Also, if I
avoid the exception and assign @"" to a text field a bit later on in another
piece of code, it works just fine. Could it be a compiler bug?
-António
----------------------------------------------------
It isn't so important to do great things,
as to do what you do with great love.
----------------------------------------------------
_______________________________________________
Cocoa-dev mailing list ([email protected])
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]