From Actionscript to Objective-C

I thought it might be useful to those who have recently approached the development of applications for Apple iPhone, compare Adobe ActionScript - the language used in Adobe Flash and Adobe Flex, more common among the neo-programmers - and Objective-C language used by Apple to develop its applications. Objective-C is in effect an object-oriented language in the pure sense, not that Actionscript is not, but Objective-C is definitely a plus because it is an extension of ANSI C and its syntax is a mix between C / C + + and Smalltalk, is a true OO (Object-oriented language). Many features of Objective-C are not present in Actionscript that, in the latest release 3.0, has been shown to grow although it is still far from the profile of a good language for object development.

Classes

For example we see how they are differently structured class definitions in ActionScript and Objective-C.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/ / Pakage - for namespacing of Adobe
{pakage
/ / Class definition real
MyClass { public class MyClass {
/ / Definition of ownership (public or private)
myPropertyVar : String ; myPropertyVar public var: String ;
/ / Constructor
MyClass ( ) { public function MyClass () {
/ / Todo
}
/ / Public method
myMethod ( ) : void { public function myMethod (): void {
/ / Todo
}
}
}

In Objective-C, the first difference (inherited from C) is the separation between the "definitions" and the implementation. In Objective-C you are always dealing with two distinct types of files:. H. M (in C we would have. H. C). Files. H (header files) contain only definitions, so no setup or implementation.

1
2
3
4
5
6
7
8
/ / MyClass.h
NSObject { @ Interface myClass: NSObject {
* myPropertyVar; @ Public NSString * myPropertyVar;
}

void ) myMethod; - (Void) myMethod;

@ End

In the file. M we have instead:

1
2
3
4
5
6
7
/ / MyClass.m
@ Implementation myClass

void ) myMethod { - (Void) {myMethod
/ / Todo
}
@ End

Objective-C manages the properties and methods in a way quite different from Actionscript. For example the method myMethod seen above is called (or invoked) in this way:

1
; [Self myMethod];

It speaks, in fact, Sending Message, rather than calling a method!

Note: this feature is real. When you invoke a method in Objective-C is called a physical address or function pointer. In Objective-C object actually sends a real message where they are asked to perform a particular "method"

The syntax with square brackets, perhaps the most difficult to digest even for ANSI C developers, will be clearer and simpler if we consider that:

1
2
3
4
5
6
7
myClass.myMethod ();
/ / Is equal to
; [MyClass myMethod];
/ / Or
; myClass.myPropertyVar = 1978;
/ / Same as
1978 ] ; [MyClass setMyPropertyVar: 1978];

With regard to the creation of objects, then the creation of an instance of a class, we have:

1
MyClass = new MyClass ( ) ; var istanceMyClass: MyClass = new MyClass ();
1
2
3
4
5
6
[ [ MyClass alloc ] init ] ; MyClass * istanceMyClass = [[MyClass alloc] init];
/ / Or simply
[ MyClass alloc ] ; MyClass * istanceMyClass = [MyClass alloc];
/ / Objective-C does support a single manufacturer as
/ / Happens in Actionscript: see for example initWithName,
/ / InitWithFrame or simply init

This is just a simple help, leaving unexplored many other features Objective-C, there are concepts such as pointers (similar to the references in Actionscript - but not identical), protocols, categories and much more. If you are really disheartened in dealing with Objective-C, as I suggested before, by ANSI C games , never mind - for now - Actionscript, Javascript or PHP! The latter, knowing the ANSI C, rediscover them in a light very different.

Comment on: "From Actionscript to Objective-C"

  1. June 18, 2009 Undolog.com "trace Actionscript, Objective-C NSLog () :

    [...] The post From Actionscript to Objective-C (where you put the code and comparing the syntax Actionscript and Objective-C) in Actionscript [...]

Leave a comment

TAG XHTML PERMITS: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Stop SOPA