On the heel of interface declaration syntax we looked at earlier, today I’m going to talk briefly about properties.
Officially, Apple calls properties as declared properties. Coming from a C# background, the first thing that springs to mind is declared properties are just like auto-implemented properties in C#. In a way, it’s similar but declared properties can have a lot of different behaviours beyond making them read-only. You can also specify the setter semantic and atomicity (critical in a multithreaded environment).
Creating a property is a two-step process. First you have to declare it in the class interface and then in the implementation.
@interface MyClass : NSObject
{
CGImageRef myImage;
}
@property(retain, nonatomic) CGImageRef myImage;
@end
@implementation MyClass
@synthesize myImage;
@end
In the snippet, the property’s name is myImage and is of type CGImageRef. The words inside the brackets, retain and nonatomic, are its attributes. It indicates that when myImage is assigned to a new value, its own values should receive a release message while retain is invoked on the new value. nonatomic allows the getter to be interrupted by another thread. This is generally not a good idea unless you want to performance benefit and are sure there is no race condition.
In the implementation, @synthesize keyword is used to let he compiler generate the necessary getter and setter methods.
In this example, the property has the same name as the instance variable but you can specify a different name by specifying something like this.
@synthesize ThisImage = myImage;
In this way, the instance variable is myImage while the property name is now ThisImage.
One last note, in objective-C, you don’t get the dot (.) notation that’s the standard way of accessing instance(class) methods and variables. You have to rely on the notion of message passing syntax.
[theClass myImage];
Assuming theClass is the object of the type MyClass, with the introduction of declared properties, you GET dot notation and therefore, theClass.myImage works. Hooray!!! Except, come on guys, so much for bringing the language to the 90s (or even 80s).
Ian Blackburn 3:02 pm on June 26, 2009 Permalink |
Nice comparison – thanks!
Couple of point on Silverlight – it is not limited to WCF services – you can use REST, sockets, POX pretty much anything you want; and I am not exactly sure what you mean by streaming, but I think Silverlight has most of those bases covered too…
Cheers
Ian
Simone 8:43 am on July 4, 2009 Permalink |
Good comparison… I’d like to point out a few little imprecision:
UI Controls: HTML5+JS has many not rudimentary UI controls… take a look at all the jQuery UI controls, or also the ones that come with the ASP.NET Ajax control toolkit, or ExtJS and so on… they don’t come out of the box with the “language”, but it’s easy to add them
Offline mode and local storage: HTML5 has both offline mode and local storage, naively