Re: Basics of Cocoa Bindings

2015-09-09 Thread Quincey Morris
(reposted to the list in 2 parts because the whole thing was 1 byte over the 
stupid limit)

On Sep 8, 2015, at 21:04 , Alex Hall mailto:mehg...@icloud.com>> wrote:
> 
> and too little comprehension of how bindings work

I think it’s both easier than you think, and harder. Bindings are not actually 
very interesting — to use, that is. (Implementing new ones properly is a bit of 
a challenge, but it is almost never done any more, because bindings are ancient 
and nearly obsolescent technology. We use them because they work, and because 
there’s nothing to take their place, but they were designed for the kind of 
Interface Builder (IB) we had in 10.3 days, or perhaps even further back into 
the NeXT days.)

Technically, bindings are two-way links between two different properties of 
objects in two different classes. When either property value changes, the 
binding ensures that the other property changes to match. That’s about it.

However, what bindings *are* is pretty much beside the point. What matters is 
how they’re *used*, and for that you need to keep in mind what IB is all about. 
IB is a design tool, not a programming language, so is has a lot of inspectors 
where you can enter information — mostly strings that are *names* representing 
entities that are present only at run time.

In addition, IB allows you to define relationships between elements, sometimes 
by using controls in inspectors, but often by manipulating a graphical 
representation of the UI. Incidentally, I know you know all this part, I’m just 
trying to layout it all out in sequence.

In your code, by contrast, you have instances, you have methods, and you have 
logic, courtesy of the Obj-C language. (Swift doesn’t change anything 
fundamental about this, so I’m ignoring it.) As you know, you generally have a 
choice of implementing UI elements via code or via IB, and it’s usually easier 
to use IB because IB is usually better at expressing UI relationships. That 
leads to a problem — how do you adapt the pure data you enter into IB at design 
time to the Obj-C runtime that’s all there is at … well, run-time?

The solution is to snap together a series of pieces, like interlocking 
children’s blocks, with an IB piece at one end and an Obj-C piece at the other. 
Let’s say the data pieces at the IB end are plastic blocks like Lego, and the 
code pieces at the Obj-C end are metal components like in an erector set. A 
binding is a piece that connects one piece to another, sure — see the above 
definition — but more importantly it’s a piece that *adapts* plastic to metal.

Bindings are not the only such adapters. IB outlets are adapters (one way only, 
metal to plastic). IB actions are adapters (also one way, but plastic to 
metal). Control delegates are adapters. Table view data sources are adapters. 
The trick is to find the correct sequence of adapters for each job, and as I 
said already, these days we mostly just choose from a pretty short list of 
adapter patterns. Bindings are probably the cleverest of the adapters, and I 
think the only kind of adapter that’s two-way.

So, how do bindings work as adapters? Although bindings are bi-directional, in 
correct usage we say that a binding connects *from* a UI element (plastic) *to* 
a data model value (metal). Bindings keep track of a list of property names — 
at least two, because there’s always a from and a to — which we usually write 
from left to right, though they're easier to follow from right to left, from 
plastic to metal. A bound UI element takes its value from the *last*-named 
binding component, applied to an object whose identity the binding knows. That 
object is determined by applying the next-to-last component to another object 
the binding knows about. And so on, along the sequence from plastic until it 
hits genuine metal.

That’s about all there is to bindings, apart from details. As it happens, each 
UI element can be bound only to certain categories or functions of model 
object. (I’m not using those terms in the Obj-C technical sense.) IB contains 
an internal list of what binds to what, and it won’t let you bind things that 
shouldn’t be bound. You know this list from the popup menu in the Bindings 
inspector in IB — it’s usually a very short list for any given element.

Notice that I’ve said nothing yet about NS…Controller. (For the sake of the 
current discussion, I’ll just say NSControllers, though the general principles 
apply to all NSController subclasses, including array controllers.) How do they 
relate to bindings? In a very real sense, they don’t — they’re something else — 
they are in fact a separate kind of adapter. Unfortunately, in practice, 
NSController and bindings are all tangled up together in a confusing mess. 
Let’s try to avoid the tangle, or the confusion, as long as we can.

NSControllers are another piece of obsolescent 10.3-era technology, and I think 
I should disclose that I hate them with a passion, even as I’m forced to use 
them. The n

Re: Basics of Cocoa Bindings

2015-09-09 Thread Quincey Morris
(continued from part 1)

