IntroductionThis article details the steps taken in creating the iPad port of the libswift library. Attached to this article is a proof-of-concept application. Required softwareTo build applications for the iPad, the best way is to use a Mac with XCode. You need the (at least) IOS 4 SDK, which will only run on Mac OS X 10.6 (Snow leopard). To retrieve the libswift code, it is easiest to use git for Mac, for which an installer is available here. Compiling libswiftApplications for the iPad are written in Objective-C, and source files use the extension .m. There also exists a variant called Objective-C++, which allows mixing of Objective-C and C++. Files which are to be compiled as Objective-C++ files should have the extension .mm. Therefore, the first thing to do after creating a new project is to rename any files which will call C++ code (i.e. the libswift code) to have the .mm extension. The next step is to import the libswift source files into the project. Make sure you only import the necessary source files, and not all the tests, documentation, and the .git directory. To call the libswift library, you need to include the swift.h header file. However, this only works correctly if done in a .mm file, or in a header file which is only included by .mm files. Note that libswift uses its own namespace (swift). So either you have to include a "using namespace swift;" line, or prepend libswift symbols with "swift::". Miscellaneous infoNetworking on the iPad can be done with the standard Unix socket API. All calls like socket, sendto, recvfrom, select, getsockname etc. are available. Threading on the iPad does not use the POSIX threading interface, but instead uses an Objective-C based threading (see this tutorial). One of the things to be careful about is dead-locks (obviously). Using the NSOperation-based threading, it is very easy to create one. When using the performSelectorOnMainThread method, the last argument is whether to wait for completion. This can be used to prevent race conditions, but can easily lead to dead-lock as well. For example, when cancelling a thread and then waiting for all threads to finish (as is done in stopDownload in the proof-of-concept), also trying to wait for completion of the method called on the main thread will cause a dead-lock. When using XCode and the iPhone simulator (which also simulates iPads), standard output and standard error are available in the console (Run -> Console). Any uncaught exceptions are also shown here. Arno Notes
Attachments
|