Objective C: How can you pass integer variables between classes? - objective-c

So lets say I made a variable in one class called 'number' and gave it a value of 3.
and I made a variable in another class called 'number2'
what functions could I use to pass the value of 'number' to 'number2' in that other class?
Thanks.

To get started with Objective-C, including learning how to pass values as method arguments, have a look at Apple's Learning Objective-C: A Primer, Object-Oriented Programming with Objective-C, and Cocoa Fundamentals Guide.

Look up accessor methods on google.

Related

Queries regarding Smalktalk's method and class

You can't have methods with the same name in the same class in Smalltalk. Why?
I don't understand why methods can't have same name in same class.
You are probably thinking about function overloading in languages like C++ in which you can have multiple functions/methods with the same name but different parameter types or count. The difference is that in dynamic programming languages like Smalltalk the type is associated with the object not the variable and so a variable can hold any type and the compiler doesn't know the type. So there would be no way to distinguish between functions/methods with the same name.

Object oriented programming same methods

can i have same method name with same params and params type in a single class? how about in a different class with same name?
In response to the first part is the ans overriding? what about the second part of the questions "how about in a different class with same name?"
I think there a few examples in which the answer to both your questions is yes, but as far as my knowledge in Java and Objective C is concerned, you cannot have two methods named exactly the same with same parameter names and types in the same class. I believe that you can in two different classes, but you generally shouldn't, just to keep your code simple and easily understandable, but you can do it all the same.

How to declare a class factory method in Objective C?

I am a newbie with Objective C programming.
My first steps to learn Objective C is to read the PDF "Programming with Objective C" from the Apple Developers site.
At the end of every chapter there are exercises to make. Chapter 1 has 4 questions. The first 3 questions are not so dificult to make. But the 4th question I can't figure it out what the anwser is.
The question is:
Add a declaration for a class factory method, called "Person". Don't worry about implementation this method until the next chapter.
I hope that anybody can and will help me.
Thank you
Carlos Wiesemann
Take another look at the section just before the exercises, Objective-C Classes Are also Objects. That section talks about how classes themselves are objects that can have methods separate from the methods that an instance of the class has. When the question asks for a "class factory" method, it means a class method that creates a new instance of that class, just like the string methods in the linked section.
Class method declarations look just like instance methods, except they are prefixed with a plus sign instead of a minus sign. For example,suppose you have a class named Car
let’s add the following class-level method to Car.h:
+ (void)setDefaultModel:(NSString *)aModel;

Objective-C equivalent of a flash action script function

Learning basic Objective-C and have a few beginner questions.
How would I define and implement a method which takes two (or three) arguments within my class?
I find the syntax to pass multiple arguments into a method really confusing. I would really appreciate any help. thanks.
Apple's "The Objective-C Programming Language" document provides a nice overview of Object Messaging including an explanation of the syntax.
Here's an example of a simple 2-argument method implementation:
-(int)myMethodThatMultipiesThisNumber:(int)x byThisOne:(int)y
{
return x * y;
}
You would invoke it like:
int z = [myObject myMethodThatMultipliesThisNumber:6 byThisOne:9];
Is that what you're looking for?
Edit: Based on your comment below, it seems like you're missing a fundamental feature of Objective-C messaging - that the method name is interleaved with the arguments. Check out this page from The Objective-C Programming Language for all the detail you need.
Whether or not you are interested in iPhone programming, I would watch the first three classes of Paul Hegarty's CS193P class from Stanford.
Those first three classes have very little iPhone specific stuff, instead, classes 1 and three go over the features and syntax of Objective C, and class 2 goes over basic use of Xcode (which, if you want to do Objective C work, is likely the IDE you will be using). Other than the fact that it goes VERY fast (which may actually be what you are looking for) you would be hard pressed to find a better "quick overview" of Objective C.

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
Yes, and yes:
http://www.cocoacast.com/?q=node/103
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.