The clever thing about array controllers is that to metal pieces they look like 
plastic, and to plastic pieces they look like metal. Hence the name 
“mediating”. As in legal arbitration, the mediator looks to each side like the 
opposing side’s advocate. Their other generally useful characteristic is that 
IB recognizes them as “metal” targets for bindings, which is why array 
controllers tend to appear in those Bindings inspector popups (usually — there 
are exceptions to everything).

That’s what controllers are — adapters. They are a common generalization or 
abstraction that permits IB to connect pretty much any UI element indirectly to 
pretty much any model object. IB is so filled with admiration for them that it 
gives some of their standard properties (selection, arrangedObjects, etc) 
special placement in the Bindings inspector so that you can just choose the 
“controller key” from a menu without having to type it. There’s a whole 
digression possible here about the nature of these properties — some like 
“selection” are proxy objects, others like “selectedObjects” are true 
properties of the array controller — but I’m not going to digress. Controller 
keys are just preset initial components of a bindings component sequence. The 
rest of them are called “model keys”.

I don’t think you ever *need* an array controller, except perhaps where you 
need to get to a data model via a route that IB doesn’t recognize. Remember, to 
plastic, array controllers look like metal. You don’t actually *need* an array 
controller between a table view and a data model, but 99.9% of the time it’s 
easier just to go ahead stick one in the chain. Also, if you have multiple 
table views, you can connect them with array controllers into a single sequence 
that cascades the data out with no actual code.

Hmm, I just realized that what I said about table views is kind of old-school. 
It really only applies to cell-based table views. When it comes to view-based 
table views, I think I’ll just go ahead and risk offending the purists I 
haven’t offended yet by saying that binding view-based table view content *at 
all* is a waste of time, with or without an array controller. (By contrast, 
binding table cell subviews via the table cell view is absolutely the right 
thing to do.) Binding content is just awkward to do with view-based table 
views, and it saves you very little code. (It *may* eliminate the data source, 
but you must have a table view delegate anyway, and that’s where most of the 
code is.)

I was also going to talk a little bit about KVC and KVO, which is where you 
find topics like accessors, and the dreaded keyPathsForValuesAffecting 
(which is actually just a convenient shortcut to KVO compliance in some 
standard cases). In fact — er, here go the purists over the cliff again — 
bindings actually have very little to do with KVC, if you look at it right.

It’s true that, in practice, one of a binding’s two directions is always 
implemented using KVO. But you can treat this as an implementation detail and 
forget about it.

It’s also true that a requirement for bindings is that *every* component of the 
sequence of name strings (keys) *must* be a KVO-compliant property of the 
relevant object. That’s a draconian requirement or a natural outcome depending 
on your point of view. When you implement a data model for your app, you 
*should* IMO ensure that all of its properties are KVO-compliant just because 
it’s the right thing to do. For scalar (one-to-one, non-collection properties), 
it’s usually trivial. For one-to-many (collection) properties, it’s a few lines 
of boilerplate to implement a couple of accessor methods with predetermined 
names (usually just an insert accessor and a remove accessor).

If you follow this principle, then you can go hog wild binding things in your 
NIB files or storyboards, throwing in the occasional NSController to 
“metallicize” an attachment point that IB doesn’t otherwise recognize. 
(Incidentally, this is pretty much all that NSObjectController is good for. It 
has one other subtle but useful capability — it implements the NSEditor family 
of informal protocols — but other than that it’s pretty much dead weight.)

The only time you’d skip KVO compliance in a data model property is when the 
value changes outside your control, in a way that’s hard to monitor. If you can 
convince yourself you’ll never want to bind to, or observe, that property, go 
ahead and skip compliance. Otherwise, you’re going to save yourself grief later 
if you keep trying until you find a way of making it compliant.

I’ve gone on quite a long rant here, too long probably, though I tried to 
jettison every detail I felt I could do without. I hope it clarifies at least 
some things, without repeating a lot of things you already know. If there’s an 
executive summary, I guess I’d say it’s this: bindings, NSControllers and 
KVC/KVO are all core Cocoa competencies, but they’re thr

Auto Layout Log Warning Message

2015-09-09 Thread Dave
Hi,

I made some changes and now I’m getting the following error message:

2015-09-09 13:26:34.424 LTWALTest1[16833:6675944] Layout still needs update 
after calling -[NSScrollView layout].  NSScrollView or one of its superclasses 
may have overridden -layout without calling super. Or, something may have 
dirtied layout in the middle of updating it.  Both are programming errors in 
Cocoa Auto-layout.  The former is pretty likely to arise if some pre-Cocoa 
Auto-layout class had a method called layout, but it should be fixed.

