Re: ObjC question
Re: ObjC question
- Subject: Re: ObjC question
- From: Aaron Burghardt <email@hidden>
- Date: Sun, 11 Apr 2010 06:49:51 -0400
On Apr 10, 2010, at 9:11 PM, Seth Willits wrote:
> On Apr 10, 2010, at 5:11 PM, Tony Romano wrote:
>
>> When you create the file system event, you can pass a void * via the structure which is accessible in the event callback. In this pointer, I want to pass my Volume object so I know which volume the event was for. I could have easily passed the volume object pointer in when I create the FileSystemEvent object but I always like to stretch my thinking.
>
>
> I'm not sure how this relates to your previous question. I think you may have misspoken/left something out above.
>
> I'm guessing you meant that when you setup the FSEvent callback, you're passing in the FileSystemEvent object instead of the Volume object? In the callback, in order to use the Volume, the FileSystemEvent would need a reference to the Volume. Otherwise you'd need to pass the volume to the callback and get the FileSystemEvent object from the Volume.
>
> Additionally, you could also create a struct which separately contains references to both the FileSystemEvent and the Volume if for some reason you don't have and don't want a reference to the Volume in the FileSystemEvent.
>
Assuming Seth described your intentions correctly and your goal is to encapsulate the FSEvent functions within an object, perhaps you want to consider a delegate pattern.
1. Add an property to FileSystemEvent named "delegate".
2. When Volume creates a FileSystemEvent, it sets itself as the delegate.
3. In the FSEvent callback function, get the delegate from the FileSystemEvent and send it the appropriate message(s).
That way, your usage of FSEvent functions is contained within the FileSystemEvent class, and you have a design pattern that follows Cocoa conventions. Conceptually, it also illustrates that FileSystemEvent may have other uses outside of the Volume class. This is essentially a rephrasing of the "initWithContainer:" sample code that Kevin suggested.
Aaron
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden