Swift: Preloading an image and displaying it

Note: Source code (RemoteImage) available on Github Yesterday, I explained how to use the NSURLConnection API to load a remote JSON file. Today I will show you how to use the same API to load a remote image. In fact, the NSURLConnection, similar to URLStream (in AS3) can load pretty much anything, basically it will download raw bytes, once loaded, you are free to do whatever you want with them.

Read more

Swift: Loading and parsing a remote JSON file

Note: Source code (RemoteJSON) available on Github Loading something remotely is a pretty simple task in Flash. We can use the URLStream or URLLoader object, a URL is wrapped inside a URLRequest object, we call the load() API and we are done. So I was wondering what it looks like in Swift and specifically loading a JSON file, which is a common thing to do today, so here is a little snippet

Read more

Swift: ARC vs Flash GC

In ActionScript 3, memory is managed through the help of a garbage collector that allocates and deallocate objects through the application lifecycle. The garbage collector (GC) allocates memory when a new object is created, scans the objects graph periodically, detects unreferenced objects and deallocated them, pretty useful. AS3 is not the only language that relies on garbage collection, C# with Mono, JavaScript or Java all rely on garbage collection. On paper,

Read more

Swift: Overflowing

As you guys know, I always loved playing with binary stuff, and one of the frustrating thing in ActionScript has always been the lack of more granular data types. In ActionScript 3, whatever type you use, it will either occupy 64 or 32 bits in memory, even for a simple boolean. Not super optimized. So if you were to work with a byte (which is 8-bit), the smallest data type you could use

Read more

Swift: Drawing text on bitmap

Note: Source code (DrawingText) available on Github In the last article, we covered the basics of bitmap drawing with Swift and the Quartz/Core Image APIs. As I was playing with that, I wondered how text could be drawn on a bitmap. In Flash, the BitmapData API does not have an API for drawing text, the workaround was to use a TextField offscreen that would be passed to the BitmapData.draw API.

Read more