setStringValue is not even mentioned in NSTextField's documentation... why is that?


#1

so… I understand that one needs to use the documentation to learn Objective-C and how it is used in XCode… but I’m having a hard time understanding how the documentation works. On page 28, we see some code…

[textField setStringValue:@"Generator Seeded"];

“textField” here is an instance of NSTextField. But in the documentation for NSTextField… there is no method called “setStringValue:” Nor is it in the super class NSControl. How is one supposed to know what methods to use given a NSTextField object if they aren’t even listed in the documentation? In fact… is there a method in the documentation for NSTextField that would send text to a textfield?

Again, going by the documentation… setStringValue: is a PDFAnnotationTextWidget (!!!)… and a deprecated one at that. But… it oddly still works as of this writing in October of 2018… and… if there’s a newer and better way to send something to a text field… I don’t even know where I would begin to look.

Frustrating.


#2

What class does NSTextField inherit from? You should ask yourself.

A quick look at documentation shows that it is NSControl. Looking further reveals that there is a property named stringValue, which is what you need.

You need to get into the habit of consulting the documentation if something doesn’t make sense, or if you are unsure. Start with Option-click in Xcode, or Command-Click.


#3

Ah! stringValue is an instance property of NSControl… so its setter method would be called setStringValue. I think the valuable lesson for me here is any time I see the word “set” in front of something I need to realize it’s probably a setter method that is synthesized, and therefore not shown. Coming from C this is a tricky concept… you call a function that exists by that very name in stdio or stdlib or wherever. Since doing a search for “setStringValue” pulls up no matches in NSControl documentation, I assumed it wasn’t a part of NSControl. I knew I was going to get burned by the fact that synthesizing the setters and getters creates hidden code, and I did.

Thanks as always Ibex10, I so appreciate the help. :]

ps. am I the last person on the planet learning Objective-C? It really feels that way.


#4

That’s because you are a real programmer :slight_smile:


#5

Aww, thanks! You know, I’m resisting Swift until I feel comfortable with Objective-C, but I gotta tell you it’s hard, a lot of the tutorial sites have migrated away from Objective-C.

Thanks for the encouragement… a little bit of that goes a long way. Onward!