I don’t have layout defined in any of my own classes and I wasn’t getting this 
error before I updated a view and added some extra controls. I don’t get any 
XCode/IB errors or warning but I get the above message in the console?

Should I ignore it? If not how to fix it?

Thanks a lot
Dave


___

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: Progress Bar Gripe

2015-09-09 Thread Jens Alfke

> On Sep 8, 2015, at 11:28 PM, Michael David Crawford  
> wrote:
> 
> I invite you to continue our friendly debate.

Then start a blog, enable comments, and post about these topics there. 
Cocoa-dev is not the right forum for high-level debate about Apple’s bug 
reporting/fixing policies or progress-bar UI.

—Jens
___

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: Handling close with multiple document windows

2015-09-09 Thread David Durkee
Thanks, Quincey and Mike, I wasn’t expecting it to be so simple!

David

> On Sep 8, 2015, at 4:52 PM, Quincey Morris 
>  wrote:
> 
> On Sep 8, 2015, at 14:40 , David Durkee  > wrote:
>> 
>> I haven’t been able to find a way to make trying to close the main window 
>> try to close the document even if the secondary window is open.
> 
> Set the ‘shouldCloseDocument’ property of the *main* win controller to YES.
> 

___

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

Setting the position of a NSScrollView

2015-09-09 Thread Dave
Hi All,

I’m using the code below to set the position of a Scroll View:

NSPoint pt = NSMakePoint(0,[[self.pValidationIssueScrollView documentView] 
bounds].size.height);
[[self.pValidationIssueScrollView documentView] scrollPoint:pt];

However it doesn’t seem to do anything. The Clip View of the NSScrollView is 
Flipped, does this make a difference? Also there is an NSStackView inside the 
Clip View. 

Any ideas why this is not working?

Thanks a lot for any help,
Dave


___

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

Setting the position of a NSScrollView

2015-09-09 Thread Dave
Also tried:

NSPoint myScrollPosition;

myScrollPosition = NSMakePoint(0,0);
[[self.pValidationIssueScrollView documentView] scrollPoint:myScrollPosition];

This is being called in windowDidLoad but I’ve also tried calling it in 
awakeFromLib


___

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

Setting the position of a NSScrollView

2015-09-09 Thread Dave
Found it!

-(void) scrollToTopOfScrollView:(NSScrollView*) theScrollView
{
NSPoint myScrollPosition;

if ([[theScrollView documentView] isFlipped] == YES) 
myScrollPosition = NSMakePoint(0.0,0.0);
else
myScrollPosition=NSMakePoint(0.0,NSMaxY([[theScrollView documentView] 
frame]) - NSHeight([[theScrollView contentView] bounds]));

[[theScrollView documentView] scrollPoint:myScrollPosition];
}
 
-(void) scrollToBottomOfScrollView:(NSScrollView*) theScrollView
{
NSPoint myScrollPosition;
 

if ([[theScrollView documentView] isFlipped] == YES) 
myScrollPosition=NSMakePoint(0.0,NSMaxY([[theScrollView documentView] 
frame]) - NSHeight([[theScrollView contentView] bounds]));
else
myScrollPosition = NSMakePoint(0.0,0.0);

[[theScrollView documentView] scrollPoint:myScrollPosition];
}



___

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

Swift: combining Obj-C enums

2015-09-09 Thread Rick Mann
I've not found a succinct way to do this. Is there one?

let files = try fm.contentsOfDirectoryAtURL(inFile,
includingPropertiesForKeys: nil,
options: 
.SkipsSubdirectoryDescendants | .SkipsPackageDescendants | .SkipsHiddenFiles)


TIA,

-- 
Rick Mann
rm...@latencyzero.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: Swift: combining Obj-C enums

2015-09-09 Thread Greg Parker

> On Sep 9, 2015, at 6:28 PM, Rick Mann  wrote:
> 
> I've not found a succinct way to do this. Is there one?
> 
>let files = try fm.contentsOfDirectoryAtURL(inFile,
>   includingPropertiesForKeys: nil,
>   options: 
> .SkipsSubdirectoryDescendants | .SkipsPackageDescendants | .SkipsHiddenFiles)

In Swift 2 this is an OptionSetType. An option set literal looks like this:

[.SkipsSubdirectoryDescendants, .SkipsPackageDescendants, .SkipsHiddenFiles]


