Re: Array of Dictionaries as .userInfo

2016-01-26 Thread Roland King

> On 26 Jan 2016, at 23:12, Eric E. Dolecki  wrote:
> 
> I have a control which takes an array of dictionaries to construct it's UI
> (as a distinct method).
> 
> Now I'd like to add a notification to supply the data as well. I'd like to
> pass the data as userInfo.
> 
> When constructing the observer method, how do I constuct?
> 
> func weHaveData(notification:NSNoticiation){
>   let dict = notification.userInfo as Array>
>   control.loadData(dict)
> }
> 
> *Can't convert value of type [NSObject:AnyObject]? to
> Array> in coercion*
> 
> I've tried without the cast. Is there an easy work around?
> ___


the userInfo of an NSNotification is an NSDictionary, so of course you can’t 
cast it to an Array. There’s no workaround, they aren’t the same thing at all. 

If you want to pass an Array of Dictionaries in the userInfo, you need to put 
it in the userInfo *dictionary* under a key, then retrieve it, then cast it. 
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Array of Dictionaries as .userInfo

2016-01-26 Thread Eric E. Dolecki
That makes perfect sense - thanks. I forgot about the userInfo type!

On Tue, Jan 26, 2016 at 10:31 AM Roland King  wrote:

>
> > On 26 Jan 2016, at 23:12, Eric E. Dolecki  wrote:
> >
> > I have a control which takes an array of dictionaries to construct it's
> UI
> > (as a distinct method).
> >
> > Now I'd like to add a notification to supply the data as well. I'd like
> to
> > pass the data as userInfo.
> >
> > When constructing the observer method, how do I constuct?
> >
> > func weHaveData(notification:NSNoticiation){
> >   let dict = notification.userInfo as Array>
> >   control.loadData(dict)
> > }
> >
> > *Can't convert value of type [NSObject:AnyObject]? to
> > Array> in coercion*
> >
> > I've tried without the cast. Is there an easy work around?
> > ___
>
>
> the userInfo of an NSNotification is an NSDictionary, so of course you
> can’t cast it to an Array. There’s no workaround, they aren’t the same
> thing at all.
>
> If you want to pass an Array of Dictionaries in the userInfo, you need to
> put it in the userInfo *dictionary* under a key, then retrieve it, then
> cast it.
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Array of Dictionaries as .userInfo

2016-01-26 Thread Clark Cox
The notification’s userInfo *must* be a dictionary, trying to force it to be 
something else is just asking for trouble. You could create a dictionary that 
contains your array of dictionaries if you want to be able to pass it through 
an NSNotification.

That said, IMHO, this use of notifications has a little bit of code smell. 
Ideally, I would expect a notification to tell the control to 
reload/refresh/relayout itself by asking an appropriate delegate or controller 
for the data it needs (rather than getting the data out of the notification 
itself). It helps to have a strictly defined path that your data can follow; if 
it’s in an NSNotification, it could potentially have come from *anywhere*

-- 
Clark Smith Cox III
clarkc...@gmail.com

> On Jan 26, 2016, at 07:12, Eric E. Dolecki  wrote:
> 
> I have a control which takes an array of dictionaries to construct it's UI
> (as a distinct method).
> 
> Now I'd like to add a notification to supply the data as well. I'd like to
> pass the data as userInfo.
> 
> When constructing the observer method, how do I constuct?
> 
> func weHaveData(notification:NSNoticiation){
>   let dict = notification.userInfo as Array>
>   control.loadData(dict)
> }
> 
> *Can't convert value of type [NSObject:AnyObject]? to
> Array> in coercion*
> 
> I've tried without the cast. Is there an easy work around?
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/clarkcox3%40gmail.com
> 
> This email sent to clarkc...@gmail.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Array of Dictionaries as .userInfo

2016-01-26 Thread Eric E. Dolecki
I agree with you there in terms of passing the data in the notification.
I've requested that the developer in charge of some of the appDelegate
backend allow for the explicit data request. It's an extra call or two, but
keeps the pipeline known and clean.

On Tue, Jan 26, 2016 at 10:37 AM Clark Cox  wrote:

> The notification’s userInfo *must* be a dictionary, trying to force it to
> be something else is just asking for trouble. You could create a dictionary
> that contains your array of dictionaries if you want to be able to pass it
> through an NSNotification.
>
> That said, IMHO, this use of notifications has a little bit of code smell.
> Ideally, I would expect a notification to tell the control to
> reload/refresh/relayout itself by asking an appropriate delegate or
> controller for the data it needs (rather than getting the data out of the
> notification itself). It helps to have a strictly defined path that your
> data can follow; if it’s in an NSNotification, it could potentially have
> come from *anywhere*
>
> --
> Clark Smith Cox III
> clarkc...@gmail.com
>
> > On Jan 26, 2016, at 07:12, Eric E. Dolecki  wrote:
> >
> > I have a control which takes an array of dictionaries to construct it's
> UI
> > (as a distinct method).
> >
> > Now I'd like to add a notification to supply the data as well. I'd like
> to
> > pass the data as userInfo.
> >
> > When constructing the observer method, how do I constuct?
> >
> > func weHaveData(notification:NSNoticiation){
> >   let dict = notification.userInfo as Array>
> >   control.loadData(dict)
> > }
> >
> > *Can't convert value of type [NSObject:AnyObject]? to
> > Array> in coercion*
> >
> > I've tried without the cast. Is there an easy work around?
> > ___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >
> > 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:
> > https://lists.apple.com/mailman/options/cocoa-dev/clarkcox3%40gmail.com
> >
> > This email sent to clarkc...@gmail.com
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Array of Dictionaries as .userInfo

