Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Cocoa programming issue
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="mystic_fm" data-source="post: 776045" data-attributes="member: 28538"><p>NSTextField knows how to convert its contents to an NSString if the stringValue selector is called, true. But that doesn't mean that an NSTextField can be treated as is if it is an NSString ... they are still separate types of objects, with separate functionality.</p><p></p><p>Selectors only function when sent to classes that have them defined (either in the class itself or in one of the classes it inherits from). The stringValue selector is defined as a member of the NSControl class, from which NSTextField is subclassed (check the "Inherits from" section of the NSTextField documentation). Conversely, isEqualToString is a selector defined as part of the NSString class, and does not inherit anything from either NSTextField or NSControl. Hence, you can no more say [NSTextField isEqualToString] than you can say [NSString stringValue]. The latter would of course be redundant and effectively a no-op, but nonetheless it doesn't work ... try it for yourself and see.</p><p></p><p>If you want to use NSString selectors on the string contents of an NSTextField, first you need to get the contents of the NSTextField into an NSString object. You should already know how to do that ... in fact you just finished talking about doing it successfully, and it doesn't even have to require any additional lines of code. Hint: you can nest messages.</p></blockquote><p></p>
[QUOTE="mystic_fm, post: 776045, member: 28538"] NSTextField knows how to convert its contents to an NSString if the stringValue selector is called, true. But that doesn't mean that an NSTextField can be treated as is if it is an NSString ... they are still separate types of objects, with separate functionality. Selectors only function when sent to classes that have them defined (either in the class itself or in one of the classes it inherits from). The stringValue selector is defined as a member of the NSControl class, from which NSTextField is subclassed (check the "Inherits from" section of the NSTextField documentation). Conversely, isEqualToString is a selector defined as part of the NSString class, and does not inherit anything from either NSTextField or NSControl. Hence, you can no more say [NSTextField isEqualToString] than you can say [NSString stringValue]. The latter would of course be redundant and effectively a no-op, but nonetheless it doesn't work ... try it for yourself and see. If you want to use NSString selectors on the string contents of an NSTextField, first you need to get the contents of the NSTextField into an NSString object. You should already know how to do that ... in fact you just finished talking about doing it successfully, and it doesn't even have to require any additional lines of code. Hint: you can nest messages. [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Cocoa programming issue
Top