Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Objective-C Confusion!!!

Hello... I've recently started the Objective-C course. And I've gotten a few videos in... I am pretty fluent in Swift already, but I will likely not make my first App in Swift because its not a stable language yet, which is why I'm learning Objective-C (Just to be clear, I am fluent in Swift Syntax, I am not fluent in App making)

I had a few questions though...

To create a variable, instead of using "var" like in swift, you do "NSString *<stringname>;" (Without quotes) is it essentially just a var without the var prefix? It's just a direct way of saying we're making a variable of type String. Without the "var str: String"?

Also... in this case:

import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) { @autoreleasepool { // insert code here... NSLog(@"Hello, World!"); }

NSString *firstName;
firstName = @"Ryan";
NSLog(@"firstName: %@", firstName);



return 0;

}

NSString *str = @"Test";

It won't let me declare a string variable outside of the main function... is that normal? Does all code need to be inside of a main function or a function with argc and stuff declared??? I may sound very noobish but I really want to understand this so later I'm not totally lost.

I should say, it won't let me execute ANY code including printing outside of the main function... is that normal? What if I make a new objective-c class file, do I need to make another main function before adding any code?