> ## Content Index
> Fetch the complete content index at: https://blogs.remobjects.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Prism Aspects to Help with Monobjc Development
- URL: https://blogs.remobjects.com/2009/02/06/prism-aspects-to-help-with-monobjc-development/
- Published: 2009-02-06T16:39:25.000Z
- Updated: 2018-08-22T06:17:48.000Z
- Author: marc hoffman
- Tags: #Import 2026-08-17 20:17

Joanna Carter wrote a great article for [our wiki](http://prismwiki.codegear.com/?ref=blogs.remobjects.com) about [implementing Key-Value Coding and Cocoa Bindings](http://prismwiki.codegear.com/en/Implementing%5FKey-Value%5FCoding%5Fand%5FCocoa%5FBindings?ref=blogs.remobjects.com) for Monobjc applications, earlier this week.

Key-Value Coding (KVC) and Key-Value Observing (KVO) are based on Objective-C properties, so for something as simple as a one-line property declaration:

| property Name: NSString; |
| ------------------------ |

quite a bit of plumbing code is normally required to expose this property properly for the Objective-C runtime: attributes are needed on the getter and setter methods (which in turn forces us to \*implement\* those, in the first place), and to participate in KVO, notification methods need to be called in the setter as well. The neat little property expands to something like this:

| private fName: NSString;public\[ObjectiveCMessage("name")\]method get\_Name: NSString;partial;\[ObjectiveCMessage("setName:")\]method set\_Name(value: NSString);partial; |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

along with manual implementations for the property getter an setter:

| method Customer.get\_Name: NSString;beginresult:\= fName;end; method Customer.set\_Name(value: NSString);begin WillChangeValueForKey("name"); fName :\= value; DidChangeValueForKey("name");end; |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |

UGH-ly, and a nightmare to maintain – especially once you want to add actual custom logic to the setters, or have a lot of properties in the same class.

With the new support for Aspect Oriented Programming (AOP) code-named “Cirrus” that we’re adding to Delphi Prism (Carlo [just blogged about that](https://blogs.remobjects.com/blogs/ck/2009/02/05/p251) earlier today), i though, why not wrap all of this up in a nice little **aspect**.

So i grabbed the latest internal Prism build (carlo had just finished integrating “Cirrus” into our builds), and just a a few minutes later, the \[ObjectiveCProperty\] aspect was born. It works pretty similarly to the plain attributes that Monobjc provides (such as \[ObjectiveCMethod\] you saw above), and with it, the above properly now looks like this:

| \[aspect:ObjectiveCProperty\]property Name: NSString; |
| ----------------------------------------------------- |

but provides all the functionality of the “long” implementation we saw before. If you look at the generated assembly in Reflector, you’ll see that appropriate \[ObjectiveCMethod\] attributes have been added to the getter and setter methods (even though we never implemented getter/setters ourselves, in this case), and the calls to WillChangeValueForKey/DidChangeValueForKey are present in the setter, as well.

The aspect will work on any property, regardless of whether it uses shortcut declaration, a local field or manually specified getter/setter code. Just slap the aspect on, and the property is exposed to the Objective-C runtime. Optionally, the aspect can also take a different name to expose the property as (by default, it camel-cases the name, so “Foo” becomes “foo/setFoo”), and a boolean parameter to disable KVO.

And, most importantly, all of this is implemented in user code: anyone could write an aspect like this, even though the aspect accomplishes tasks that previously would have required extensive changes to the compiler!

As Carlo [mentioned](https://blogs.remobjects.com/blogs/ck/2009/02/05/p251), “Cirrus” is still in development, and will ship in a future update to Delphi Prism later this year. Don’t quote me on it, but i would *expect* it to be available in the May release.

!\[Cirrus\](http://blogs.remobjects.com/blogs/media/blogs/mh/Cirrus-white2.png "Cirrus")