16 Replies - 6310 Views - Last Post: 01 September 2011 - 10:00 AM
#1
What is objective-C?
Posted 06 August 2011 - 01:21 AM
Replies To: What is objective-C?
#2
Re: What is objective-C?
Posted 06 August 2011 - 04:39 AM
Of course it's still a language and yes it can be used anywhere, but you'll probably never see it outside of these platforms.
#3
Re: What is objective-C?
Posted 06 August 2011 - 06:11 AM
#4
Re: What is objective-C?
Posted 06 August 2011 - 06:24 AM
It's a C-based language, the only "language" for web development is HTML/XHTML, design is just visualising.
It has a very strange non-OOP way of doing OOP which is definitely not OOP by any stretch of the matter. Also, you don't call functions, you send "messages" to them. It's God-awful.
#5
Re: What is objective-C?
Posted 06 August 2011 - 05:57 PM
#6
Re: What is objective-C?
Posted 06 August 2011 - 06:07 PM
#7
Re: What is objective-C?
Posted 06 August 2011 - 06:23 PM
#8
Re: What is objective-C?
Posted 06 August 2011 - 11:13 PM
#9
Re: What is objective-C?
Posted 07 August 2011 - 11:33 AM
There are a few things that makes it appear different:
1) (Almost) Everything you make is a pointer. For example, when you want to make an instance of a class, it has to be a pointer. So for example, in C++ you would do:
MyClass *myclass = new MyClass();
While in Obj-C, you would do:
NSClass *myclass = [[NSClass alloc] init];
And that last part comes to number 2.
2) Messages are just methods in pointers.
C++ would do:
// from above myclass->someMethod(someVar, anothervar);
Obj-C would do:
[myclass someMethod: someVar AnotherVar: anotherVar];
This may look confusing, but this ties with #3.
3) Making methods. Obj-C uses some fancy syntax for making methods, but it makes it more readable.
C++ method in a class/outside a class:
// class void MyClass::someMethod(int var1, double var2); // outside a class someMethod(int var1, double var2);
Now Obj-C's:
// class + (void) someMethod: (int)var1 someVar: (double)var2; // outside class - (void) someMethod: (int)var1 someVar: (double)var2;
4) Making classes
C++:
class MyClass : public ParentClass {
private:
int somevar;
protected:
void someMethod();
public:
char c;
};
// in .cpp file
void MyClass::someMethod() {}
Obj-C:
// if making a class, always subclass NSObject
@interface MyClass : NSObject {
// note you don't need the colon like C++, but you need a @
@public
@private
@protected
// vars here
}
// method prototypes here
@end
// in the .m file
@implementation MyClass
// define methods here
@end
5) #include -> #import
There is more, but that's the noticeable differences.
This post has been edited by heyoman1: 07 August 2011 - 02:08 PM
#10
Re: What is objective-C?
Posted 08 August 2011 - 06:19 AM
#11
Re: What is objective-C?
Posted 08 August 2011 - 07:45 AM
If it helps piques your interest something you can do in ObjC is auto-generate the get/set functions.
@interface Fraction : Object {
int numerator;
int denominator;
}
@property int numerator
@property int denominator
@end
#import "Fraction.h" @implementation Fraction @synthesize numerator; @synthesize denominator; @end
Demonstrated above is the default property/synthesize, which is to allow reading and writing. you can specify read/write only, as well as specifying how to pass objects instead of primitive data types.
@property (readonly) int var; @property (writeonly) int var; @property (retain) Object *obj; @property (assign) Object *obj; @property (copy) Object *obj;
Assign and copy are fairly simple to grasp. Retaining is how the NS framework handles memory management if you choose to not use the garbage collector. Each object has a reference count. Calling retain increments the reference counter, and release decrements the reference counter. So, telling the @property to use retain is simply an assignment with a call to retain.
Note, for property/synthesize to work you need to have Mac OS 10.5 or gcc 4.6 or higher.
#12
Re: What is objective-C?
Posted 08 August 2011 - 07:48 AM
Quote
#13
Re: What is objective-C?
Posted 08 August 2011 - 08:24 AM
#14
Re: What is objective-C?
Posted 08 August 2011 - 02:54 PM
|
|

New Topic/Question
Reply



MultiQuote





|