2016-01-26 Thread Alex Zavatone
Shouldn't the notification be as dumb as possible and let the notification 
receiver/processor handle any decisions on what to process or read from?


On Jan 26, 2016, at 10:37 AM, Clark Cox wrote:

> The notification’s userInfo *must* be a dictionary, trying to force it to be 
> something else is just asking for trouble. You could create a dictionary that 
> contains your array of dictionaries if you want to be able to pass it through 
> an NSNotification.
> 
> That said, IMHO, this use of notifications has a little bit of code smell. 
> Ideally, I would expect a notification to tell the control to 
> reload/refresh/relayout itself by asking an appropriate delegate or 
> controller for the data it needs (rather than getting the data out of the 
> notification itself). It helps to have a strictly defined path that your data 
> can follow; if it’s in an NSNotification, it could potentially have come from 
> *anywhere*
> 
> -- 
> Clark Smith Cox III
> clarkc...@gmail.com
> 
>> On Jan 26, 2016, at 07:12, Eric E. Dolecki  wrote:
>> 
>> I have a control which takes an array of dictionaries to construct it's UI
>> (as a distinct method).
>> 
>> Now I'd like to add a notification to supply the data as well. I'd like to
>> pass the data as userInfo.
>> 
>> When constructing the observer method, how do I constuct?
>> 
>> func weHaveData(notification:NSNoticiation){
>>  let dict = notification.userInfo as Array>
>>  control.loadData(dict)
>> }
>> 
>> *Can't convert value of type [NSObject:AnyObject]? to
>> Array> in coercion*
>> 
>> I've tried without the cast. Is there an easy work around?
>> ___
>> 
>> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
>> 
>> 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:
>> https://lists.apple.com/mailman/options/cocoa-dev/clarkcox3%40gmail.com
>> 
>> This email sent to clarkc...@gmail.com
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> 
> This email sent to z...@mac.com


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: Array of Dictionaries as .userInfo

2016-01-26 Thread Eric E. Dolecki
Yes probably in most cases. One can send an object and a NSDictionary
(userInfo) though too. So there are some implied options. I was about to
over-use my userInfo ;)

On Tue, Jan 26, 2016 at 11:46 AM Alex Zavatone  wrote:

> Shouldn't the notification be as dumb as possible and let the notification
> receiver/processor handle any decisions on what to process or read from?
>
>
> On Jan 26, 2016, at 10:37 AM, Clark Cox wrote:
>
> > The notification’s userInfo *must* be a dictionary, trying to force it
> to be something else is just asking for trouble. You could create a
> dictionary that contains your array of dictionaries if you want to be able
> to pass it through an NSNotification.
> >
> > That said, IMHO, this use of notifications has a little bit of code
> smell. Ideally, I would expect a notification to tell the control to
> reload/refresh/relayout itself by asking an appropriate delegate or
> controller for the data it needs (rather than getting the data out of the
> notification itself). It helps to have a strictly defined path that your
> data can follow; if it’s in an NSNotification, it could potentially have
> come from *anywhere*
> >
> > --
> > Clark Smith Cox III
> > clarkc...@gmail.com
> >
> >> On Jan 26, 2016, at 07:12, Eric E. Dolecki  wrote:
> >>
> >> I have a control which takes an array of dictionaries to construct it's
> UI
> >> (as a distinct method).
> >>
> >> Now I'd like to add a notification to supply the data as well. I'd like
> to
> >> pass the data as userInfo.
> >>
> >> When constructing the observer method, how do I constuct?
> >>
> >> func weHaveData(notification:NSNoticiation){
> >>  let dict = notification.userInfo as Array>
> >>  control.loadData(dict)
> >> }
> >>
> >> *Can't convert value of type [NSObject:AnyObject]? to
> >> Array> in coercion*
> >>
> >> I've tried without the cast. Is there an easy work around?
> >> ___
> >>
> >> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >>
> >> 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:
> >> https://lists.apple.com/mailman/options/cocoa-dev/clarkcox3%40gmail.com
> >>
> >> This email sent to clarkc...@gmail.com
> >
> >
> > ___
> >
> > Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> >
> > 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:
> > https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com
> >
> > This email sent to z...@mac.com
>
>
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com