-- 
Greg Parker gpar...@apple.com Runtime Wrangler



___

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: Swift: combining Obj-C enums

2015-09-09 Thread Rick Mann

> On Sep 9, 2015, at 18:43 , Greg Parker  wrote:
> 
> 
>> On Sep 9, 2015, at 6:28 PM, Rick Mann  wrote:
>> 
>> I've not found a succinct way to do this. Is there one?
>> 
>>   let files = try fm.contentsOfDirectoryAtURL(inFile,
>>  includingPropertiesForKeys: nil,
>>  options: 
>> .SkipsSubdirectoryDescendants | .SkipsPackageDescendants | .SkipsHiddenFiles)
> 
> In Swift 2 this is an OptionSetType. An option set literal looks like this:
> 
>[.SkipsSubdirectoryDescendants, .SkipsPackageDescendants, 
> .SkipsHiddenFiles]

Ah, thank you! (And thanks for the rapid reply!)

-- 
Rick Mann
rm...@latencyzero.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

Display USB Video Camera output : AVFoundation?

2015-09-09 Thread Jerry Krinock
In a Mac app, I need to display real-time video (as in “movies”) from a USB 
camera on the screen.  Can someone please confirm that AVFoundation the way to 
go?

I’ve read that QTKit is deprecated but, oddly, I cannot find any mention of 
deprecation here in the QTKit Programming Guide:

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/QTKitApplicationProgrammingGuide/

Thank you,

Jerry


___

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: Display USB Video Camera output : AVFoundation?

2015-09-09 Thread Jens Alfke

> On Sep 9, 2015, at 9:22 PM, Jerry Krinock  wrote:
> 
> In a Mac app, I need to display real-time video (as in “movies”) from a USB 
> camera on the screen.  Can someone please confirm that AVFoundation the way 
> to go?

I can confirm that it’s easy to use AVFoundation to display live video from the 
built-in webcam on a MacBook Pro. I would guess that it also works for other 
cameras recognized by the OS; the standard live-video view has a control to 
switch the input source.

—Jens
___

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: Display USB Video Camera output : AVFoundation?

2015-09-09 Thread Shane Stanley
On 10 Sep 2015, at 2:22 pm, Jerry Krinock  wrote:
> 
> In a Mac app, I need to display real-time video (as in “movies”) from a USB 
> camera on the screen.

Have a look at the sample code AVRecorder.

-- 
Shane Stanley 



___

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: Display USB Video Camera output : AVFoundation?

2015-09-09 Thread Quincey Morris
On Sep 9, 2015, at 21:22 , Jerry Krinock  wrote:
> 
> I’ve read that QTKit is deprecated but, oddly, I cannot find any mention of 
> deprecation here in the QTKit Programming Guide:

The lack of a mention of deprecation isn’t so odd if you scroll to the bottom 
of the page and note that the last update was in 2009. It’s worth training 
yourself to check the update date before you believe anything you read in any 
of the programming guides. (And at the speed things change, I’d avoid believing 
any document that’s more than 2 or 3 years old. It’s getting to the point where 
the only trustworthy documents are those written in the future.)

If you follow the links through to specific QTKit classes, you’ll see that 
absolutely everything was deprecated in 10.9, except for the QTMovieModernizer 
class, which was added in 10.9.


___

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: Display USB Video Camera output : AVFoundation?

2015-09-09 Thread Britt Durbrow
One of my projects (still on the back burner at the moment, but slowly 
progressing nonetheless) is a DIY pick-and-place machine for doing small-run 
electronics. It uses standard VGA-quality  USB webcams (such as the type that 
you can get off of eBay for under $10 each… often under $4) to do the 
component-detection machine vision; and I do have the video input section of 
the project seeing the webcams with AVFoundation.

So if that’s the kind of camera in question… yeah, it works.

:-)

> On Sep 9, 2015, at 9:22 PM, Jerry Krinock  wrote:
> 
> In a Mac app, I need to display real-time video (as in “movies”) from a USB 
> camera on the screen.  Can someone please confirm that AVFoundation the way 
> to go?
> 
> I’ve read that QTKit is deprecated but, oddly, I cannot find any mention of 
> deprecation here in the QTKit Programming Guide:
> 
> https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/QTKitApplicationProgrammingGuide/
> 
> Thank you,
> 
> Jerry
> 
> 
> ___
> 
> 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/bdurbrow%40rattlesnakehillsoftworks.com
> 
> This email sent to bdurb...@rattlesnakehillsoftworks.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