Swarm FAQ:Writing Objective C
From SwarmWiki
Q: What is this Objective C language?
A: For information on Objective-C see:
NOTE: You will see a lot of documentation on Apple's web site about 'Cocoa'. You should ignore this. Cocoa and Swarm are like different dialects of the Objective-C language. (Cocoa is used by Apple to write a lot of software for the Macintosh) A number of classes and methods in the two dialects have similar functions but different names. If you read documentation or books on Cocoa it will confuse you when you try to use Swarm.
Q: Are there variants on the Objective C language?
A: There are two possible issues under this heading:
1. Objective-C 2.0 Apple is promising an update of Objective-C to ship with the new MacOS X 10.5 Leopard in 2007. It is unlikely that Swarm will support the new variant, but at this stage we cannot be sure because details are not available.
2. Messages to nil It is normal in Objective-C that messages sent to nil objects are accepted and return nil if the return type is an object or int. In Swarm code, messages to nil tend to be the result of errors in programming. So some Swarm binaries will treat them as errors. This behaviour may change. Please let us know on the support mailing list if you have views on this.
Q: Why does my Swarm code (or Swarm demos) no longer compile in Linux?
Do you have one of these problems with a newer Linux system?
- Old code (including some of the demo models packaged with Swarm) no longer compiles.
- Code that compiles in Swarm on Windows does not compile in Linux.
- There are many more warning statements even when the code compiles.
The explanation is that newer Linux/Unix systems now have versions of the gcc compiler (gcc 4.0.0 and higher) that are less forgiving. You must simply debug the code to make it compatible with gcc 4+'s tighter rules.
The official documentation of gcc changes are at: http://gcc.gnu.org/gcc-4.0/changes.html.
Swarm users have found differences such as:
- Object typing: You may have to be more careful about specifying the class of an object variable. You may no longer be able to do things like handle an object as an ID sometimes and as an instance of a particular class other times.
- Variable typing: You may no longer be able to do things like declare a variable a BOOL in one place and treat it as UNSIGNED in another place.
- You may no longer be able to use probes to change the value of variables declare as "const".
- You may need to import libraries (including standard libraries like stdlib) in both the .m and .h file, instead of just in the .h file.
- Some "lvalue" constructs are no longer valid: casts of a variable as "lvalue" must be on the right side of an assignment statement, not on the left.
- Nested functions are not allowed on Apple's version of gcc 4+. (Or: they require special effort to use; see: http://developer.apple.com/technotes/tn2006/tn2161.html )
![[Main Page]](/stylesheets/images/wiki.png)