New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Objective-C .. I just don't get it


Post Reply New Thread Subscribe

 
Thread Tools
pendal

 
Member Since: May 15, 2009
Posts: 1
pendal is on a distinguished road

pendal is offline
I am having a really hard time moving to objective-c /cocoa in terms of the .h and .m files.

I understand what they are, but I don't get what goes where.

My biggest issues right now is

how can I internalize variables for use inside a specific function
PHP Code:
-(void)afunctionImade{
var1 1;

var2 5;


var3 var1 var2;
return 
var3;

if i try to build and go on this i get the error

"var1 undeclared (first use in this function)"
and so on for each variable.

I ONLY want to use those vars inside of that exact function, I don't want them to be accessed anywhere else. Why do I have to declare it somewhere? Or how do i declare it so that is it only used inside that function?

Thanks in advance,
Chris
QUOTE Thanks
Aptmunich

 
Aptmunich's Avatar
 
Member Since: Mar 09, 2004
Location: Munich
Posts: 9,075
Aptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant futureAptmunich has a brilliant future
Mac Specs: Aluminium Macbook 2.4 Ghz 4GB RAM, SSD 24" Samsung Display, iPhone 4, iPad 2

Aptmunich is offline
It doesn't look as though you've defined an object type for your variables...
You'd need to write:
Code:
int var1 = 1;
(Unlike PHP, you can't use variables without types like that in Objective-C - or many other languages).

Once declared, you can access the variable directly:

Code:
var1 = 5*12;
QUOTE Thanks
mystic_fm

 
Member Since: Mar 15, 2007
Posts: 161
mystic_fm will become famous soon enough
Mac Specs: 17" MacBook Pro, 2.33GHz C2D, 2GB RAM

mystic_fm is offline
To add to what Aptmunich said, your problem here seems to have been more of a lack of understanding of the C language rather than with Objective-C. You may want to take a step back and find some C language tutorials or books to dive into and gain an understanding of before you start adding Objective-C's extensions to the mix.
QUOTE Thanks

Post Reply New Thread Subscribe


« New to mac and to SDK | g++ compiler »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Best programming language for Mac knightjp OS X - Development and Darwin 21 05-10-2010 04:45 PM
Objective C call main method ncohen OS X - Development and Darwin 1 06-23-2009 03:02 PM
New to Objective C - what is the problem with this? rb1383 OS X - Development and Darwin 1 04-22-2009 12:33 AM
question about objective C memory allocation thuffir OS X - Development and Darwin 3 11-18-2008 10:30 PM
Cocoa, Objective C - where do I start? TheMonkey OS X - Development and Darwin 1 08-19-2006 07:25 AM

All times are GMT -4. The time now is 10:47 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?