views:

64

answers:

2

hi all,

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

+1  A: 

Yes, and yes:

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

Merlyn Morgan-Graham
A: 

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.

Abizern
Properties are just a formal syntax for declaring accessor methods and (in the modern runtime) instance variables. KVC is a way to access such a property, whether it was formally declared or not. The distinction is that `foo.bar` directly sends a `bar` message to `foo`, exactly as `[foo bar]` would, whereas KVC will actually *look for* a method like `bar` or `_bar` and only send a message if it finds one (and it will peek the `bar` or `_bar` ivar if it doesn't find a method). So, KVC mostly sits on top of properties; properties do not wrap KVC.
Peter Hosey
I was trying to say that properties simplify creating KVC compliant accessors, even down to `@synthesize _iVar = iVar;`
Abizern
is there anyone to explain me easier how to set StringValue of variable of one class to the textfield of another class?
aden
Have a look at Cocoa Bindings http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/WhatAreBindings.html
Abizern