aden
aden

Reputation: 1927

access a variable of another class via a property

I have two classes,In classA I create a variable that I need to use in classB , should i use property ?

is there anyone to explain me easier ,how to set StringValue of variable in one class to the textfield of another class?

thanks

Upvotes: 0

Views: 1103

Answers (2)

Abizern
Abizern

Reputation: 150745

The simple answer is Yes, use properties, that is what they are for: a simple way of exposing the state of an object to other objects.

The longer answer is that Objective-C 2.0 properties are just a wrapper around the concept of Key-Value-Coding and Key-Value-Observing (KVC/KVO).

It is well worth reading the documentation for these as the concept is fundamental to the way that Cocoa works and understanding them early on in your learning process will save you a lot of trouble in the future.

And, since you will be passing object references around I might as well add a link to the Memory Management Programming Guide which will help you correctly apply the proper memory management attributes to your @property declarations.

Upvotes: 0

Merlyn Morgan-Graham
Merlyn Morgan-Graham

Reputation: 59151

Yes, and yes:

http://www.cocoacast.com/?q=node/103

Upvotes: 1

Related Questions