Quick question on all this. I'm making my model a KVO-compliant class, just to 
see what'll happen. The Apple guide says to implement methods, all of which 
include <key>. I've replaced <key> with TweetsTab, such as countOfTweetsTab, 
and I added tweetsTab (note the lowercase t) to my array controller in the 
Attributes Inspector. What I can't work out is how to tell the controller to 
*use* tweetsTab when it accesses the KVO methods in my model class.

When I go to the bindings inspector for my array controller, I can select a 
controller, set the path (which I set to the instance of my model in my view 
controller), but I can't set the controller key, because that text field is 
refusing to let me edit it. I thought I'd put tweetsTab in here, but that is 
apparently the wrong way to go about it, unless Xcode is doing something funny? 
I hope I'm making sense.
> On Sep 7, 2015, at 08:25, Alex Hall <mehg...@icloud.com> wrote:
> 
> 
>> On Sep 7, 2015, at 02:07, Ken Thomases <k...@codeweavers.com> wrote:
>> 
>> On Sep 7, 2015, at 12:01 AM, Alex Hall <mehg...@icloud.com> wrote:
>> 
>>> My first step is to make a KVO-compliant backing store, because Swift 
>>> arrays won't do the job. As you said, my goal of updating an array and 
>>> having my table automagically update itself to match the array just won't 
>>> happen. What I need is a class that implements the methods described in the 
>>> link you provided,so that bindings will work correctly. Obviously I can use 
>>> an array internally, but the interface of the class *must* offer the 
>>> necessary methods. I'll call this new class MyKVOCClass, because I'm 
>>> terrible at naming things.
>> 
>> It's not particularly that the class must offer the necessary methods.  It's 
>> that your code must use those methods to modify the array or KVO is not 
>> aware of the changes you make.
> 
> That makes sense. I'd be able to just have the model class expose what it 
> needs to, handling all its internals by itself. There's no need for the 
> controller to care which tab is selected or which array something gets added 
> to, because the KVO methods will expose that. If I'm understanding correctly, 
> I would turn my model itself into a KVO-compliant class which would, in the 
> eyes of my array controller, have just one array.
> 
>> It sounds like you're suggesting making a class just to be an array-like 
>> thing that is KVO-compliant.  That sounds to me like you're heading down the 
>> wrong road.  The class which needs to be KVO-compliant is the thing which 
>> currently holds the arrays (even if a bit indirectly).  That brings us to 
>> the next point…
>> 
>>> Next, remember that my model is a dictionary of arrays right now. The model 
>>> has a single variable that can change to point at any of the arrays in the 
>>> dictionary; the table is to display only that selected array (the table is 
>>> view-based, one column, no multi-selecting, no editing).
>> 
>> Can you explain in some more concrete terms why this level of dynamism is 
>> required?  What does the dictionary represent in some real-world sense or 
>> "business logic"?  What do the various arrays represent?  Is there a fixed 
>> set of arrays or is that variable?  What makes one of the arrays current and 
>> what does that signify (other than that's the one shown in the table)?  What 
>> other implications does it have?  What do the arrays have in common?  Why, 
>> other than happenstance or convenience, does it make sense for them to all 
>> be part of the same controller?
> 
> Sure. This is a Twitter app, which shows one type of tweet at a time. That 
> is, the table can show one of home, mentions, DMs, favorites, RTs of the 
> user, Twitter searches, tweets from a different user, etc. When an array is 
> "active", right now it just shows its own tweets in the table, but I hope to 
> do a bit more in the future, like changing the window title to show the tab's 
> name. I'm just starting, so I know a lot of refactoring will have to happen; 
> I'm in the "just get it working" stage.
> 
> My class is TweetDataController, and it currently does *everything* that 
> isn't related to my view. It holds my dictionary of tabs, but it also calls 
> the Twitter framework methods to download new tweets, it posts tweets, it 
> parses them for display, it replaces short URLs with expanded ones in tweet 
> text… I know it's not good to have all that logic in one place, and I was 
> going to refactor it soon, but as I said, I'm still getting things working 
> and seeing how the app--and its internals--will evolve and need to be changed.
> 
> Anyway, the idea behind the dictionary of arrays is that each tab (list of 
> tweets) is an array of Tweet objects, and all the tabs are in the dictionary, 
> accessed by String constants. For instance, when the user hits cmd-4 to show 
> his favorites, the view controller calls 
> TweetDataController.getTabByName(TwitterDataController.favoritesTabName). In 
> the model, currentTab (a string) is set to the favoritesTabName string, and 
> then the view controller reloads the table. Since the active tab has changed, 
> reloading gets the array of tweets for favorites and my table shows favorites.
> 
> I'm not bent on using this setup, it just made sense at the time, and I 
> needed something. This is why I said earlier that I'm using a dictionary, but 
> only need an array controller. It's also why I need that computed property, 
> so that the controller is always pointing at the correct array. I see what 
> you're saying, though: TweetDataController can implement the KVO-specific 
> methods and expose only what it needs to, no need to worry about the active 
> tab. As I said above, the model would then appear to the controller to just 
> be a KVO-ready array.
>> 
>> I'm asking because this design strikes me as one which will cause trouble 
>> and I'm looking for handholds for a suggested refactoring.  I'll wait for 
>> more info before getting into the other stuff.
>> 
>> Regards,
>> Ken
>> 
> 
> 
> --
> Have a great day,
> Alex Hall
> mehg...@icloud.com
> 


--
Have a great day,
Alex Hall
mehg...@icloud.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

Reply via email to