Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum

View Single Post
Old 06-13-2009, 07:03 PM   #7 (permalink)
RLScott
Registered Member
 
Join Date: Jun 2009
Location: Ypsilanti, Michigan
Age: 63
Posts: 1,549
RLScott is on a distinguished road
Default

Quote:
Originally Posted by ozzie View Post
If I have 2 .h and .m files and I want to pass the value of a variable between them, how would I do it?

So in Slide1.m it declares Variable1 = 10; then I want Slide2.m to be able to declare Variable2 = Variable1; but it obviously says "Variable1 undeclared (first use in a function)"

Thanks in advance
If Variable1 and Variable2 are integers, then they don't have to be instance variables of any class. You can simply declare them both to be global variables. In Slide1.h, use:

Code:
extern int Variable1;
@interface Slide1
 . . .
@end
and similarly for Slide2.h. And in the implementation files, use:
Code:
int Variable1;
@implementation Slide1
 . . .
@end
You see that the declaration and the definition are outside of the @interface and @implementation blocks. It is up to you to ensure that there is only one instance of the Slide1 and Slide2 classes.

The problem with using instance variables, even if they are properties, is that you need to also have a reference to the instance of the class they belong to. How does Slide1.m have any pointer to an instance of Slide2? There could potentially be several Slide1 instances and several Slide2 instances. But from your description, it appears that you are thinking of just one instance of each class.

Robert Scott
Ypsilanti, Michigan
RLScott is offline   Reply With Quote
 

» Advertisements
» Online Users: 407
14 members and 393 guests
7twenty7, AppsBlogger, baja_yu, BumChinBooth, ChrisYates, dylanreich, evilmatt10, JoeRCruso, MarkC, Mnashmi, networ, samdanielblr, TheStalker, za1407
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,636
Threads: 94,101
Posts: 402,816
Top Poster: BrianSlick (7,990)
Welcome to our newest member, samdanielblr
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:29 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.