Re: Data, enumerateBytes: separate blocks?

2017-12-27 Thread Daryle Walker
> On Dec 25, 2017, at 2:09 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> So, if your goal is to minimize searching, you have to search for CR and LF 
> simultaneously. There are two easy ways to do this:
> 
> 1. Use “index(where:)” and test for both values in the closure.
> 
> 2. Use a manual loop that indexes into a buffer pointer (C-style).
> 
> #1 is the obvious choice unless invoking the closure is too slow when a lot 
> of bytes need to be examined. #2 would use “enumerateBytes” to get a series 
> of buffer pointers efficiently, but there is no boundary code to be tested, 
> since you’re only examining 1 byte at a time.
> 
> Once you have the optional indices to the first CR or LF, and you find you 
> need to check for a potential CR-LF or CR-CR-LF, you can do that by 
> subscripting into the original Data object directly, outside of the search 
> loop.
> 
> This approach would eliminate the problematic test case, and (unless I’m 
> missing something obvious) have the initial search as its only O(n) 
> computation, everything else being O(1), i.e. constant and trivial.
> 

Right now I have:

> guard let firstBreak = index(where: {
> [MyConstants.cr, MyConstants.lf].contains($0)
> }) else { return nil }
> 
> let which: Terminator
> switch self[firstBreak] {
> case MyConstants.cr:
> let nextBreak = index(after: firstBreak)
> if nextBreak < endIndex {
> switch self[nextBreak] {
> case MyConstants.cr:
> let nextBreak2 = index(after: nextBreak)
> if nextBreak2 < endIndex {
> if self[nextBreak2] == MyConstants.lf {
> which = .crcrlf
> } else {
> which = .cr
> }
> } else {
> which = .cr
> }
> case MyConstants.lf:
> which = .crlf
> default:
> which = .cr
> }
> } else {
> which = .cr
> }
> case MyConstants.lf:
> which = .lf
> default:
> preconditionFailure("The search from 'index' should never find 
> anything outside {CR, LF}.")
> }
> return (which, firstBreak)


In my basic test suite, the property is called 37 times. The guard’s return is 
hit 4 times, and the outer switch 33 times. For that outer switch, the CR case 
is hit 25 times, the LF case 8 times, and that default I had to put in 0 times. 
Within the CR case, the individual results are hit 4, 6, 3, 5, 5, and 2 times 
respectively.

However, the guard’s contain test is covered 192 times! I’m guessing that’s 
once for each byte the code goes past, right? Between that and wondering how 
efficient the test is, I wonder if using something like [2] would be better. 
But I would test a megabyte at a time or something. Now I have to figure out 
how to divide a range to a set of subranges (of a set size, except possibly the 
last). And how would I test which way is faster?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Data, enumerateBytes: separate blocks?

2017-12-25 Thread Daryle Walker

> On Dec 24, 2017, at 3:51 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Dec 24, 2017, at 04:45 , Charles Srstka <cocoa...@charlessoft.com 
> <mailto:cocoa...@charlessoft.com>> wrote:
>> 
>> you could consider making its interface take generic collections of UInt8
> 
> This would not solve the *general* problem Daryle raised. He’s looking for a 
> way to test the logic of some buffer-boundary-crossing code, which makes 
> sense only if he has multiple buffers, which means he must be using 
> “enumerateBytes”, which not supported by Collection. If he doesn’t use 
> enumerateBytes, then he doesn’t need anything but Data anyway.
> 
> However, considering what appears to be the *actual* problem (finding the 
> first CR or CR-LF or CR-CR-LF separator in a byte sequence), he could use 
> Data without using enumerateBytes, and still not risk copying the data to a 
> contiguous buffer.
> 
> This solution would use Data’s “index(of:)” to find the first CR, then a 
> combination of advancing the index and subscripting to test for LF in the 
> following 1 or 2 positions.

Not quite.

My first versions of this idea, pre-Swift and therefore using NSData with 
Objective-C, did use the direct search functions that come with the NSData API. 
There seems to be a detail you missed in my sample code that explains the use 
of “enumerateBytes”:

LF-only is also a searched-for separator.

That means no matter what, I must find the first CR and the first LF. Then I 
compare their relative positions (and check for another CR if the spacing is 
right). What happens if whichever byte value is second is gigabytes away from 
the first? (Or equivalently, only one value is present and there’s gigabytes of 
trailing data to fail to find the other value.) I would end up wasting the 
user’s time for a second result I’d never use.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Data, enumerateBytes: separate blocks?

2017-12-23 Thread Daryle Walker

> On Dec 22, 2017, at 2:18 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Dec 22, 2017, at 08:48 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> DispatchData would need to be convertible to Data.  Is there a way to do the 
>> conversion in Swift?
> 
> Actually, on consideration, I think not. It would be if DispatchData was 
> bridgeable like Data, but it isn’t, and I don’t see any way of extracting its 
> underlying reference. This leaves you with two options that I can see:
> 
> 1. Use an Obj-C helper function, taking an array of input buffers, and 
> returning a dispatch_data_t object that combines them, cast to a NSData*. You 
> can then use the returned reference as Data.
> 
> 2. Move your Data extension to DispatchData. That’s what I was asking about 
> earlier — is there any reason why you couldn’t just use DispatchData rather 
> than Data, in all the code that deals with this data set? In that case, you 
> can just build the DispatchData in Swift.
> 
> IAC, you should probably submit a bug report. Since dispatch_data_t is 
> documented to be a subclass of NSData, there should probably be a mechanism 
> for getting Data and DispatchData values as equivalents of each other, 
> without any unprovoked copying of the underlying data.

This code is not for private use within an app, but for something I plan to 
publicize as a library on GitHub. So the interface has to stay as using Data. 
(Fortunately, this part of the interface, an extension to Data, is private.) 
DispatchData and Data don’t even have a custom shared interface (just the 
general RandomAccessCollection) I could use here to not repeat myself in 
implementation.

The library doesn’t need DispatchData, just my test case (and only as posing as 
a Data instance). It doesn’t seem I can do it without heroic measures by making 
a mixed Swift/Objective-C test project. And even if that is possible, I don’t 
even know if the Swift Package Manager supports it.  So I have to let my 
meticulous side get bothered by the red-0-calls under Code Coverage mocking me 
until this is fixed somehow.

Bug #36204480 (“DispatchData IS-NOT-A Data in Swift”).

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Data, enumerateBytes: separate blocks?

2017-12-22 Thread Daryle Walker
> On Dec 21, 2017, at 11:10 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Dec 21, 2017, at 18:04 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> when multiple blocks are used
> 
> At this point, I don’t understand what you don’t understand. Here’s a code 
> fragment that works in a playground:
> 
>> import Foundation
>> 
>> let buffer1: [UInt8] = [1,2]
>> let buffer2: [UInt8] = [3,4,5,6]
>> 
>> var data = DispatchData.empty
>> data.append (buffer1.withUnsafeBytes { DispatchData (bytesNoCopy: $0) })
>> data.append (buffer2.withUnsafeBytes { DispatchData (bytesNoCopy: $0) })
>> 
>> print (data.count)
>> data.enumerateBytes {
>>  bytes, index, stop in
>>  print (bytes.count, index, bytes [0])
>> }
> 
> producing this output:
> 
>> 6
>> 2 0 1
>> 4 2 3
> 
> Isn’t this what you were asking for: a loop enumerating each of the 
> contiguous portions of a larger data set?

I already have the code as an extension of Data. In C, we can use pointer 
type-punning shenanigans to convert between a dispatch_data_t and NSData*. To 
trigger this code in a test that I would write in Swift, DispatchData would 
need to be convertible to Data.  Is there a way to do the conversion in Swift?  
It doesn’t seem obvious since DispatchData and Data are value types, not 
pointer nor reference types.

I just checked it out with your code above in a playground.  I added an 
extension to Data called “printHello” and called it with a Data object I also 
added.  Sure enough, the DispatchData object could not call that same method.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Data, enumerateBytes: separate blocks?

2017-12-21 Thread Daryle Walker

> On Dec 19, 2017, at 8:08 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Dec 19, 2017, at 14:57 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> What are the hoops/bridges required?
> 
> I think I was referring to what Wim Lewis said, which is that you can create 
> DispatchData values (or perhaps dispatch_data_t objects), but you’re going to 
> have to forcibly cast from dispatch_data_t to its superclass, and then bridge 
> that to Data.
> 
> However, if you’re going to the trouble of creating DispatchData values, you 
> may as well use those directly, rather than bridging across to Data. The 
> decision may depend on exactly which APIs you need to use to process the data.

I need to test when multiple blocks are used:

> // Find the first occurance of each potential terminator byte value.
> var firstCr, firstLf: Index?
> enumerateBytes { buffer, start, stop in
> if let localLf = buffer.index(of: ParsingQueue.Constants.lf) {
> firstLf = start.advanced(by: buffer.startIndex.distance(to: 
> localLf))
> stop = true
> }
> 
> if let firstCrIndex = firstCr, firstCrIndex.distance(to: 
> start.advanced(by: buffer.count)) > 2 {
> // No block after this current one could find a LF close 
> enough to form CR-LF or CR-CR-LF.
> stop = true
> } else if let localCr = buffer.index(of: 
> ParsingQueue.Constants.cr) {
> firstCr = start.advanced(by: buffer.startIndex.distance(to: 
> localCr))
> stop = true
>         }
> }

(This is in an extension of Data.) Right now, I have no way to activate the 
second IF-block for testing.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Data, enumerateBytes: separate blocks?

2017-12-19 Thread Daryle Walker

> On Nov 28, 2017, at 3:54 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> I believe that there is one more little piece to this that’s more recent. 
> Since (after that 10.9 change) the NSData class had to become (publicly) 
> aware that subclasses might contain discontiguous data, the opportunity arose 
> for Cocoa to leverage this in other scenarios, where dispatch_data_t (aka 
> DispatchData in Swift) wasn’t involved. That’s good in general, as a 
> performance enhancement for code that cares to enumerate the block ranges, 
> but it happens behind the scenes.
> 
> By contrast, AFAIK the only mechanism for 3rd party code to *forcibly* create 
> NSData objects with discontiguous data buffers is via 
> dispatch_data_t/DispatchData. For that reason, it might make more sense for 
> Daryle to work in the DispatchData domain rather than the plain Data domain. 
> However, as you say, there’s a bridge involving some simple hoops available 
> if necessary.

What are the hoops/bridges required?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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


SASL

2017-12-01 Thread Daryle Walker
Is there a (user-accessible) SASL library on macOS (X)? No need to download one 
for a mail client idea if the system comes with one. 

Sent from my iPhone
___

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


Data, enumerateBytes: separate blocks?

2017-11-27 Thread Daryle Walker
Is there a way to make a (NS)Data that uses multiple contiguous blocks? Besides 
generating a multi-gig file and hoping, that is. I’m using enumerateBytes for 
efficiency and need to test sequences that cross sub-blocks. 

Sent from my iPhone
___

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


What are the closure parameters for the Swift version of "Data.enumerateBytes"?

2017-09-09 Thread Daryle Walker
The method signature is:

public func enumerateBytes(_ block: (UnsafeBufferPointer, Data.Index, 
inout Bool) -> Swift.Void)

From trying out the version from NSData in Objective-C years ago, and this 
method’s own explanation, I know the third closure parameter controls whether 
to keep iterating. Instead of a pointer and a range, we have a buffer and index 
for the first two closure parameters. I guess the span information has just 
moved from the second to the first parameter. The first parameter has changed 
from a pointer to the start of the memory segment to a buffer enclosing the 
segment’s start and span. The second parameter used to represent which span of 
bytes within the total NSData object are modeled in the segment, now I guess 
it’s now the index within the Data object where the modeled segment starts. Is 
my guess correct?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: [webkit-dev] How to display new MIME types?

2017-07-29 Thread Daryle Walker

> On Jul 26, 2017, at 9:13 PM, Conrad Shultz <conrad_shu...@apple.com> wrote:
> 
>> On Jul 22, 2017, at 7:32 PM, Jens Alfke <j...@mooseyard.com> wrote:
>> 
>>> On Jul 21, 2017, at 7:19 PM, Conrad Shultz <conrad_shu...@apple.com> wrote:
>>> 
>>> You can build a Safari extension as an app extension bundled with an app, 
>>> meaning you can write your extension in Swift or Objective-C (and 
>>> JavaScript).
>> 
>> It doesn’t look like these can do what the OP wants to do — display a 
>> specific MIME type in Safari. Safari Extensions are triggered by web pages 
>> loading, and can inject JS or CSS, which implies that the page is already 
>> HTML-based. If Safari encounters a page whose MIME type is 
>> “application/foobar”, it’s not going to display any HTML, it’s going to 
>> download it as a file and the extension never gets to run.
> 
> Yes, you will not able to directly display a new MIME type in Safari using 
> the existing extensions API. I encourage filing a bug at 
> https://bugreport.apple.com <https://bugreport.apple.com/> requesting new 
> functionality.

#33607778

> However, you might be able to emulate a similar behavior. For example, your 
> extension could add script that detects a link (or other reference) in HTML 
> to the content of interest, then routes it (either as downloaded data or the 
> resource URL) to your native code, which could then render it either in your 
> associated app or in a popover in Safari.

What if my custom type is the first page visited (i.e. no link)?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: [webkit-dev] How to display new MIME types?

2017-07-20 Thread Daryle Walker

> On Jul 20, 2017, at 7:38 PM, Saagar Jha <saa...@saagarjha.com> wrote:
> 
> I remember asking one of the WebKit engineers a similar question. Her 
> response was that NPAPI was basically deprecated, and she suggested writing a 
> plugin in that intercepted links and displayed its own UI when necessary.

What kind of plug-in? One still using NPAPI? Some other format?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: [webkit-dev] How to display new MIME types?

2017-07-20 Thread Daryle Walker
[I originally had this on the WebKit development list first.]

> On Jul 18, 2017, at 3:31 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> [I’m not sure this is the right forum.]
> 
> If I want Safari for Mac to display a new MIME type, how do I do it? I know 
> there used to be an Apple-custom API for this, but it was deprecated for 
> classic Netscape plug-ins long ago. However, those NPAPI plug-ins have been 
> deprecated themselves across platforms for many years. There are the newest 
> Safari extensions, which are versions of Apple’s app-extensions API, but 
> those only do JavaScript modifications and such, and don’t cover new types (I 
> think). Am I completely out of luck now? Can I still try NPAPI?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-07 Thread Daryle Walker

> On Apr 7, 2017, at 4:43 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Apr 7, 2017, at 07:24 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> Does anyone have any ideas how to do this a runtime? I need to intercept 
>> when a table cell is created so I can either change its font property or set 
>> a font binding.
> 
> Do you implement tableView:viewFor:row: in your delegate? That’s the (well, 
> a) place to configure table cells.

This is what I did, although I was initially nervous because I didn’t want to 
handle cell-view creation. There is another delegate method that notifies you 
of when a view is about to be used for a cell; I overrode that first, but it 
never got called (or at least the “guard” checking if the view was a 
“NSTableCellView” never passed). I also had to change the font in the delegate 
call I already had for row-height calculation.

> Note that if you want to reference subviews of the cell view via outlets, 
> you’ll need to subclass NSTableCellView to add the outlets. Then you can 
> connect them from the cell view prototype in IB to individual UI elements. 
> (The standard outlets “text” and “image” work the same way, but you get them 
> for free on NSTableCellView. )
> 
> Alternatively, if you subclass NSTableCellView, you can override 
> “prepareForReuse”, which would allow you to configure subviews without having 
> to put the code in the delegate method.

I first tried overriding “prepareForReuse” in my text-field subclass, but it 
never stuck.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-07 Thread Daryle Walker

> On Apr 5, 2017, at 5:19 PM, Daryle Walker <dary...@mac.com> wrote:
> 
>> On Apr 5, 2017, at 5:08 PM, Daryle Walker <dary...@mac.com> wrote:
>> 
>>> On Apr 5, 2017, at 12:19 PM, Charles Srstka <cocoa...@charlessoft.com> 
>>> wrote:
>>> 
>>> Actually, while NSTableCellView won’t bind to *most* things outside of the 
>>> table view, there is an exception for the table’s delegate. So, if you set 
>>> the table’s delegate to File’s Owner, and then bind the NSTableCellView’s 
>>> ‘font’ binding to File’s Owner, it should work.*
>>> 
>>> *But only in a XIB file. In a storyboard, the XIB compiler will get stuck 
>>> in an infinite loop which will continue even after you click the “Stop” 
>>> button, grabbing more and more RAM surreptitiously in the background until 
>>> your Mac runs out of swap space and you’re forced to do a hard reboot. 
>>> Hooray for Xcode!
>> 
>> I am using a storyboard. And this hang upon XIB-compilation is what happens 
>> whenever I try font-binding.
> 
> Hmm, I wonder if I can do this binding at run-time, within the view 
> controller’s “viewDidLoad” or whatever. But I need to get references to each 
> columns’ prototype cell. Can I control-drag from the cell to create an outlet 
> for those?!

You can control-drag from a prototype cell to the source file to create an 
outlet, but IB flags an error soon afterwards, proclaiming the connection to be 
invalid. Makes sense, since I’m connecting a prototype and not actual table 
cells, and the actual cells are too transient for an outlet connection. Does 
anyone have any ideas how to do this a runtime? I need to intercept when a 
table cell is created so I can either change its font property or set a font 
binding. (If we do the latter, we also need to intercept the cell’s destruction 
so I can unbind.)

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-05 Thread Daryle Walker

> On Apr 5, 2017, at 5:08 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> 
>> On Apr 5, 2017, at 12:19 PM, Charles Srstka <cocoa...@charlessoft.com> wrote:
>> 
>> 
>> Actually, while NSTableCellView won’t bind to *most* things outside of the 
>> table view, there is an exception for the table’s delegate. So, if you set 
>> the table’s delegate to File’s Owner, and then bind the NSTableCellView’s 
>> ‘font’ binding to File’s Owner, it should work.*
>> 
>> *But only in a XIB file. In a storyboard, the XIB compiler will get stuck in 
>> an infinite loop which will continue even after you click the “Stop” button, 
>> grabbing more and more RAM surreptitiously in the background until your Mac 
>> runs out of swap space and you’re forced to do a hard reboot. Hooray for 
>> Xcode!
> 
> I am using a storyboard. And this hang upon XIB-compilation is what happens 
> whenever I try font-binding.

Hmm, I wonder if I can do this binding at run-time, within the view 
controller’s “viewDidLoad” or whatever. But I need to get references to each 
columns’ prototype cell. Can I control-drag from the cell to create an outlet 
for those?!

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-05 Thread Daryle Walker

> On Apr 5, 2017, at 12:19 PM, Charles Srstka <cocoa...@charlessoft.com> wrote:
> 
> 
> Actually, while NSTableCellView won’t bind to *most* things outside of the 
> table view, there is an exception for the table’s delegate. So, if you set 
> the table’s delegate to File’s Owner, and then bind the NSTableCellView’s 
> ‘font’ binding to File’s Owner, it should work.*
> 
> *But only in a XIB file. In a storyboard, the XIB compiler will get stuck in 
> an infinite loop which will continue even after you click the “Stop” button, 
> grabbing more and more RAM surreptitiously in the background until your Mac 
> runs out of swap space and you’re forced to do a hard reboot. Hooray for 
> Xcode!

I am using a storyboard. And this hang upon XIB-compilation is what happens 
whenever I try font-binding.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Is there a way to pluralize menu items?

2017-04-05 Thread Daryle Walker

> On Apr 5, 2017, at 9:10 AM, Steve Mills <sjmi...@mac.com> wrote:
> 
> On Apr 4, 2017, at 22:09:34, Daryle Walker <dary...@mac.com> wrote:
>> 
>> I have a menu item named like “Remove Item”. But I added support for 
>> multiple-selection in the table-view. So is there a way to change the menu 
>> item to “Remove Items” when more than one item is selected. I think there’s 
>> a “stringdict” format that can handle all sorts of plural rules (some 
>> locales do more than singular vs. non-singular in English). Can that help 
>> here?
> 
> Add a validateMenuItem: method to set the title based on the number of items.

Can I do this from validateUserInterfaceItem: instead?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Is there a way to pluralize menu items?

2017-04-04 Thread Daryle Walker
I have a menu item named like “Remove Item”. But I added support for 
multiple-selection in the table-view. So is there a way to change the menu item 
to “Remove Items” when more than one item is selected. I think there’s a 
“stringdict” format that can handle all sorts of plural rules (some locales do 
more than singular vs. non-singular in English). Can that help here?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Auto-layout: how do I make the other side "win"?

2017-04-04 Thread Daryle Walker

> On Apr 3, 2017, at 1:52 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Apr 3, 2017, at 08:57 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> When I select the window in the window controller’s scene in the storyboard, 
>> its content size is 800x450. It doesn’t show that way on app run. The view 
>> that’s connected to it, a split-view (top & bottom), is still set to the 
>> default 450x300. The two splits are also at the default 450x300. The bottom 
>> split is a tab-view, whose two tabbed views are also at the default 450x300.
> 
> Set the size of the split view to 800 x 450, and change nothing else, then 
> run the app. What size window do you get? What are the relative sizes of the 
> two splits? (Make sure you turn off window restoration, or the results will 
> be meaningless.)
> 
>> I haven’t added any constraints yet.
> 
> Your content almost certainly won’t lay out correctly when the window is 
> resized by the user at run time. 

Since my previous post, I have added constraints.

Split-view: none, since it doesn’t have any direct views.

Table-view (top split): set the table’s surrounding scroll view to match its 
container view. Set its minimum width to 200, and minimum height to 150.

Tab-view (bottom split): none, since it doesn’t have any direct views.

First tab view: originally was going to be just a button, now it’s a button in 
front of a visual-effect view (using the (Inherited) Aqua colors). The view 
matches its container view and has its minimum width set to 200. It doesn’t 
specify anything for vertical, but the button has a fixed height and fixes its 
top and bottom margins to the standard value. (The button has a fixed width and 
centered horizontal positioning.) This indirectly locks the effect view to 61 
points high.

Text view (i.e. second tab view): same setup as the table view.

All these views are still set to the default 450x300, except the first tab 
view’s height is 61.

Now stretching out the split-view’s content rectangle….

And the run-time window is still short.

Now stretching the table- and tab-views to 800 in width, but staying 300 in 
height….

And the window does have the expanded width. But I still don’t like how the 
header section takes over half of the height, even when the text view is 
active. (The header is always oversized when the effect-view is active, since 
its height is fixed at 61 points.)  I’ll change the table-view height to 200, 
and the tab-view height to 250….

And the run-time proportions are still table-view-is-bigger when the text view 
is active. Maybe I need to tweak the text view’s scene too…. Nope, no further 
change. I want the header to be around a third of the height when the text view 
is active, while the text view takes the other two-thirds. I have a toolbar and 
have the window’s top matter (title bar and toolbar) go into the content area 
(like modern apps should). It’s weird seeing the table view’s data partially 
translucent behind the title- and tool-bars.

When adjusting views’ heights for a top/bottom split-view, how should I account 
the splitters’ heights? Right now, I have the thin splitter. How high is that?

>> It seems that I do have do design from the inside-out and guess the shrunken 
>> sizes of my components, instead of having my sizes from the outside-in and 
>> having auto-layout shrink the interiors.
> 
> In IB you’re designing for *all* window sizes simultaneously, not for a 
> particular size. Auto-layout constraints *are* the design, not the rules for 
> adjusting the design. However, you have two complications:
> 
> 1. By not having any constraints, you’re leaving it up to IB (or perhaps the 
> run-time constraints system, or perhaps some combination of both) to add 
> constraints (or constraint-like behavior) that attempts to preserve your 
> unconstrained design. You can’t really complain if if doesn’t do what you 
> want, since it doesn’t really know what you want.
> 
> 2. The size of the outer container (the content view) is unconstrained, 
> because auto-layout is designed to work in both directions (the content view 
> can resize the window; the window can resize the content view). Something has 
> to resolve that ambiguity in each case. Sometimes explicit constraints within 
> the view will do it (and there are specific NSLayoutPriority values which you 
> can use to control the “direction” of the resolution), and sometimes the 
> window size is forced on the content (window restoration, or window 
> drag-to-resize), but if not, the NIB size of the content view sets the size 
> of the window.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

___

Cocoa-dev mailing list (Cocoa-dev@lists.a

Re: Auto-sized table cells, for macOS

2017-04-04 Thread Daryle Walker

> On Mar 18, 2017, at 3:21 AM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Mar 17, 2017, at 23:18 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> The table isn’t using the new values, though.
> 
> There’s no direct relationship linking the intrinsic size to the row height. 
> That’s kinda the point. Nothing is going to happen automatically. You have to 
> detect when the row height might change (e.g. when the text is edited), and 
> run autolayout on a prototype cell. Autolayout uses the intrinsic height to 
> resize the cell view. That gives you the height, and then you must manually 
> tell the table that the height for the row has changed.

Let’s restart with the code based on Jeremy Hughes’ post:

> class WrappingTextField: NSTextField {
> 
> override var intrinsicContentSize: NSSize {
> guard let cell = self.cell, cell.wraps else { return 
> super.intrinsicContentSize }
> 
> self.validateEditing()
> return cell.cellSize(forBounds: NSRect(x: 0, y: 0, width: 
> self.bounds.width, height: .greatestFiniteMagnitude))
> }
> 
> override func textDidChange(_ notification: Notification) {
> super.textDidChange(notification)
> self.invalidateIntrinsicContentSize()
> }
> 
> }

This clip uses the field’s “bounds,” but based on code I saw on StackOverflow 
(<http://stackoverflow.com/a/10463761/1010226>), I changed it to the “frame” 
instead. I think the latter is what you need when sizing a view relative to its 
super-view.

Previous versions of my code had a huge KVO setup to watch for string changes 
and caching the results. Looking back, it was too much on the wrong side of 
“work smarter, not harder.” The text fields derived their value from my model, 
but as far as the surrounding table-view is concerned, the text-fields are the 
only source of “truth” that matters! That means sourcing the table-view update 
flag from these text fields. I can modify the (second) method above, put how to 
I figure out what row needs to be updated. Hint: the table-view surrounds the 
text-fields. The table view surrounds a list of row views, which surround a 
list of cell views (which are generated by the table-column markers, which 
aren’t views themselves). Work backwards from the field to get the row and 
table. But, unlike columns, the table does not hold a convenient array of rows.

> override var intrinsicContentSize: NSSize {
> guard let cell = self.cell, cell.wraps else { return 
> super.intrinsicContentSize }
> 
> validateEditing()
> return cell.cellSize(forBounds: NSRect(x: 0, y: 0, width: 
> frame.width, height: .greatestFiniteMagnitude))
> }
> 
> override func textDidChange(_ notification: Notification) {
> super.textDidChange(notification)
> self.invalidateIntrinsicContentSize()
> 
> if let rowView = superview?.superview as? NSTableRowView, let 
> tableView = rowView.superview as? NSTableView {
> tableView.enumerateAvailableRowViews { currentRowView, 
> currentRowIndex in
> if rowView === currentRowView {
> tableView.noteHeightOfRows(withIndexesChanged: 
> IndexSet(integer: currentRowIndex))
> }
> }
> }
> }

I don’t look for the immediately-surrounding NSTableCellVIew because the 
surrounding view may be of a different class, and that fact doesn’t matter as 
long as I can get the row-view surrounding the cell views. Now, I do make a 
table-view delegate to compute the new row height. Before, I had problems 
generating a cell to work on. Apple explicitly bars two of the generating 
methods from working in the delegate call. But I can use the third one to make 
a prototype cell. I searched for row-adjusting code on GitHub, and adapted the 
last full method on 
<https://github.com/konstantinpavlikhin/KSPAutomaticHeightCalculationTableCellView/blob/master/Sources/KSPAutomaticHeightCalculationTableCellView.m>
 to help:

> extension MessageHeaderViewController: NSTableViewDelegate {
> 
> func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat 
> {
> var height = tableView.rowHeight
> guard self.headerTable === tableView, let field = 
> self.headerArray[row] as? RawHeaderField else { return height }
> 
> for (columnId, value) in [(Names.nameColumn, field.name), 
> (Names.bodyColumn, field.body)] {
> guard let prototypeCell = tableView.make(withIdentifier: 
> columnId, owner: self) as? NSTableCellView else {
> continue
> }
> 
> let column = 
> tableView.tableColumns[tableView.column(withIdentifier: c

What do the font-related Cocoa Bindings in NSTableView and NSTableColumn do?

2017-04-04 Thread Daryle Walker
Neither class (directly?) has font controls, so would any related binding 
affect, if anything?

Is there a way to affect the font of a table cell via Bindings? The few times I 
tried, at the NSTextField level (NSTableCellView does not have any font-related 
Bindings), resulted in Xcode’s XIB compiler jamming. (I always cancel and take 
out the change.)

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Auto-layout: how do I make the other side "win"?

2017-04-03 Thread Daryle Walker

> On Apr 1, 2017, at 5:00 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Apr 1, 2017, at 12:07 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> I got a feeling that, since the interior of the window and the exterior of 
>> the view are probably bound, that the auto-layout system is choosing the 
>> view’s smaller size over the window’s bigger one. How do I reverse this? Or 
>> do I have to manually increase the size of all the interior views?
> 
> The window’s content rect *is* the frame of the content view, and you’re 
> right that the window is initially resized to the content view size from the 
> storyboard. In IB, you should set the content view size, not the window size, 
> to the desired initial value. If you have a complete set of auto-layout 
> constraints, that should be the only manual part of the adjustment, and all 
> the subviews should resize correctly.

When I select the window in the window controller’s scene in the storyboard, 
its content size is 800x450. It doesn’t show that way on app run. The view 
that’s connected to it, a split-view (top & bottom), is still set to the 
default 450x300. The two splits are also at the default 450x300. The bottom 
split is a tab-view, whose two tabbed views are also at the default 450x300. I 
haven’t added any constraints yet.

It seems that I do have do design from the inside-out and guess the shrunken 
sizes of my components, instead of having my sizes from the outside-in and 
having auto-layout shrink the interiors.

> However, you have to be a bit careful. By defaults, windows are restorable. 
> On the second and subsequent runs of your app, your window will restore to 
> the last saved size, and the content will be resized to the window — the 
> opposite of what happens on first run. You should disable restoration (in the 
> Run scheme options) while you’re testing your initial window size. In 
> addition, document windows are subject to resizing on opening, if you use a 
> window autosave identifier.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Auto-layout: how do I make the other side "win"?

2017-04-01 Thread Daryle Walker
1. Created new storyboard and dragged a window (with controller) into it. Comes 
with a view (with controller).
2. Expanded the size of the window. Didn’t touch the associated view.
3. On test run, window comes out much smaller than expected. Can’t figure out a 
tweak to fix it.

I got a feeling that, since the interior of the window and the exterior of the 
view are probably bound, that the auto-layout system is choosing the view’s 
smaller size over the window’s bigger one. How do I reverse this? Or do I have 
to manually increase the size of all the interior views?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Can't use +initialize, now what?

2017-03-29 Thread Daryle Walker
Sometimes, I see something in Apple’s AppKit/Foundation reference site that 
mentions that their technique should be loaded early in the program by putting 
it in the class’s “+initiallize” method. Now the new Xcode release notes say 
that “• Swift now warns when an NSObject subclass attempts to override the 
initialize class method, because Swift can't guarantee that the Objective-C 
method will be called. (28954946)” So, what is code that needs to be setup 
early supposed to do? Use the application delegate’s will-finish-launching 
method and hope it is early enough?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

How to make a NSText​Find​Bar​Container client.

2017-03-28 Thread Daryle Walker
It seems that I’ll be the first American in general & GitHub open-source 
history to ever make a NSText​Find​Bar​Container subclass. The window 
controller shows two views in a split view. The top half is a NSTableView 
surrounded by a NSScrollView. The bottom half is a NSTextView surrounded by a 
scroll view. Each one can handle NSTextFinder, but I’m considering them halves 
of the same document (since they are). So I’m make a single find-bar to cover 
both views. I’ve read about NSTitlebarAccessoryViewController and wonder if I 
can use it to hold the Find controls.

> class MyWindowController: NSWindowController {
> //...
> dynamic var representedMessage: RawMessage?
> dynamic var isWritable: Bool = true
> 
> // Outlets
> @IBOutlet weak var messageController: NSObjectController!
> @IBOutlet weak var headerController: NSArrayController!
> @IBOutlet weak var textFinder: NSTextFinder!
> @IBOutlet weak var accessoryView: NSVisualEffectView!
> 
> // Pseudo-outlets
> var headerViewController: NSViewController!
> var bodyViewController: NSTabViewController!
> var addBodyViewController: NSViewController!
> var bodyTextViewController: NSViewController!
> 
> var headerTableView: NSTableView!
> var bodyTextView: NSTextView!
> 
> /// Table of which characters, combining the header and body as a single 
> string, are where.
> dynamic var textRanges = [NSMakeRange(0, 0)]
> /// The accessory title-bar to contain the text-finding controls.
> let findBar = NSTitlebarAccessoryViewController()
> 
> //...
> 
> override func windowDidLoad() {
> super.windowDidLoad()
> //...
> findBar.layoutAttribute = .bottom
> }
> //...
> }

I added a NSTextFinder to my window controller’s top bar and added an outlet. 
I’m using the window controller class as the NSTextFinderClient delegate:

> extension MyWindowController: NSTextFinderClient {
> 
> /// Determine the right substring, from the text range map.
> func string(at characterIndex: Int, effectiveRange outRange: 
> NSRangePointer, endsWithSearchBoundary outFlag: 
> UnsafeMutablePointer) -> String {
> //...
> }
> 
> /// Determine the length of the virtual string, from the text range map.
> func stringLength() -> Int {
> return NSMaxRange(self.textRanges.last!)
> }
> 
> }

and a NSTextFindBarContainer delegate:

> extension MyWindowController: NSTextFinderBarContainer {
> 
> var findBarView: NSView? {
> get { return self.findBar.view }
> set { self.findBar.view = newValue ?? /*self.accessoryView*/ NSView() 
> }
> }
> 
> func contentView() -> NSView? {
> return self.window?.contentView
> }
> 
> var isFindBarVisible: Bool {
> get {
> return self.findBar.parent != nil
> }
> 
> @objc(setFindBarVisible:) set {
> if newValue && self.findBar.parent == nil {
> self.window?.addTitlebarAccessoryViewController(self.findBar)
> } else if !newValue && self.findBar.parent != nil {
> self.findBar.removeFromParentViewController()
> }
> }
> }
> 
> func findBarViewDidChangeHeight() {
> // Do I need to do something here?
> }
> 
> }

I have no idea if what I’m doing here is even close to being right. (The 
“accessoryView” property maps to a NSVisualEffectView that I made because I 
thought “NSView()” was wrong at first. It made no difference.) When I try 
running the app, creation of the first window is jammed by:

> 2017-03-28 15:33:27.659649 XNW[51906:6766586] -[NSNib 
> _initWithNibNamed:bundle:options:] could not load the nibName: 
> NSTitlebarAccessoryViewController in bundle (null).
> 2017-03-28 15:33:27.677235 XNW[51906:6766586] -[NSNib 
> _initWithNibNamed:bundle:options:] could not load the nibName: 
> NSTitlebarAccessoryViewController in bundle (null).

Is anyone from Apple and/or has privately made a NSTextFindBarContainer class 
capable of helping? As I said, there are no answers from WebSearch (i.e. others 
will be helped by me). Is there Apple sample code that covers this?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Where can I write in Undo/Redo action titles?

2017-03-27 Thread Daryle Walker
[I thought I wrote something about this, but I didn’t see it in my Sent e-mail 
list.]

I “drunk the Kool-Aid” and have a Core Data-based model and using Cocoa 
Bindings. This combination gives me Undo support. The problem is that you’re 
traditionally supposed to put the names of actions during the action so 
Undo/Redo can add them to their menu label. I do have a pair of menu actions 
with app-custom code, but the other actions are automatic so there’s no obvious 
spot to insert action strings.

Any ideas of where I can interrupt the Undo/Redo process to insert titles? Or 
do I have to live with plain “Undo” and “Redo” for my actions?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Can't access by data via KVC during KVO

2017-03-27 Thread Daryle Walker
angeArray()
> for newField in newArray {
> let field = newField as! RawHeaderField
> newFieldRanges.append(contentsOf: [field.name, 
> field.body].map { NSMakeRange(0, ($0 as NSString).length) })
>         }
> textRanges.replaceSubrange(textRanges.startIndex ..< 
> bodyTextRangeIndex, with: newFieldRanges)
> }

This one still works when “.initial” is active.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: How do I set a NSTextView's font in Interface Builder?

2017-03-27 Thread Daryle Walker

> On Mar 24, 2017, at 2:28 PM, Keary Suska <cocoa-...@esoteritech.com> wrote:
> 
>> On Mar 24, 2017, at 10:33 AM, Jens Alfke <j...@mooseyard.com> wrote:
>> 
>>> On Mar 23, 2017, at 6:35 PM, Daryle Walker <dary...@mac.com> wrote:
>>> 
>>> I have the NSTextView selected in its storyboard scene. And I have the 
>>> Attributes Inspector active. The entry for the font is empty. Clicking the 
>>> squared-T gives a pop-up with a “Custom” font and changing it to one of the 
>>> fixed selections (User, fixed) doesn’t do any actual change. 
>> 
>> This is a longstanding bug, or maybe it’s an API issue. The problem is that 
>> the view’s text is empty, and an empty NSAttributedString can’t have any 
>> attributes because the attributes are associated with characters.
>> 
>> IIRC you can fix this by adding some placeholder text, even a single space, 
>> in the view, then replacing it at runtime.
> 
> I don’t believe that is actually true. Attributes *can* apply to an empty 
> range. Alternatively, or additionally, I believe if you call 
> setTypingAttributes: on an empty text view that any new types text will use 
> the specified attributes.

I solved this by starting to play with UserDefaults. I added my font as a 
default, then referenced it in the text view with Cocoa Bindings.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Is there a way to access other controller square's other icons programmatically?

2017-03-27 Thread Daryle Walker

> On Mar 24, 2017, at 3:49 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Mar 24, 2017, at 11:11 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> I have a re-explaination, including a picture, at …
> 
> I think I’m beginning to understand what you’re asking. Part of the problem 
> is that Apple has never properly documented the use of storyboards on macOS, 
> and there seems to be no standard pattern for doing many of the things that 
> we used to do when using XIBs instead.

So, there is no API to getting at runtime the top-bar items that you add?! (If 
you don’t mind a subclass, you can drag items from the storyboard to the 
corresponding subclass definition file.)

> If I understand correctly, you have a window with an associated custom 
> subclass of NSWindowController. The root view controller is a 
> NSSplitViewController, with a NSViewController on the left, and a 
> NSTabViewController on the right. Each of the tabs has a NSViewController, 
> with a table view in one tab and a text view in another tab (based on what 
> you said in earlier posts). My structure may not be exactly the same as 
> yours, but it’s something like that, right?

It’s a top/bottom split view. And the table view is on top, while the text view 
is one of the tabs in the bottom half.

> Now, in some of the NSViewController views, you need to use a 
> NSArrayController or NSObjectController, which is added directly to the 
> storyboard. The question then becomes: how to connect the array or object 
> controller to its content (which lies outside the storyboard) and/or 
> establish an outlet to the array or object controller that gives you a 
> programmatic reference to the object in the nib. (In a XIB-based design, this 
> is straightforwardly done via the File’s Owner pseudo-object.)
> 
> I think the short answer is that you should create a subclass for each 
> NSViewController in your tree of controllers. You *could* subclass the split 
> and tab view controllers too, but there’s no real need. The subclass would 
> contain whatever outlets and properties providing access to model data it 
> needs for its particular view. Each VC would have its own set of object 
> and/or array controllers, and each object/array controller would bind or 
> connect to its own VC.

I was trying to avoid using subclasses.

> The only remaining problem is how to establish programmatic references 
> between the WC and the VC subclasses, in particular how to make model data 
> available to the VCs.
> 
> — If this is a non-document app, I would recommend you create a class 
> property in your WC subclass that holds a reference to your singleton WC of 
> that subclass. This reference would be set in an override of the WC init 
> method.
> 
> — If this is a document-based app, I would suggest that your VC subclasses 
> use KVO to observe themselves along key paths of the form 
> “view.window.windowController.document.model…”. You could, for example, 
> create a derived “model” property that returns 
> “view.window.windowController.document.model”, along with a class 
> “keyPathsOfValuesAffectingModel” method to make the derived property KVO 
> compliant. You can then bind UI elements through the model property.
> 
> The only thing to be careful of is that the derived “model” property will be 
> nil initially, so your UI has to do something sensible until the model 
> reference is available (in particular, not crash).
> 
> — Alternatively, you can have the WC walk the tree of VCs, injecting a 
> reference to itself in each VC of known custom subclasses.
> 

I first kept my object and array controllers in my window controller class. I 
walked the controller tree, keeping references to the table and text views, and 
adding the appropriate controller as the view controller’s represented-object. 
(I’m not subclassing, so they have no other use.) I used the represented-object 
as the controller key while building Cocoa Bindings.

> Does any of that help?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Click-through

2017-03-25 Thread Daryle Walker
Is there any way to disable click through? On a toolbar control or otherwise. 
Through an Interface Builder setting or otherwise. 

Sent from my iPhone
___

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


Official sidebar?

2017-03-25 Thread Daryle Walker
Testing out my app. Finally noticed the new "Show Tab Bar" View menu item. The 
menu also handles the tool bar, full screen, and a sidebar. Never noticed that 
last one before. What do I have to do in my storyboard and/or window controller 
to support that?

(Of course, I don't need one right now. But I'm still curious.)

Sent from my iPhone
___

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: Is there a way to access other controller square's other icons programmatically?

2017-03-24 Thread Daryle Walker
I have a re-explaination, including a picture, at 
<http://stackoverflow.com/questions/43002809/how-do-i-access-the-top-level-objects-of-a-storyboard-scene-programmatically>.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

> On Mar 23, 2017, at 9:44 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> I used to use a single view controller, in a storyboard, with all the 
> controls/views laid out, including any object/array controllers in the top 
> bar along with the view-controller reference and the first responder icon. 
> Now I moved to a network of view controllers, i.e. split- and 
> tab-view-controllers. This means that the various parts can’t access each 
> other anymore. I have a custom window controller class with a reference to 
> the model and an object controller that points to the model. Since the view 
> controller tree is fixed, I can walk it and keep references to each view 
> controller. While walking the tree, I make the model’s object controller the 
> represented-object for each view controller (with Cocoa Bindings). I think 
> each view controller has a reference to its top view; this means I can walk 
> each controller for the individual scroll, clip, and table/text views.
> 
> Now the view controller that contains the table view also has an array 
> controller connecting the table to the model’s object controller. When 
> walking the controller tree, how can I get a reference to that array 
> controller to store as a property in my window controller class? (Or anything 
> in that top icon strip besides the controller itself) I want to keep 
> referencing the same object & array controllers already allocated when I 
> build my tree of text blocks to support find.

___

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

Is there a way to access other controller square's other icons programmatically?

2017-03-23 Thread Daryle Walker
I used to use a single view controller, in a storyboard, with all the 
controls/views laid out, including any object/array controllers in the top bar 
along with the view-controller reference and the first responder icon. Now I 
moved to a network of view controllers, i.e. split- and tab-view-controllers. 
This means that the various parts can’t access each other anymore. I have a 
custom window controller class with a reference to the model and an object 
controller that points to the model. Since the view controller tree is fixed, I 
can walk it and keep references to each view controller. While walking the 
tree, I make the model’s object controller the represented-object for each view 
controller (with Cocoa Bindings). I think each view controller has a reference 
to its top view; this means I can walk each controller for the individual 
scroll, clip, and table/text views.

Now the view controller that contains the table view also has an array 
controller connecting the table to the model’s object controller. When walking 
the controller tree, how can I get a reference to that array controller to 
store as a property in my window controller class? (Or anything in that top 
icon strip besides the controller itself) I want to keep referencing the same 
object & array controllers already allocated when I build my tree of text 
blocks to support find.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

How do I set a NSTextView's font in Interface Builder?

2017-03-23 Thread Daryle Walker
I have the NSTextView selected in its storyboard scene. And I have the 
Attributes Inspector active. The entry for the font is empty. Clicking the 
squared-T gives a pop-up with a “Custom” font and changing it to one of the 
fixed selections (User, fixed) doesn’t do any actual change. This makes the 
text-view with the initial font (the application/user non-fixed-width font). Is 
there a way to change the text-view’s font in IB?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Handling Cocoa Bindings over a tree of View Controllers

2017-03-21 Thread Daryle Walker
A design for my third window iteration involves using several NSViewController 
subclasses in a UI tree. The current (i.e. second) version just has the root 
NSViewController and a bunch of NSView objects. There is a NSObjectController 
and a NSArrayController to bind the various view objects to my CoreData-based 
document data. 

Since all the objects are together, I can make a big Bindings network. The new 
design would spread the components. I need the object controllers to 
synchronize their editing notifications. I'm wondering how.

I'm half asleep, but I'm thinking of starting with the NSWindowController with 
a reference to the model and one NSObjectController. That object controller 
points to the model and it's managed context. For all the NSViewControllers in 
the tree, they'll use the first object controller as their represented object 
and reference it for their Bindings needs. Would that work?

Sent from my iPhone
___

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: Of course I forgot some NSTextFinder questions

2017-03-21 Thread Daryle Walker

> On Mar 20, 2017, at 1:41 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Mar 20, 2017, at 04:58 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>>> If all the strings were concatenated together would be the ‘x’ in "fox”.
> 
>> Is there a off-by-one bug with the end of the second string? Or am I really 
>> misunderstanding Apple’s counting strategy? The second string seems to be 
>> only 9 characters long. And shouldn't index 18 point to the first character 
>> of the third string instead?
> 
> There’s clearly an omission in that sentence in the documentation, and it 
> appears to mean to say: If all the strings were concatenated together, the 
> 18th character would be the ‘x’ in “fox”.
> 
> Looking at the example concatenation in the next paragraph, it appears that 
> the expectation is that the “conceptually concatenated string” has spaces 
> inserted between the substrings, and that would account for the extra 
> character in the “fox” text. My guess is that putting conceptual spaces in 
> the conceptual concatenation has something to do with the proper recognition 
> of word boundaries (in some languages), but it’s not clear how that works in 
> practice.
> 

There’s nothing conceptual about; it’s a different bug instead!

A lot of new(-ish) Apple API don’t get guides, but have semi-extensive 
instruction in the AppKit (or whatever) notes for the first version of macOS 
the API premiered. The Mac OS X 10.7 Lion part of the 10.11-and-before AppKit 
notes 
(<https://developer.apple.com/library/content/releasenotes/AppKit/RN-AppKitOlderNotes/index.html#10_7TextFinder>)
 uses this very example, but there is a space character before the “brown”! So 
the problem is there was a transcription error between the AppKit notes and the 
API page. (But there isn’t an extra space before the third string or another 
space either at the end of the third string or the start of the fourth.)

> A bug report would probably be appropriate.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Of course I forgot some NSTextFinder questions

2017-03-20 Thread Daryle Walker
1. From Apple’s NSTextFinder class guide 
<https://developer.apple.com/reference/appkit/nstextfinder>:

> For example, if a client had the strings “The quick”, “brown fox” , “jumped 
> over the lazy”, and “dog”, and a NSText​Finder instance requests the string 
> at index 18, then the client should return "brown fox”. If all the strings 
> were concatenated together would be the ‘x’ in "fox". Additionally, the 
> client should return, by-reference through the out​Range parameter, the 
> effective range of the string that is returned. In this example, the range of 
> “brown fox” is {9, 10}, because, in the imagined concatenation, the substring 
> starts at index 9 and is 10 characters long.

Is there a off-by-one bug with the end of the second string? Or am I really 
misunderstanding Apple’s counting strategy? The second string seems to be only 
9 characters long. And shouldn't index 18 point to the first character of the 
third string instead? (Well, the 18 is right assuming the length of 10 is 
actually right. But it isn’t, so it’s not.)

2. Since the first half of my data is in a table view, I guess I’ll supply a 
list of ranges for the cells’ text and flag that matches shouldn’t straddle 
boundaries. But should my text for the second half (i.e. the text view) be 
included in that list (going Make-Range(first-half-length, 
second-half-length))? Or as a separate string for the text view’s find bar 
(going Make-Range(0, second-half-length))?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

NSTextFinder guide

2017-03-20 Thread Daryle Walker
Now I’m looking into adding find support to my window. My window is divided 
into two halves: a NSTableView and a NSTextView. The two views are in separate 
tabs, so you can’t see them at the same time. Also, I sometimes have the 
text-view inactive. (When it’s inactive, you can’t click the text view’s tab. 
In fact, if the inactivation happens while the text view is shown, I 
immediately switch to the table view.)

Is it possible for a find-next from the table view’s last location to jump to 
the text view’s first location whenever the text view is active? And jump from 
the text view's last find to the table view’s first find when wraparound is on? 
(Not automatic, but some sort of delegate call so I can switch tabs and trigger 
the other view’s find.) I’m on the fence whether this is a good user 
interaction, though (like what happens if the other view has no matches). No 
matter which way I go, I need the two views’ bar's search strings and other 
search settings to always be the same, since they are supposed to be parts of 
the same document. Of course, switching one view’s search bar on/off should do 
the same to the other view’s bar.

Is there an official guide for this class (besides Apple’s class definition 
page)? Or is there a cool guide on a seasoned developer’s blog (or here)?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Auto-sized table cells, for macOS

2017-03-18 Thread Daryle Walker

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

> On Mar 17, 2017, at 2:24 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Mar 17, 2017, at 01:45 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> I made my first attempt after reading 
>> <http://stackoverflow.com/a/32332743/1010226 
>> <http://stackoverflow.com/a/32332743/1010226>>:
>> 
>>> // Increase the row height to fit all the text (instead of the first 
>>> line).
>>> func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> 
>>> CGFloat {
>>> precondition(tableView === self.headerTableView)
>>> 
>>> var height = tableView.rowHeight
>>> let nameColumn = tableView.tableColumn(withIdentifier: 
>>> Names.nameColumnIdentifier)!
>>> let bodyColumn = tableView.tableColumn(withIdentifier: 
>>> Names.bodyColumnIdentifier)!
>>> let field = (self.headerArrayController.arrangedObjects as! 
>>> NSArray).object(at: row) as! RawHeaderField
>>> let attributes = [NSFontAttributeName: NSFont.systemFont(ofSize: 0)]
>>> let nameString = NSAttributedString(string: field.name, attributes: 
>>> attributes)
>>> let bodyString = NSAttributedString(string: field.body, attributes: 
>>> attributes)
>>> for (string, column) in [(nameString, nameColumn), (bodyString, 
>>> bodyColumn)] {
>>> let frame = NSRect(x: 0.0, y: 0.0, width: column.width, height: 
>>> .greatestFiniteMagnitude)
>>> let view = NSTextView(frame: frame)
>>> view.textStorage?.setAttributedString(string)
>>> view.isHorizontallyResizable = false
>>> view.sizeToFit()
>>> height = max(height, view.frame.size.height /*+ 20*/)
>>> }
>>> 
>>> return height
>>> }
> 
> This isn’t what you want, for two entirely separate reasons.
> 
> 1. Assuming you’re using view-based table views (and if you’re not, you 
> really should be), then you don’t want the height of the text, you want the 
> height of the cell (NSTableCellView) that contains your text in a subview. 
> The whole point is that you leverage autolayout to get the NSTableCellView to 
> compute the text height for you. Furthermore, the text is placed *within* the 
> cell, so the height of the NSTableCellView may be bigger than the height of 
> the text, or (in general) the cell might contain other views that need to be 
> taken into account.
> 
> 2. You shouldn’t be using a NSTextView, but a NSTextField. A text view 
> typically is placed within a fixed height frame, wrapped in a scroll view, so 
> the concept of an intrinsic height is problematic. What is your actual cell 
> structure, text view or text field?

It’s whatever NSTableCellView uses as a default, so… NSTextField.

…

I just tried something from a recent post by Jeremy Hughes:

//=
class WrappingTextField: NSTextField {

override var intrinsicContentSize: NSSize {
guard let cell = self.cell, cell.wraps else { return 
super.intrinsicContentSize }

self.validateEditing()
return cell.cellSize(forBounds: NSRect(x: 0, y: 0, width: 
self.bounds.width, height: .greatestFiniteMagnitude))
}

override func textDidChange(_ notification: Notification) {
super.textDidChange(notification)
self.invalidateIntrinsicContentSize()
}

}

//=

I put this class as the table-cell’s type and took out the table delegate but 
kept the constraints of the text field to match those of the cell. No change 
(so far). I did debug printouts to the Xcode console, and there are changes. 
All the sizes from “super" are “(-1.0, 17.0)”, but the new sizes vary in widths 
and height. The table isn’t using the new values, though.


>> But it only establishes the row heights once, at start but never after any 
>> resizes (column or whole-table).
> 
> As I said before, you have to watch for column width changes and recalculate 
> your heights accordingly. There is no automatic way of handling variable 
> heights on the Mac that matches the way it can be done on iOS.
> 
>> It still is short on some long lines. (Is it because I use word-wrap, 
>> instead of by character, for that column?) Also, I hard-coded the font to 
>> match what the table has. Is there any way to read what the cell template 
>> has? (“NSTableView.view(something)” can generate a view for a given row and 
>> column, but Apple specifically barred it (with an assert/exception) during 
>> th

Re: Calculating intrinsicContentSize for a NSTextField

2017-03-17 Thread Daryle Walker

> On Mar 17, 2017, at 1:18 PM, Jeremy Hughes <moon.rab...@virginmedia.com> 
> wrote:
> 
> I have a text field that I want to grow and shrink while it is being edited.
> 
> In order to do that, I have overridden intrinsicContentSize and textDidChange 
> in a subclass of NSTextField:
> 
[SNIP]
> 
> This works, but if I remove the call to attributedStringValue (whose result 
> is discarded) the result of the following line fails to reflect changes in 
> the bounds of the text, and the field fails to grow or shrink.
> 
> Presumably, calling attributedStringValue has a side effect which changes the 
> way that cellSize:forBounds: is calculated.

Looking at the “attributedStringValue” docs, "validate​Editing()” is called as 
the side effect.

> Is there a way that I can get cellSize:forBounds: to return the correct value 
> without relying on this side effect?
> 
> An alternative way of calculating the intrinsic content size would be to use:
> 
> attributedStringValue.boundingRect(with: size, options: 
> .usesLineFragmentOrigin)
> 
> but this fails to take account of cell insets.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: NSTableView column sizes

2017-03-17 Thread Daryle Walker
The effect I don’t like about the default code is that when the last column’s 
width is set to fill out the table, it’s only set for the current set of 
widths. As soon as you narrow an earlier column, the last column’s right border 
becomes visible. I want the last column to always max out, no matter how 
earlier columns are resized.

> On Mar 15, 2017, at 4:38 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Mar 15, 2017, at 06:51 , Stephane Sudre <dev.iceb...@gmail.com 
> <mailto:dev.iceb...@gmail.com>> wrote:
>> 
>> the Column Sizing option
> 
> Remember too that each column has its own sizing options that operate in 
> conjunction with the table view’s options. For each column, you can decide 
> whether the column participates in autoresizing (separately from whether it 
> is user resizable), and you can set minimum and maximum widths.
> 
> You can do most reasonable things with these combinations of options, without 
> having to resort to programmatic adjustment.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Auto-sized table cells, for macOS

2017-03-17 Thread Daryle Walker

> On Mar 14, 2017, at 11:33 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Mar 14, 2017, at 18:26 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> You’d think that this would be a solved problem….
> 
> It sort of is. I think you can find a solution on stackoverflow.com 
> <http://stackoverflow.com/> (which is where I got the idea from IIRC) but you 
> have to wade through the out of date stuff to pick out a modern way of doing 
> it. Here’s the code I came up with (for an outline view, table view should be 
> similar):

I meant from the people at Apple HQ. Besides those who intentionally want 
truncating behavior, wouldn’t “expand to show all text” be the expected 
default? The current default isn’t friendly to end users.

>>  func resizeListItem (_ listItem: RecentObjectValue, cell: 
>> NSTableCellView, width: CGFloat, resizedRows: NSMutableIndexSet? = nil)
>>  {
>>  cell.objectValue = listItem
>>  
>>  cell.textField?.preferredMaxLayoutWidth = width - 2
>>  cell.needsUpdateConstraints = true
>>  cell.layoutSubtreeIfNeeded ()
>>  
>>  let rowHeight = cell.fittingSize.height
>>  
>>  guard listItem.rowHeight != rowHeight else { return }
>>  
>>  listItem.rowHeight = rowHeight
>>  let row = recentsListView.row (forItem: listItem)
>>  
>>  guard row >= 0, let rows = resizedRows else { return }
>>  
>>  rows.add (row)
>>  }
> 
> The listItem parameter is a custom struct that contains the actual data 
> displayed in the row (the data model of the outline view, in effect), but it 
> also caches the row height. The resizedRows parameter just accumulates an 
> optional set of changed heights for a subsequent “noteHeightOfRowsChanged”. 
> The cell parameter is created once for measuring purposes, in viewDidLoad:
> 
>>  /* view controller instance variable */ headerCell = 
>> recentsListView.make (withIdentifier: "HeaderCell", owner: self) as! 
>> NSTableCellView
>>  let headerConstraint = NSLayoutConstraint (item: headerCell, 
>> attribute: .height, relatedBy: .greaterThanOrEqual, toItem: nil, attribute: 
>> .notAnAttribute, multiplier: 1, constant: 17)
>>  NSLayoutConstraint.activate ([headerConstraint])
> 
> The only other thing you need is a strategy for deciding when to recalculate 
> the heights. When the column width changes, obviously, as well as for 
> inserted rows, but there might be other cases as well.

Unfortunately, you didn’t provide your Stack Overflow sources. I made my first 
attempt after reading <http://stackoverflow.com/a/32332743/1010226>:

> // Increase the row height to fit all the text (instead of the first 
> line).
> func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat 
> {
> precondition(tableView === self.headerTableView)
> 
> var height = tableView.rowHeight
> let nameColumn = tableView.tableColumn(withIdentifier: 
> Names.nameColumnIdentifier)!
> let bodyColumn = tableView.tableColumn(withIdentifier: 
> Names.bodyColumnIdentifier)!
> let field = (self.headerArrayController.arrangedObjects as! 
> NSArray).object(at: row) as! RawHeaderField
> let attributes = [NSFontAttributeName: NSFont.systemFont(ofSize: 0)]
> let nameString = NSAttributedString(string: field.name, attributes: 
> attributes)
> let bodyString = NSAttributedString(string: field.body, attributes: 
> attributes)
> for (string, column) in [(nameString, nameColumn), (bodyString, 
> bodyColumn)] {
> let frame = NSRect(x: 0.0, y: 0.0, width: column.width, height: 
> .greatestFiniteMagnitude)
> let view = NSTextView(frame: frame)
> view.textStorage?.setAttributedString(string)
> view.isHorizontallyResizable = false
> view.sizeToFit()
> height = max(height, view.frame.size.height /*+ 20*/)
> }
> 
> return height
> }

But it only establishes the row heights once, at start but never after any 
resizes (column or whole-table). It still is short on some long lines. (Is it 
because I use word-wrap, instead of by character, for that column?) Also, I 
hard-coded the font to match what the table has. Is there any way to read what 
the cell template has? (“NSTableView.view(something)” can generate a view for a 
given row and column, but Apple specifically barred it (with an 
as

NSTableView column sizes

2017-03-15 Thread Daryle Walker
1. Is there a way to make the last (right in the U.S. localization) column to 
always be at the end of the table-view, instead of a gap after a resize?

2. My table has two columns. Is there a way to keep their sizes in proportion 
after a window resize? (If the divider is moved, resizes will follow the new 
proportions.)

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Auto-sized table cells, for macOS

2017-03-14 Thread Daryle Walker
I’ve read about techniques to make the size of a table cell expand to fit its 
text, but they all were based on iOS’s UITableView. Is there a similar trick 
using auto-layout for macOS’s NSTableView? I’m using Cocoa Bindings and do not 
have a table-view delegate.

You’d think that this would be a solved problem….

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Printing questions

2017-03-12 Thread Daryle Walker


Sent from my iPhone

> On Mar 12, 2017, at 5:18 AM, Daryle Walker <dary...@mac.com> wrote:
> 
> I hope it’s a nice first try, but I have some concerns.
> 
> 1. I also added an “Export as PDF…” menu item, which uses the save-as-PDF 
> default action. I guess it calls my code, but the docs for 
> “NSDocument.pdfPrintOperation” say I should use a separate print-information 
> objects for PDF mode. Does the default code take care of that already? Or do 
> I have to figure out somehow if I’m in print-to-PDF mode or regular print 
> mode and change the initialization of “info” above to be 
> “self.pdfPrintOperation” as needed?

And this is why you shouldn't post half-tired. It's "pdfPrintOperation," not 
"pdfPrintInfo," so my override wouldn't be called by definition. I guess I 
would override "pdfPrintOperation" to attach a custom print-info, but what 
should be in it? Is there some Apple sample code on this property? I didn't 
find it at all on GitHub. 


> 2. The RTF files I saved with the conversion operation have wrapping when 
> viewed through QuickLook. But the print-outs don’t do that; they do wrap, but 
> the limit is past the page margins so I lose part of the text. How can I set 
> the wrapping-mode/margins correctly.

I forgot to mention that another symptom was a second page appearing if the 
document only used one. I guess it was trying to represent the cut-off text on 
the right side. But it doesn't show up if more than one page is used. 

> 3. Are there any other (subtle) problems with the text-view code, since I 
> just took it from Stack Overflow?


___

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

Document drafts

2017-03-12 Thread Daryle Walker
Some of the API for NSDocument is oriented around draft documents. What is a 
draft and how does it differ from a non-draft? How do I create/open a document 
in draft mode? I didn't see anything about it in the Document guide; were 
drafts supposed to be a New World Order like auto-saves or versions, but got 
abandoned?

Sent from my iPhone
___

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


Printing questions

2017-03-12 Thread Daryle Walker
I like composing controls and such over coming up with new views. This 
frustrates me with printing, though, since it’s based on making a view, and 
making sure that is page-cuttable. I made RTF-export for my app in the first 
place because I thought there was an easy conversion to printing.

Poking around Stack Overflow, I realized that the view to print can be an 
existing class. I could couple the document-data-to-NSAttributedString 
operation I already wrote with a NSTextView to make something that a 
NSPrintOperation could use:

> override func printOperation(withSettings printSettings: [String : Any]) 
> throws -> NSPrintOperation {
> // Copy the message to a string to print.
> var messageString: NSAttributedString! = /* … */
> 
> // Create a view to visualize the message string.
> var info = self.printInfo.copy() as! NSPrintInfo
> info.dictionary().addEntries(from: printSettings)
> 
> let view = NSTextView(frame: info.imageablePageBounds)
> view.autoresizingMask = [.viewWidthSizable, .viewHeightSizable]
> do {
> view.textStorage?.beginEditing()
> defer { view.textStorage?.endEditing() }
> 
> view.textStorage?.setAttributedString(messageString)
> }
> 
> return NSPrintOperation(view: view, printInfo: info)
> }

I hope it’s a nice first try, but I have some concerns.

1. I also added an “Export as PDF…” menu item, which uses the save-as-PDF 
default action. I guess it calls my code, but the docs for 
“NSDocument.pdfPrintOperation” say I should use a separate print-information 
objects for PDF mode. Does the default code take care of that already? Or do I 
have to figure out somehow if I’m in print-to-PDF mode or regular print mode 
and change the initialization of “info” above to be “self.pdfPrintOperation” as 
needed?

2. The RTF files I saved with the conversion operation have wrapping when 
viewed through QuickLook. But the print-outs don’t do that; they do wrap, but 
the limit is past the page margins so I lose part of the text. How can I set 
the wrapping-mode/margins correctly.

3. Are there any other (subtle) problems with the text-view code, since I just 
took it from Stack Overflow?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Printing in a Mac app with multiple philosophies

2017-03-11 Thread Daryle Walker
There are two IBActions for printing in a Mac app, “print:” and 
“printDocument:”. The Xcode project samples pick one of those actions to use 
based on if you requested a document-based app or not. But what are you 
supposed to do in a mixed-app, one with both NSDocument subclasses and 
printable non-document window systems? The menu item can point to only one 
action. Do I add a custom action that the menu item points to, and then 
implement that action in all my printable objects? (Those actions can redirect 
to “print(Document):” as needed.)

On a related note, what if I have a document class with multiple window types, 
and when I print I want to use the specific view of the current window? The 
document class’s print should probably be for total model coverage instead of a 
sub-view. I guess I can take my own advice from the first paragraph and do a 
custom print command. Now I have an interface question: what should I name the 
whole-model and specific window’s sub-view print actions? Should they be 
totally separate menu items, or with one hidden behind the Option key?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: How do I use a NSTextBlock in an attributed string?

2017-03-10 Thread Daryle Walker

> On Mar 9, 2017, at 7:05 AM, Daryle Walker <dary...@mac.com> wrote:
> 
>> 
>> On Mar 8, 2017, at 4:17 PM, Daryle Walker <dary...@mac.com> wrote:
>> 
>> I tried:
>> 
>>>   // Set the paragraph formatting for the body...
>>>   let bodyAdvancement = bodyFont.maximumAdvancement
>>>   let bodyIndent = max(bodyAdvancement.width, 
>>> bodyAdvancement.height) / 2.0
>>>   let bodyParagraphStyle = NSParagraphStyle.default().mutableCopy() 
>>> as! NSMutableParagraphStyle
>>>   bodyParagraphStyle.headIndent = bodyIndent
>>>   bodyParagraphStyle.lineBreakMode = .byWordWrapping
>>> 
>>>   // ...and separator
>>>   let separatorParagraphStyle = bodyParagraphStyle.mutableCopy() 
>>> as! NSMutableParagraphStyle
>>>   let separatorTextBlock = NSTextBlock()
>>>   separatorParagraphStyle.textBlocks.append(separatorTextBlock)
>>> 
>>>   // Set the body, but add a line for the initial separator
>>>   let richSeparator = NSMutableAttributedString(string: " \n", 
>>> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
>>> separatorParagraphStyle])
>>>   let richBody = NSMutableAttributedString(string: body, 
>>> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
>>> bodyParagraphStyle])
>>>   result.append(richSeparator)
>>>   result.append(richBody)
>> 
>> What I wanted: the separator line surrounded by a block.
>> What I got: the separator and the body all surrounded by a block.
>> 
>> I originally had the separator and body in a single string, and used a range 
>> to influence just the separator. This got the same result. I thought 
>> treating the separator and body in separate strings first wouldn’t infect 
>> the body with the text block, but it (illogically) does!
>> 
>> How do I end the influence of a block? Put -1 entries in the text-block 
>> array?
> 
> From tinkering around it seem like there is splatter dynamics when going 
> across ranges of text with different “textBlocks” settings, UNLESS the second 
> range uses no blocks. In just that case the second range copies the block 
> policy of the first range. This makes no sense.

I read the paragraph styles of my paragraphs, and their block settings are as 
expected. The separator has a single block, and the body has no blocks. This is 
a straight-up bug, but in Apple’s code (during rendering). That’s the problem 
with rarely-used/mentioned classes: not only does barely anyone knows how to 
use them, sometimes the creators didn’t do enough testing.

Since the bug is on Apple’s side (# 30968328), I can’t fix it and I’m stuck. 
The only idea in mind, besides giving up, is to create a 1x1 table. Now for 
more research….

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: How do I use a NSTextBlock in an attributed string?

2017-03-09 Thread Daryle Walker

> On Mar 8, 2017, at 4:17 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> I tried:
> 
>>// Set the paragraph formatting for the body...
>>let bodyAdvancement = bodyFont.maximumAdvancement
>>let bodyIndent = max(bodyAdvancement.width, 
>> bodyAdvancement.height) / 2.0
>>let bodyParagraphStyle = NSParagraphStyle.default().mutableCopy() 
>> as! NSMutableParagraphStyle
>>bodyParagraphStyle.headIndent = bodyIndent
>>bodyParagraphStyle.lineBreakMode = .byWordWrapping
>> 
>>// ...and separator
>>let separatorParagraphStyle = bodyParagraphStyle.mutableCopy() 
>> as! NSMutableParagraphStyle
>>let separatorTextBlock = NSTextBlock()
>>separatorParagraphStyle.textBlocks.append(separatorTextBlock)
>> 
>>// Set the body, but add a line for the initial separator
>>let richSeparator = NSMutableAttributedString(string: " \n", 
>> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
>> separatorParagraphStyle])
>>let richBody = NSMutableAttributedString(string: body, 
>> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
>> bodyParagraphStyle])
>>result.append(richSeparator)
>>result.append(richBody)
> 
> What I wanted: the separator line surrounded by a block.
> What I got: the separator and the body all surrounded by a block.
> 
> I originally had the separator and body in a single string, and used a range 
> to influence just the separator. This got the same result. I thought treating 
> the separator and body in separate strings first wouldn’t infect the body 
> with the text block, but it (illogically) does!
> 
> How do I end the influence of a block? Put -1 entries in the text-block array?

From tinkering around it seem like there is splatter dynamics when going across 
ranges of text with different “textBlocks” settings, UNLESS the second range 
uses no blocks. In just that case the second range copies the block policy of 
the first range. This makes no sense.

NSTextBlock is a rarely used class, so it’s hard to find sample code on it. I 
got some on <https://github.com/jyhong836/MarkdownAttribute>, but his/her 
handling code is spread over several files. But I don’t see how his/her code 
could work if the paragraph/block attribute doesn’t splatter upon range change. 
I don’t see that s/he is doing anything special to ensure a reset.

How is a paragraph defined in terms of applied paragraph styles? (Like if you 
fix an attributed-string’s paragraph styles, they are based on the setting of 
the “first” character.) Is it the first character after a line-break sequence 
to the end of the next line-break sequence?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

How do I use a NSTextBlock in an attributed string?

2017-03-08 Thread Daryle Walker
I tried:

> // Set the paragraph formatting for the body...
> let bodyAdvancement = bodyFont.maximumAdvancement
> let bodyIndent = max(bodyAdvancement.width, 
> bodyAdvancement.height) / 2.0
> let bodyParagraphStyle = NSParagraphStyle.default().mutableCopy() 
> as! NSMutableParagraphStyle
> bodyParagraphStyle.headIndent = bodyIndent
> bodyParagraphStyle.lineBreakMode = .byWordWrapping
> 
> // ...and separator
> let separatorParagraphStyle = bodyParagraphStyle.mutableCopy() 
> as! NSMutableParagraphStyle
> let separatorTextBlock = NSTextBlock()
> separatorParagraphStyle.textBlocks.append(separatorTextBlock)
> 
> // Set the body, but add a line for the initial separator
> let richSeparator = NSMutableAttributedString(string: " \n", 
> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
> separatorParagraphStyle])
> let richBody = NSMutableAttributedString(string: body, 
> attributes: [NSFontAttributeName: bodyFont, NSParagraphStyleAttributeName: 
> bodyParagraphStyle])
> result.append(richSeparator)
> result.append(richBody)

What I wanted: the separator line surrounded by a block.
What I got: the separator and the body all surrounded by a block.

I originally had the separator and body in a single string, and used a range to 
influence just the separator. This got the same result. I thought treating the 
separator and body in separate strings first wouldn’t infect the body with the 
text block, but it (illogically) does!

How do I end the influence of a block? Put -1 entries in the text-block array?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: My method causes DATA LOSS! (was: Can I use the restore/auto-save loading functions for imports?)

2017-03-06 Thread Daryle Walker
> On Mar 6, 2017, at 7:05 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> 
>> On Mar 6, 2017, at 4:58 PM, Daryle Walker <dary...@mac.com> wrote:
>> 
>> The docs fo “NSDocumentController.reopenDocument(for: withContentsOf: 
>> display: completionHandler:)” mention it’s for app restore. It ultimately 
>> calls “NSDocument.init(for: withContentsOf: ofType:)”, which mentions 
>> autosaved documents. Do I have to restrict these methods for their 
>> documented purposes? Or can I use them for general code, like an 
>> import-document function? They look perfect; they load in a file’s data to a 
>> new document, but leave the document’s file-identity anonymous afterwards.
> 
> I tried:
> 
>> extension DocumentController {
>> 
>>/**
>>An action method called by the Import command, it runs the modal Open 
>> panel and, based on the selected filenames, creates one or more `NSDocument` 
>> objects from the contents of the files, but stripping the file identities.
>> 
>>The method adds the newly created objects to the list of `NSDocument` 
>> objects managed by the document controller.  This method calls 
>> `reopenDocument(for:withContentsOf:display:completionHandler:)`, which 
>> actually creates the `NSDocument` objects.  The first parameter is set to 
>> `nil`, meaning the documents are initialized with the source data, but they 
>> don't point back to said source.
>> */
>>@IBAction func newDocumentFrom(_ sender: Any?) {
>>self.beginOpenPanel {
>>guard let files = $0 else { return }
>> 
>>for file in files {
>>self.reopenDocument(for: nil, withContentsOf: file, display: 
>> true) {
>>if let error = $2 {
>>self.presentError(error)  // Ignore if recovery was 
>> done.
>>}
>>print("Document: \($0); Already open: \($1); Error: 
>> \($2)")
>>}
>>}
>>}
>>}
>> 
>> }
> 
> Do not do this.
> 
> 1. When I load a file with normal open, then try my import action above, no 
> new window appears because the document has already been open once.
> 2. When my import was the first action on the file, there is a window with 
> that document’s data. But the file DISAPPEARS from the Finder! I guess using 
> these functions not as planned marked the file as temporary and cleared it.
> 
> Since I already created a NSDocumentController subclass, I could do it right. 
> Maybe I first call the regular open functionality, then:
> 
> A. If the document already exists, make a new unconnected copy with Duplicate.
> B. If the document didn’t exist, strip the file-URL and old file-name.

I actually unconditionally duplicate the loaded document and remove the first 
one if it wasn’t already open:

> @IBAction func newDocumentFrom(_ sender: Any?) {
> self.tryingImport = true
> self.beginOpenPanel { possibleFiles in
> self.tryingImport = false
> guard let files = possibleFiles else { return }
> 
> for file in files {
> self.imports.append(file)
> self.openDocument(withContentsOf: file, display: false) { 
> possibleDocument, alreadyOpen, possibleError in
> if let error = possibleError {
> self.presentError(error)  // Ignore any recovery
> }
> if alreadyOpen {
> self.imports.remove(at: self.imports.index(of: file)!)
> }
> if let document = possibleDocument {
> do {
> try self.duplicateDocument(withContentsOf: file, 
> copying: true, displayName: document.displayName)
> } catch {
> self.presentError(error) // Ignore any recovery
> }
> if !alreadyOpen {
> document.close()
> }
> }
> }
> }
> }
> }

It seems to be working so far. I have overrides of “addDocument” to not work if 
the file is in self.imports and of “runModalOpenPanel” to watch 
self.tryingImport and change the OK button accordingly (from “Open” to 
“Import”).

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

My method causes DATA LOSS! (was: Can I use the restore/auto-save loading functions for imports?)

2017-03-06 Thread Daryle Walker

> On Mar 6, 2017, at 4:58 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> The docs fo “NSDocumentController.reopenDocument(for: withContentsOf: 
> display: completionHandler:)” mention it’s for app restore. It ultimately 
> calls “NSDocument.init(for: withContentsOf: ofType:)”, which mentions 
> autosaved documents. Do I have to restrict these methods for their documented 
> purposes? Or can I use them for general code, like an import-document 
> function? They look perfect; they load in a file’s data to a new document, 
> but leave the document’s file-identity anonymous afterwards.

I tried:

> extension DocumentController {
> 
> /**
> An action method called by the Import command, it runs the modal Open 
> panel and, based on the selected filenames, creates one or more `NSDocument` 
> objects from the contents of the files, but stripping the file identities.
> 
> The method adds the newly created objects to the list of `NSDocument` 
> objects managed by the document controller.  This method calls 
> `reopenDocument(for:withContentsOf:display:completionHandler:)`, which 
> actually creates the `NSDocument` objects.  The first parameter is set to 
> `nil`, meaning the documents are initialized with the source data, but they 
> don't point back to said source.
>  */
> @IBAction func newDocumentFrom(_ sender: Any?) {
> self.beginOpenPanel {
> guard let files = $0 else { return }
> 
> for file in files {
> self.reopenDocument(for: nil, withContentsOf: file, display: 
> true) {
> if let error = $2 {
> self.presentError(error)  // Ignore if recovery was 
> done.
> }
> print("Document: \($0); Already open: \($1); Error: 
> \($2)")
> }
> }
> }
> }
> 
> }

Do not do this.

1. When I load a file with normal open, then try my import action above, no new 
window appears because the document has already been open once.
2. When my import was the first action on the file, there is a window with that 
document’s data. But the file DISAPPEARS from the Finder! I guess using these 
functions not as planned marked the file as temporary and cleared it.

Since I already created a NSDocumentController subclass, I could do it right. 
Maybe I first call the regular open functionality, then:

A. If the document already exists, make a new unconnected copy with Duplicate.
B. If the document didn’t exist, strip the file-URL and old file-name.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Can I use the restore/auto-save loading functions for imports?

2017-03-06 Thread Daryle Walker
The docs fo “NSDocumentController.reopenDocument(for: withContentsOf: display: 
completionHandler:)” mention it’s for app restore. It ultimately calls 
“NSDocument.init(for: withContentsOf: ofType:)”, which mentions autosaved 
documents. Do I have to restrict these methods for their documented purposes? 
Or can I use them for general code, like an import-document function? They look 
perfect; they load in a file’s data to a new document, but leave the document’s 
file-identity anonymous afterwards.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Enforcing Editor vs. Viewer (was: Which way should my document class handle an older format?)

2017-03-05 Thread Daryle Walker

> On Mar 4, 2017, at 3:40 AM, Daryle Walker <dary...@mac.com> wrote:
> 
> My document class reads in UTF-8 data for its internal format. The format has 
> an older version that is ASCII-based. Since the latter is a subset of the 
> former, my parser can handle both formats. Right now, I can’t write out in 
> the older format. (The new format is just a text dump upon save. The old 
> format would need to handle any post-ASCII values.)
> 
> I’m wondering how I should be the old format in the Info.plist. I could put 
> it in as a second document type. This lets me set it as “Viewer” 
> independently of the first format being set to “Editor.” Altering the message 
> and trying to save gives a system error about the file not being able to be 
> saved. However, the “isInViewMode” flag doesn’t get set, so the document is 
> editable! (But the edits can’t be saved.)
> 
> The other way is to have one document type entry in the Info.plist, but put 
> the old format as a second content type. Of course, it’ll always be in 
> “Editor.” And the save sheet gets a pop-up menu for the format to be saved. I 
> haven’t added an entry for exported-types in the p-list, so the menu is just 
> the first type. The second type isn’t in the menu and if I try to duplicate 
> the file (the new-world-order substitute for “Save As” since Lion), I get a 
> can’t-be-saved error.
> 
> I guess the second scenario seems to be what I want, but it still seems ugly. 
> Are there any better solutions?

It seems like TextEdit does it the first way, and so does sample code in a 
relevant StackOverflow query, so I’m switching back.

But, does Apple's default code for NSDocument do anything differently between 
an “Editor” and a “Viewer”? (This can happen if a edit-type shares the same 
document subclass as a view-type.) Or do I have to check which mode myself and 
enforce editor-ness vs. viewer-ness myself?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Overriding the automatic-save type

2017-03-05 Thread Daryle Walker
The NSDocument property “autosavingFileType” lets the developer indicate which 
one of the types the document class supports will be the one used for 
auto-saves. The notes at the website suggest that “init(for: withContentsOf: 
ofType:)” be overridden too. It punts to the TextEdit sample document class, 
but I don’t see anything that would help. However, could I use 
“NSDocumentController.typeForContents(of:)” to fill in the original file’s type?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Which way should my document class handle an older format?

2017-03-04 Thread Daryle Walker
My document class reads in UTF-8 data for its internal format. The format has 
an older version that is ASCII-based. Since the latter is a subset of the 
former, my parser can handle both formats. Right now, I can’t write out in the 
older format. (The new format is just a text dump upon save. The old format 
would need to handle any post-ASCII values.)

I’m wondering how I should be the old format in the Info.plist. I could put it 
in as a second document type. This lets me set it as “Viewer” independently of 
the first format being set to “Editor.” Altering the message and trying to save 
gives a system error about the file not being able to be saved. However, the 
“isInViewMode” flag doesn’t get set, so the document is editable! (But the 
edits can’t be saved.)

The other way is to have one document type entry in the Info.plist, but put the 
old format as a second content type. Of course, it’ll always be in “Editor.” 
And the save sheet gets a pop-up menu for the format to be saved. I haven’t 
added an entry for exported-types in the p-list, so the menu is just the first 
type. The second type isn’t in the menu and if I try to duplicate the file (the 
new-world-order substitute for “Save As” since Lion), I get a can’t-be-saved 
error.

I guess the second scenario seems to be what I want, but it still seems ugly. 
Are there any better solutions?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: I think I messed up the undo-count during load

2017-03-03 Thread Daryle Walker
Nearly a day later, and the bug doesn’t show up now. I hate Heisen-bugs. But is 
there a timing issue on how “NSManagedObjectContext.save” works?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

I think I messed up the undo-count during load

2017-03-02 Thread Daryle Walker
I got data loading working (-ish?) in my NSDocument-based app. But soon after 
the window opens, the “Edited” status appears. Here’s the method:

> override func read(from data: Data, ofType typeName: String) throws {
> guard UTTypeConformsTo(typeName as CFString, 
> Names.internationalEmailMessageUTI as CFString) else {
> throw CocoaError(.fileReadUnknown)
> }
> 
> // Parse the incoming data.
> let operationalMessage = InternetMessageReadingOperation(data: data)
> operationalMessage.start()
> assert(operationalMessage.isFinished)
> guard !operationalMessage.isCancelled else { throw 
> CocoaError(.userCancelled) }
> 
> // Create a document message object from the operation message object.
> var backgroundMessage: RawMessage!
> var backgroundError: Error?
> let backgroundContext = self.container.newBackgroundContext()
> backgroundContext.performAndWait {
> backgroundMessage = RawMessage(context: backgroundContext)
> // ...
> 
> do {
> try backgroundContext.save()
> } catch {
> backgroundError = error
> }
> }
> guard backgroundError == nil else { throw backgroundError! }
> 
> // Replace the current message with a copy of the new one.
> let mainContext = self.container.viewContext
> mainContext.performAndWait {
> self.undoManager?.disableUndoRegistration()
> defer { self.undoManager?.enableUndoRegistration() }
> 
> let oldMessage = self.message
> self.message = mainContext.object(with: 
> backgroundMessage.objectID) as! RawMessage
> mainContext.delete(oldMessage!)
> try! mainContext.save()  // Can't really recover; the new message 
> is already in.
> }
> }

The Document guide mentioned something about disabling undo during data load. 
Am I doing it right here? I’ve heard that “read(from: ofType:)” may be called 
during other times besides initial file load, so I want to get the swap-out 
functionality correct. Here’s a relevant part of “init()”:

> // Finish preparing the main context and seed the root message object.
> let mainContext = self.container.viewContext
> mainContext.performAndWait {
> self.message = RawMessage(context: mainContext)
> do {
> try mainContext.save()
> } catch let saveError {
> self.initError = saveError
> }
> }
> mainContext.automaticallyMergesChangesFromParent = true
> mainContext.undoManager = self.undoManager

Is “automaticallyMergesChangesFromParent” messing me up? Or is there some 
change-count reset function I should always call at the end?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: UTI and/or bundle-IDs with small letters

2017-03-02 Thread Daryle Walker

> On Mar 2, 2017, at 2:38 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> I’m trying out my document-based Mac app’s data-read routine, and the code it 
> being skipped. I actually check the typeName (i.e. the UTI) and it doesn’t 
> match. My bundle identifier for the app has capital letters. I base my 
> document’s main type off that identifier, so it also has capital letters. 
> Turns out that the system gives me the UTI in all small letters, so my 
> (Swift) “switch” fails and my no-matching-type code is executed. I know I 
> could switch my bundle ID to all small letters, but I want to know first if 
> this is documented? Or is the small-letters transformation a bug?
> 
> BTW, I looked at the TextEdit sample code, and it uses the type conformance 
> methods instead of an exact string match. Should I be doing that instead? 
> (Although that means no more “switch” statement.)

Before looking at the replies, I tried:

> override func read(from data: Data, ofType typeName: String) throws {
> guard UTTypeConformsTo(typeName as CFString, MyTypeUTI as CFString) 
> else {
> throw CocoaError(.fileReadUnknown)
> }

and it worked. So I’m going to switch all of my “switch” to “if-else” chains to 
use this function. The app-specific part of my bundle ID is an initialism, so 
I’m reluctant to make it small letters. So it’s debatable whether Apple making 
the UTIs it process in lowercase is a bug, but that Apple doesn’t seem to 
indicate anywhere that you can’t have a bundle-ID/UTI that differs from another 
solely by case definitely is a bug.

Bug # 30819460

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

UTI and/or bundle-IDs with small letters

2017-03-02 Thread Daryle Walker
I’m trying out my document-based Mac app’s data-read routine, and the code it 
being skipped. I actually check the typeName (i.e. the UTI) and it doesn’t 
match. My bundle identifier for the app has capital letters. I base my 
document’s main type off that identifier, so it also has capital letters. Turns 
out that the system gives me the UTI in all small letters, so my (Swift) 
“switch” fails and my no-matching-type code is executed. I know I could switch 
my bundle ID to all small letters, but I want to know first if this is 
documented? Or is the small-letters transformation a bug?

BTW, I looked at the TextEdit sample code, and it uses the type conformance 
methods instead of an exact string match. Should I be doing that instead? 
(Although that means no more “switch” statement.)

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Search terms with NSDocument and Apple Events

2017-03-02 Thread Daryle Walker
The open-file Apple Event may contain a parameter for a search term. After 
opening a file for a document, if there is a search term, and the document 
window supports searching, then fill in the window’s search field with the 
event’s search term.

The guide for "NSDocument.canConcurrentlyReadDocuments(ofType:)” mentions that 
your opening routine can’t get access to the Apple Event when running in 
multi-threaded mode. So they suggestion not activating that mode for your 
document class if you need to inspect the search term. But couldn’t you do that 
in NSDocumentController instead?

Right now, I’m pulling the trigger on concurrent opening. Then I’m thinking of 
overriding “NSDocumentController.openDocument(withContentsOf: display: 
completionHandler:)". Before calling super, I would check the Apple Event then 
to extract any search term. Then I would write a closure that checks if a 
document matches a custom protocol, and if the document class matches, use the 
protocol to pass the search term to the document. This new closure wraps the 
completionHandler argument already given and will be the handler passed on to 
super instead. That seems OK to work (in my head, at least).

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: macOS 10.13 suggestion for init() throws

2017-03-01 Thread Daryle Walker

> On Feb 28, 2017, at 4:26 PM, Jens Alfke <j...@mooseyard.com> wrote:
> 
> 
>> On Feb 28, 2017, at 11:56 AM, Daryle Walker <dary...@mac.com 
>> <mailto:dary...@mac.com>> wrote:
>> 
>> The problem here is an interface mismatch where Swift has function 
>> throw-ability status out-of-band from that function’s parameter list, while 
>> Objective-C doesn’t.
> 
> Only at the syntax level. Under the hood it works basically the same way as 
> Objective-C, with the error as a hidden ‘out’ parameter. (It pretty much has 
> to, for interoperability purposes.)
> 
> So an init() method that throws is a different method with a different 
> signature than one that doesn’t; the two aren’t type-compatible. And I don’t 
> think the two can coexist in one scope, because they’d be ambiguous at the 
> call site. So adding a throwing initializer to NSDocument would require 
> removing the non-throwing one, which can’t be done for backward-compatibility 
> reasons.

A throwable “init()” would require a “try” in front of it. If Swift bans 
non-throwable code from being prefixed with “try”, then the two versions could 
be distinguishable. Can an initializer be used for a closure property (i.e. 
function pointer)? Then in that case there could be a problem, since 
non-throwable functions are subsets are throwable ones (so a closure to a 
throwable method would accept both).

> I’m sure there are some hacky special-case workarounds that could be done to 
> make this work, if this were a really important aspect of the AppKit API. But 
> I don’t think it is. It may be annoying that the common code shared between 
> your initializers can’t throw, but there are simple workarounds.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Replacement of deprecated API GetProcessInformation

2017-02-28 Thread Daryle Walker

> On Feb 28, 2017, at 2:35 PM, Steve Mills <sjmi...@mac.com> wrote:
> 
> The process signature is an old way of identifying applications and 
> processes. The modern equivalent would be the bundle identifier. From an 
> NSRunningApplication you can get its bundleIdentifier. If you need more info, 
> you can probably get the NSBundle for it and gets its infoDictionary. The 
> process type is the CFBundlePackageType entry in the dict. Note that the 
> CFBundleSignature is also in there, but not all apps will have a decent value 
> in there.

Or any value. Between starting a Mac app project in Xcode 7 and 8, the latter 
dropped the signature entry in the default-generated Info.plist file.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: macOS 10.13 suggestion for init() throws

2017-02-28 Thread Daryle Walker

> On Feb 28, 2017, at 12:27 PM, Jens Alfke <j...@mooseyard.com> wrote:
> 
> 
>> On Feb 28, 2017, at 4:56 AM, Daryle Walker <dary...@mac.com 
>> <mailto:dary...@mac.com>> wrote:
>> 
>> Could we have a NSDocument.init() that throws in the next macOS? That would 
>> translate to a "initWithError" in Objective C (I think). It would be the new 
>> primary initializer, with the current one calling it and dropping any error 
>> to oblivion.
> 
> If you’re doing anything that might fail, you should do it in an override of 
> one of the other NSDocument initializers, which do return errors. The basic 
> -init method is explicitly documented as not allowing failure.

The no-parameter initializer for NSDocument is for code that is common to the 
other initializer calls (which are directly called from NSDocumentController). 
Those initializers can throw, so if your common initialization code has 
throwable elements, you need to save it in an (optional) Error object, then 
check and throw it in the other initializer. The problem here is an interface 
mismatch where Swift has function throw-ability status out-of-band from that 
function’s parameter list, while Objective-C doesn’t. Since Objective-C uses a 
gentleman’s agreement to handle any errors through an extra parameter, its 
initializers can’t simultaneously be parameter-less and throw-able. My 
experience with this workaround inspired me that we can improve the interface 
w.r.t. Swift.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

macOS 10.13 suggestion for init() throws

2017-02-28 Thread Daryle Walker
Could we have a NSDocument.init() that throws in the next macOS? That would 
translate to a "initWithError" in Objective C (I think). It would be the new 
primary initializer, with the current one calling it and dropping any error to 
oblivion.

This doesn't make any difference to Objective-C subclasses, which can use any 
parent class initializer, but would help in Swift, which needs store and 
release any "init" errors.

Sent from my iPhone
___

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


Memory-mapped sub-data?

2017-02-26 Thread Daryle Walker
If I take a "subdata" of a memory-mapped (NS)Data, does it stay mapped (i.e. 
use a range and reference)? Or does a full copy get made? I'm thinking of 
making a parser be a sub-parser too, and this would make the difference between 
scanning the next megabyte or the rest-of-file (even if it's gigabytes).

Sent from my iPhone
___

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: I think I screwed up Core Data multi-threading rules.

2017-02-25 Thread Daryle Walker

> On Feb 23, 2017, at 10:43 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Feb 23, 2017, at 18:25 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>>>override func save(to url: URL, ofType typeName: String, for 
>>> saveOperation: NSSaveOperationType, completionHandler: @escaping (Error?) 
>>> -> Void) {
>>>// Save the message data to the store so any background contexts can 
>>> read the data later.
>>>do {
>>>try self.container.viewContext.save()
>>>} catch {
>>>completionHandler(error)
>>>return
>>>}
>>> 
>>>// Do the usual code, possibly even use a background thread.
>>>super.save(to: url, ofType: typeName, for: saveOperation, 
>>> completionHandler: completionHandler)
>>>}
>> 
>> I found out about this method from the Document guide docs. I have two 
>> questions about it.
>> 
>> 1. Is it OK to abort your override before the call to super if your 
>> pre-super code gets an error?
> 
> The catch block you’ve shown seems perfectly reasonable. Unfortunately, the 
> documentation says you can do anything you want before or after, but “be sure 
> to invoke super”, which probably makes you nervous. However, I think you can 
> assume it’s ok to return like that if an error preventing the save occurs. 
> Any other assumption seems too paranoid.
> 
> The documentation also says that the completion handler must be invoked on 
> the main thread, and I doubt you can assume that this save function is itself 
> necessarily invoked on the main thread. IAC, it’s only one extra line to 
> invoke the completion handler on the main thread, so I’d do that.

I thought the entire AppKit, which includes NSDocument, runs only on the main 
thread. The exceptions are methods that specially state that they have a 
multi-threaded mode. There are two methods on NSDocument, one each for reading 
and writing, that enable multi-threading that you have to override to return 
TRUE. If enabled, the background thread for writing is created within “save(to: 
ofType: for: completionHandler:)” and the one for reading within 
“NSDocumentController.openDocument(withContentsOf: display: 
completionHandler:)”.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: I think I screwed up Core Data multi-threading rules.

2017-02-23 Thread Daryle Walker

> On Feb 23, 2017, at 1:56 AM, Daryle Walker <dary...@mac.com> wrote:
> 
> I naively thought this was OK, multi-threading wise. It worked before I added 
> the “canAsynchronusly…” method to say TRUE for my main file type. When that 
> method is added, the save hangs the program.
> 
>>override func data(ofType typeName: String) throws -> Data {
>>guard typeName == Names.internationalEmailMessageUTI else { throw 
>> NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) }
>> 
>>// Save the current message data to the store so a background task 
>> can see it.
>>var messageID: NSManagedObjectID?
>>var savingError: Error?
>>let mainContext = self.container.viewContext
>>mainContext.performAndWait {
>>do {
>>try mainContext.save()
>>} catch {
>>savingError = error
>>}
>>messageID = self.message?.objectID
>>}
>> 
>>// Let the main interface continue.
>>self.unblockUserInteraction()
>>guard savingError == nil else { throw savingError! }
>>guard messageID != nil else { throw NSError(domain: 
>> NSCocoaErrorDomain, code: NSCoreDataError, userInfo: nil) }
>> 
>>// Write out the message data for externalization.
>>var result: Data?
>>let backgroundContext = self.container.newBackgroundContext()
>>backgroundContext.performAndWait {
>>let backgroundMessage = backgroundContext.object(with: 
>> messageID!) as! RawMessage
>>result = backgroundMessage.messageAsExternalData
>>}
>>return result!
>>}
> 
> I use the original and the background copy of the message only within each of 
> their respective contexts. Is the new persistent-container class not 
> thread-safe even for returning (new) contexts? Am I calling 
> “unblockUserInteraction” inappropriately? (I had that question in another 
> post.) Is it the way I handle throwing?

It seems that “data(ofType:)” REALLY means it when the main interface is 
blocked until “unblockUserInteraction()” is called. The whole method is called 
in an alternate thread, which means that any of your setup code (i.e. make an 
independent copy) that MUST be on the main thread has to be called somewhere 
else.

Fortunately, there is a somewhere else:

> override func save(to url: URL, ofType typeName: String, for 
> saveOperation: NSSaveOperationType, completionHandler: @escaping (Error?) -> 
> Void) {
> // Save the message data to the store so any background contexts can 
> read the data later.
> do {
> try self.container.viewContext.save()
> } catch {
> completionHandler(error)
> return
> }
> 
> // Do the usual code, possibly even use a background thread.
> super.save(to: url, ofType: typeName, for: saveOperation, 
> completionHandler: completionHandler)
> }

I found out about this method from the Document guide docs. I have two 
questions about it.

1. Is it OK to abort your override before the call to super if your pre-super 
code gets an error?
2. What should happen if your post-super code (which I don’t have in my 
example) has an error? Do you drop it to oblivion? Or can you call the 
completion handler? Note that if the call to super has its own errors, then 
your post-super code would make the handler be called twice.

Now I can keep all the save code in the same thread:

> override func canAsynchronouslyWrite(to url: URL, ofType typeName: 
> String, for saveOperation: NSSaveOperationType) -> Bool {
> switch typeName {
> case Names.internationalEmailMessageUTI:
> return true
> default:
> return super.canAsynchronouslyWrite(to: url, ofType: typeName, 
> for: saveOperation)
> }
> }
> 
> override func data(ofType typeName: String) throws -> Data {
> guard typeName == Names.internationalEmailMessageUTI else { throw 
> NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) }
> 
> // Note the message's ID so a background context can find it later.
> let messageID: NSManagedObjectID = self.message.objectID
> self.unblockUserInteraction()
> 
> // Write out the message data for externalization.
> var messageData: Data?
> let backgroundContext = self.container.newBackgroundContext()
> backgroundContext.performAndWait {
> let backgroundMessage = backgroundContext.object(with: messageID) 
> as! RawMessage
>

I think I screwed up Core Data multi-threading rules.

2017-02-22 Thread Daryle Walker
I naively thought this was OK, multi-threading wise. It worked before I added 
the “canAsynchronusly…” method to say TRUE for my main file type. When that 
method is added, the save hangs the program.

> override func data(ofType typeName: String) throws -> Data {
> guard typeName == Names.internationalEmailMessageUTI else { throw 
> NSError(domain: NSOSStatusErrorDomain, code: unimpErr, userInfo: nil) }
> 
> // Save the current message data to the store so a background task 
> can see it.
> var messageID: NSManagedObjectID?
> var savingError: Error?
> let mainContext = self.container.viewContext
> mainContext.performAndWait {
> do {
> try mainContext.save()
> } catch {
> savingError = error
> }
> messageID = self.message?.objectID
> }
> 
> // Let the main interface continue.
> self.unblockUserInteraction()
> guard savingError == nil else { throw savingError! }
> guard messageID != nil else { throw NSError(domain: 
> NSCocoaErrorDomain, code: NSCoreDataError, userInfo: nil) }
> 
> // Write out the message data for externalization.
> var result: Data?
> let backgroundContext = self.container.newBackgroundContext()
> backgroundContext.performAndWait {
> let backgroundMessage = backgroundContext.object(with: 
> messageID!) as! RawMessage
> result = backgroundMessage.messageAsExternalData
> }
> return result!
> }

I use the original and the background copy of the message only within each of 
their respective contexts. Is the new persistent-container class not 
thread-safe even for returning (new) contexts? Am I calling 
“unblockUserInteraction” inappropriately? (I had that question in another 
post.) Is it the way I handle throwing?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

When to call unblockUserInteraction()

2017-02-22 Thread Daryle Walker
Although that method doesn't mention it, can I call it during data(ofType:), 
which is called by those other methods by default (I think)?

Sent from my iPad
___

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


Typing into a NSTextView and overriding it

2017-02-20 Thread Daryle Walker
1. How can one type in control characters into a text-view? I mean ASCII range 
0 through 31 and 127, not counting horizontal-tab and line-feed.
2. Is there a way to filter out the user from typing (or pasting, etc.) 
characters you don't want (like NUL)?
3. Is there a way to limit the length of a line? Probably using a testing 
function.

Sent from my iPad
___

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: How hard is it to make a NSOrderedSetController?

2017-02-18 Thread Daryle Walker

> On Feb 19, 2017, at 2:30 AM, Daryle Walker <dary...@mac.com> wrote:
> 
> There is one problem though. The button for “add:” works; it adds a new 
> entry. But the button for the “remove:” action only works once. Worse, it 
> only removes the last added row, no matter which row is selected! Another 
> symptom is the rows I add during “init:”; I can’t get rid of any of them even 
> if I don’t add new rows. It’s like all the rows are fixed as soon as the next 
> row is created (except for the row before the window is created; they’re 
> always fixed). I don’t know if it’s a problem with this technique or normal 
> NSArrayController and/or Core Data shenanigans.

I forgot to add a binding between the table’s and array-controller’s selection 
index-lists. (I already had one for content, of course.)

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: How hard is it to make a NSOrderedSetController?

2017-02-18 Thread Daryle Walker

> On Feb 18, 2017, at 7:06 PM, Keary Suska <cocoa-...@esoteritech.com> wrote:
> 
> 
>> On Feb 18, 2017, at 4:44 PM, Daryle Walker <dary...@mac.com> wrote:
>> 
>> I’m using a NSValueTransformer object to convert my Core Data to-many 
>> ordered relationship from a NSOrderedSet to a NSArray so NSArrayController 
>> can use it. I just connected a NSButton to the controller’s “add:” action. I 
>> get this:
>> 
>>> NSManagedObjects of entity 'Message' do not support 
>>> -mutableArrayValueForKey: for the property ‘header'
>> 
>> So it seems that the controller skips my converted value and tries to alter 
>> the property directly, which it can’t. I thought that the problem was that 
>> NSOrderedSet.array returns an array of funny proxies, but manually copying 
>> to a NSMutableArray and returning that didn’t work either. So it seems that 
>> I have to make custom actions to add objects, and hopefully the controller 
>> will see the changes.
>> 
>> But I’m wondering if I should go nuclear and create the 
>> NSOrderedSetController that Apple should have done years ago. I don’t know 
>> how hard this’ll be. It would be a serving-side Binding class. It would 
>> inherit from NSObjectController since NSArrayController would have those 
>> extra NSArray/NSSet connection methods.
>> 
>> Does the Bindings section of the Interface Builder section of Xcode 
>> hard-code the Bindings list, or will it create entries for custom 
>> Binding-capable classes? If the answer is no customization, then I would 
>> have to connect the NSManagedObject instance to the controller in code.
> 
> OTOH, it may be easier to implement a to-many accessor pattern for the 
> attribute 
> <https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/KeyValueCoding/DefiningCollectionMethods.html#//apple_ref/doc/uid/1107i-CH17-SW1>.
>  You may need to use a different key name to get prevent Core Data from 
> interfering, say “headerAsArray” or whatever.

This worked! Thank you.

There is one problem though. The button for “add:” works; it adds a new entry. 
But the button for the “remove:” action only works once. Worse, it only removes 
the last added row, no matter which row is selected! Another symptom is the 
rows I add during “init:”; I can’t get rid of any of them even if I don’t add 
new rows. It’s like all the rows are fixed as soon as the next row is created 
(except for the row before the window is created; they’re always fixed). I 
don’t know if it’s a problem with this technique or normal NSArrayController 
and/or Core Data shenanigans.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

How hard is it to make a NSOrderedSetController?

2017-02-18 Thread Daryle Walker
I’m using a NSValueTransformer object to convert my Core Data to-many ordered 
relationship from a NSOrderedSet to a NSArray so NSArrayController can use it. 
I just connected a NSButton to the controller’s “add:” action. I get this:

> NSManagedObjects of entity 'Message' do not support -mutableArrayValueForKey: 
> for the property ‘header'

So it seems that the controller skips my converted value and tries to alter the 
property directly, which it can’t. I thought that the problem was that 
NSOrderedSet.array returns an array of funny proxies, but manually copying to a 
NSMutableArray and returning that didn’t work either. So it seems that I have 
to make custom actions to add objects, and hopefully the controller will see 
the changes.

But I’m wondering if I should go nuclear and create the NSOrderedSetController 
that Apple should have done years ago. I don’t know how hard this’ll be. It 
would be a serving-side Binding class. It would inherit from NSObjectController 
since NSArrayController would have those extra NSArray/NSSet connection methods.

Does the Bindings section of the Interface Builder section of Xcode hard-code 
the Bindings list, or will it create entries for custom Binding-capable 
classes? If the answer is no customization, then I would have to connect the 
NSManagedObject instance to the controller in code.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: A horizontal line rule within a NSAttributedString?

2017-02-18 Thread Daryle Walker
What is the attachment supposed to be? An image of a line? That doesn’t seem 
scalable (to the page size). And the effort seems to be the same as figuring 
out NSTextBlock.

> On Feb 18, 2017, at 5:43 PM, Gary L. Wade <garyw...@desisoftsystems.com> 
> wrote:
> 
> I would use NSTextAttachment, create an attributed string from it, and 
> combine your three attributed strings into one.
> --
> Gary L. Wade
> http://www.garywade.com/ <http://www.garywade.com/>
>> On Feb 18, 2017, at 2:16 PM, Daryle Walker <dary...@mac.com 
>> <mailto:dary...@mac.com>> wrote:
>> 
>> An idea for formatted output of my data is the two sections turned into 
>> attributed strings, with a line between them. But I couldn’t figure out how 
>> to make a line. I didn’t want to resort to raw drawing commands. I prefer 
>> not to create (X)HTML representations (so I could put a “” in between). 
>> Poking around NSAttributedString, there seems to be a NSTextBlock that could 
>> do it. Any advice on how?


— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

A horizontal line rule within a NSAttributedString?

2017-02-18 Thread Daryle Walker
An idea for formatted output of my data is the two sections turned into 
attributed strings, with a line between them. But I couldn’t figure out how to 
make a line. I didn’t want to resort to raw drawing commands. I prefer not to 
create (X)HTML representations (so I could put a “” in between). Poking 
around NSAttributedString, there seems to be a NSTextBlock that could do it. 
Any advice on how?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

NSArrayController still doesn't support NSOrderedSet? (was: Are instances of a NSManagedObject subclass usable as regular objects?)

2017-02-15 Thread Daryle Walker

> On Feb 14, 2017, at 6:50 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> Looking at my code again, I had a massive brain-fart. I created all the data 
> objects with local “let,” but forgot to assign the top-level object to my 
> document’s data property.
> 
> Once I did that, the window doesn’t show up at all due to a different problem:
> 
>> 2017-02-14 18:43:00.018210 XNW[13100:1621112] Cannot create NSArray from 
>> object Relationship 'header' on managed object (0x60885460) 
>>  (entity: Message; id: 
>> 0x60031300 > > ; data: {
>>body = "Is this an accurate test?";
>>header = (
>>"0x600312a0 
>> > >",
>>"0x60031140 
>> > >"
>>);
>> }) with objects {(
>> (entity: HeaderField; 
>> id: 0x600312a0 
>> > > ; data: {
>>body = World;
>>message = "0x60031300 
>> > >";
>>name = Hi;
>> }),
>> (entity: HeaderField; 
>> id: 0x60031140 
>> > > ; data: {
>>body = planet;
>>message = "0x60031300 
>> > >";
>>name = Bye;
>> })
>> )} of class _NSFaultingMutableOrderedSet
> 
> This error came up twice on app start. It came up once more when I tried 
> clicking on the app icon.

I used the classic method of performing a web-search on “Cannot create NSArray 
from object Relationship”. I got a page 
<http://stackoverflow.com/questions/15078679/binding-an-ordered-relationship-with-an-nsarraycontroller>.
 I used the marked answer. I couldn’t find the page sited (nor the GitHub 
project) except through a web-archive site. It works, as far as reading is 
concerned, but I don’t know if it’ll write changes too.

Is this still needed? I’m surprised that NSArrayController supports NSArray and 
NSSet, but not (yet?) NSOrderedSet. This seems like a major bug. It’s like the 
old solution, taint your data with an order index field, was never updated 
among Apple projects, so no one noticed that the NSOrderedSet code didn’t 
actually work! Maybe I’ll file a bug after some sleep.

[The “come up twice” bug was from my last run having two documents open, 
somehow. I couldn’t see since the bug were jamming windows being shown. I 
suspected it when I added Core Data undo, but didn’t turn it off during object 
load, leading to TWO save-before-closing alerts!]

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Throwing an error from a NSDocument.init override

2017-02-15 Thread Daryle Walker

> On Feb 14, 2017, at 1:24 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Feb 14, 2017, at 00:26 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> But I can’t call the “super” versions of those other initializers from 
>> within my override.
> 
> This is the essence of your problem. Your “override” cannot be a convenience 
> initializer because convenience initializers cannot call “up” to the 
> superclass, and it cannot be a designated initializer because designated 
> initializers cannot call convenience initializers. For one solution, see here:
> 
>   
> http://stackoverflow.com/questions/38908902/overwriting-nsdocuments-initcontentsofoftype-in-swift
>  
> <http://stackoverflow.com/questions/38908902/overwriting-nsdocuments-initcontentsofoftype-in-swift>
> 
> Answering the same question in another way, look at the comments for 
> init(type:) in the NSDocument header file:
> 
>> "Initialize a new empty document of a specified type, and return it if 
>> successful. If not successful, return nil after setting *outError to an 
>> NSError that encapsulates the reason why the document could not be 
>> initialized. The default implementation of this method just invokes [self 
>> init] and [self setFileType:typeName].”
> 
> 
> This tells you exactly what the superclass convenience initializer does, and 
> the fact that it’s in the header file makes the behavior a public API 
> contract. So, you are allowed to implement your own subclass convenience 
> initializer (that throws) which does *not* invoke super, but simply does what 
> the super method is documented to do. (That’s basically the solution given on 
> Stack Overflow.)

This is what I did; repeat the three initializers. Apple’s code will call my 
versions instead of the ones in NSDocument, right?

The given notes don’t say how to get the modification date, but I got it from 
the StackOverflow article you mentioned. For the initializer that can take a 
“URL?” for a decoy file, which modification date are you supposed to use? My 
code uses “(urlOrNil ?? contentsURL)” to decide. Is that right?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Are instances of a NSManagedObject subclass usable as regular objects?

2017-02-14 Thread Daryle Walker
Looking at my code again, I had a massive brain-fart. I created all the data 
objects with local “let,” but forgot to assign the top-level object to my 
document’s data property.

Once I did that, the window doesn’t show up at all due to a different problem:

> 2017-02-14 18:43:00.018210 XNW[13100:1621112] Cannot create NSArray from 
> object Relationship 'header' on managed object (0x60885460) 
>  (entity: Message; id: 
> 0x60031300  
> ; data: {
> body = "Is this an accurate test?";
> header = (
> "0x600312a0 
> ",
> "0x60031140 
> "
> );
> }) with objects {(
>  (entity: HeaderField; 
> id: 0x600312a0 
>  ; data: {
> body = World;
> message = "0x60031300 
> ";
> name = Hi;
> }),
>  (entity: HeaderField; 
> id: 0x60031140 
>  ; data: {
> body = planet;
> message = "0x60031300 
> ";
> name = Bye;
> })
> )} of class _NSFaultingMutableOrderedSet

This error came up twice on app start. It came up once more when I tried 
clicking on the app icon.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT com 

> On Feb 14, 2017, at 6:16 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> I’m on macOS Sierra, running Swift 3 on Xcode 8.
> 
> I started the basic document-based project, with storyboards but without Core 
> Data. The main window has a table view and a text view. I connected them to 
> my document’s data object with Cocoa Bindings. I put in sample data into the 
> object and the window shows said data when run.
> 
> Now I want to switch to Core Data. I made a framework with the data model 
> file and the NSMangedObject subclasses (with slight tweaks). Usually, the 
> developer would use all the whiz-bang features of Bindings, CD fetches, 
> object controllers, and array controllers with the window. But I want the 
> Core Data change and the window change to be separate Git commits. So I just 
> replaced the name of my old data classes with my NSMangedObject subclasses.
> 
> The views come up blank when run. During “makeWindowControllers,” I print out 
> my top level data object, which is now of type “MyMangedObjectSubclass!”. I 
> crash with a NIL-dereference error. I guess it’s somebody’s fault (pun 
> totally intended). How do I give managed objects enough permanence to be used 
> with systems expecting normal objects?
> 
> [I’m at the stage where I know just enough to be dangerous, but not enough to 
> know what I’m actually doing.]

___

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

Are instances of a NSManagedObject subclass usable as regular objects?

2017-02-14 Thread Daryle Walker
I’m on macOS Sierra, running Swift 3 on Xcode 8.

I started the basic document-based project, with storyboards but without Core 
Data. The main window has a table view and a text view. I connected them to my 
document’s data object with Cocoa Bindings. I put in sample data into the 
object and the window shows said data when run.

Now I want to switch to Core Data. I made a framework with the data model file 
and the NSMangedObject subclasses (with slight tweaks). Usually, the developer 
would use all the whiz-bang features of Bindings, CD fetches, object 
controllers, and array controllers with the window. But I want the Core Data 
change and the window change to be separate Git commits. So I just replaced the 
name of my old data classes with my NSMangedObject subclasses.

The views come up blank when run. During “makeWindowControllers,” I print out 
my top level data object, which is now of type “MyMangedObjectSubclass!”. I 
crash with a NIL-dereference error. I guess it’s somebody’s fault (pun totally 
intended). How do I give managed objects enough permanence to be used with 
systems expecting normal objects?

[I’m at the stage where I know just enough to be dangerous, but not enough to 
know what I’m actually doing.]

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Throwing an error from a NSDocument.init override

2017-02-14 Thread Daryle Walker
The parameter-less version of “init” in NSDocument can’t throw. It’s suggesting 
to (save the error somehow and then) throw the error from one of the other 
initializers. This counts on the fact that you won’t initialize a NSDocument 
(subclass) instance with no parameters, but call one of the others, which calls 
“init()”.

But I can’t call the “super” versions of those other initializers from within 
my override. In fact, I can’t create overrides of them; the Swift compiler 
won’t auto-complete and insists that I mark them as “convenience” initializers. 
And I am limited to my “self.init()” call to start them up. Do I have to 
manually recreate the algorithm for each initializer overload(?)? Will 
NSDocumentController and other parts of the framework see my “overrides” of the 
standard NSDocument initializers and use them instead? Or should I just forget 
about throwing errors from “init()”? I could just call “fatalError” or similar 
instead.

(Oh, I got error objects because I’m initializing my (per-document) Core Data 
stack in “init()”.)

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Does the NSPersistentContainer name mean anything?

2017-02-12 Thread Daryle Walker
For the one-argument initializer, the name is used to figure out where the 
model file is. But I’m using the two-argument initializer, where I already give 
the model file’s location (because it’s in my framework’s bundle). Can I just 
put any random thing there (even an empty string), or is the name still 
relevant?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Is it OK to use the default initializer of NSPersistentStoreDescription?

2017-02-12 Thread Daryle Walker
When I was typing in a test object of type NSPersistentStoreDescription (on 
Xcode 8 with Swift 3), the auto-complete gave me two initializers. Besides the 
documented one that takes a URL, there’s one that takes no arguments. Its own 
notes say it’s for subclasses. I, however, am describing an in-memory store, 
which doesn’t need a URL (as far as I know).

Is this an official way to start declaring a NSPersistentStoreDescription (for 
in-memory stores)? Or should I put in a junk URL in the publicized initializer 
then set the field to NIL?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Optionality in a NSManagedObject sub-class

2017-02-10 Thread Daryle Walker

> On Feb 10, 2017, at 3:02 AM, Daryle Walker <dary...@mac.com> wrote:
> 
> It’s simple:
> 
> - I’m writing this framework for an app, both macOS, with Swift 3 and Xcode 8.
> - My protocol has two non-optional strings.
> - I unchecked “Optional” for those attributes when editing the model file.
> - I used “Manual/None” for generation, then used the menu command to create 
> the declaration and properties-extension files anyway.
> - The class uses “String?”, i.e. optionals, for my attributes.
> - This keeps the managed-object sub-class from matching the protocol when I 
> add it from another extension (in a new file).
> 
> The properties are mandatory. So is it OK to change the generated versions to 
> non-optionals? What’s the risk/trade-offs if I do so?

I gave up and used an adaptor:

> extension RawHeaderField {
> /// Adapter for core properties to conform to InternetMessageHeaderField, 
> since CoreData prefers to properties to be optionals.
> public class FieldAdapter: NSObject, InternetMessageHeaderMutableField {
> private var source: RawHeaderField
> public dynamic var name: String {
> get { return source.name ?? “" }
> set { source.name = newValue }
> }
> public dynamic var body: String {
> get { return source.body ?? “" }
> set { source.body = newValue }
> }
> 
> init(source: RawHeaderField) {
> self.source = source
> }
> }
> 
> /// A level of redirection since `RawHeaderField` can't directly conform 
> to `InternetMessageHeaderField`.
> public dynamic var field: FieldAdapter {
> return FieldAdapter(source: self)
> }
> }

Hmm, I had to add that since just taking out the “?” suffixes caused a weird 
link error. I removed them again to show all of you the error, but the 
framework compiled/linked successfully.

…

I commented out the “field” declaration to make sure that wasn’t “fixing” my 
original problem, but it still didn’t come back. There was some sort of link 
error over the (direct) “name” and “body” properties, and suggested using the 
“-v” on the linker. But I can’t reproduce it now. Maybe it was a first-time 
making the objects error.

…

Nope, running “Clean” and re-compiling/linking/testing didn’t bring the error 
back. I’ll respond if it happens later.

…

Oh, I forgot to copy the protocol declaration back to the extension on the 
first line. That brought the error back:

> Ld 
> /Users/daryle/Library/Developer/Xcode/DerivedData/XNW-erfebwrlefqdajcsjohyazbstkyo/Build/Intermediates/CodeCoverage/Products/Debug/InternetMessages.framework/Versions/A/InternetMessages
>  normal x86_64
> cd /Users/daryle/Documents/Repositories/XNW/XNW
> export MACOSX_DEPLOYMENT_TARGET=10.12
> 
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
>  -arch x86_64 -dynamiclib -isysroot 
> /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
>  
> -L/Users/daryle/Library/Developer/Xcode/DerivedData/XNW-erfebwrlefqdajcsjohyazbstkyo/Build/Intermediates/CodeCoverage/Products/Debug
>  
> -F/Users/daryle/Library/Developer/Xcode/DerivedData/XNW-erfebwrlefqdajcsjohyazbstkyo/Build/Intermediates/CodeCoverage/Products/Debug
>  -filelist 
> /Users/daryle/Library/Developer/Xcode/DerivedData/XNW-erfebwrlefqdajcsjohyazbstkyo/Build/Intermediates/CodeCoverage/Intermediates/XNW.build/Debug/InternetMessages.build/Objects-normal/x86_64/InternetMessages.LinkFileList
>  -install_name @rpath/InternetMessages.framework/Versions/A/InternetMessages 
> -Xlinker -rpath -Xlinker @executable_path/../Frameworks -Xlinker -rpath 
> -Xlinker @loader_path/Frameworks -mmacosx-version-min=10.12 -Xlinker 
> -object_path_lto -Xlinker 
> /Users/daryle/Library/Developer/Xcode/DerivedData/XNW-erfebwrlefqdajcsjohyazbstkyo/Build/Intermediates/CodeCoverage/Intermediates/XNW.build/Debug/InternetMessages.build/Objects-normal/x86_64/InternetMessages_lto.o
>  -Xlinker -export_dynamic -Xlinker -no_deduplicate -fobjc-link-runtime 
> -fprofile-instr-generate 
> -L/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx
>  -Xlinker -add_ast_path -Xlinker 
> /Users/daryle/Library/Developer/Xcode/DerivedData/XNW-erfebwrlefqdajcsjohyazbstkyo/Build/Intermediates/CodeCoverage/Intermediates/XNW.build/Debug/InternetMessages.build/Objects-normal/x86_64/InternetMessages.swiftmodule
>  -single_module -compatibility_version 1 -current_version 1 -Xlinker 
> -dependency_info -Xlinker 
> /Users/daryle/Library/Developer/Xcode/DerivedData/XNW-erfebwrlefqdajcsjohyazbstkyo/Build/Intermediates/CodeCoverage/Intermediates/XNW.build/Debug/InternetMessages.build/Objects-normal

Optionality in a NSManagedObject sub-class

2017-02-10 Thread Daryle Walker
It’s simple:

- I’m writing this framework for an app, both macOS, with Swift 3 and Xcode 8.
- My protocol has two non-optional strings.
- I unchecked “Optional” for those attributes when editing the model file.
- I used “Manual/None” for generation, then used the menu command to create the 
declaration and properties-extension files anyway.
- The class uses “String?”, i.e. optionals, for my attributes.
- This keeps the managed-object sub-class from matching the protocol when I add 
it from another extension (in a new file).

The properties are mandatory. So is it OK to change the generated versions to 
non-optionals? What’s the risk/trade-offs if I do so?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Merging scrolling/clipping with NSStackView

2017-01-21 Thread Daryle Walker

> On Jan 19, 2017, at 1:25 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Jan 19, 2017, at 06:39 , Daryle Walker <dary...@mac.com 
> <mailto:dary...@mac.com>> wrote:
>> 
>> The inner views should be as tall as they need to be.
> 
> I don’t understand this part. How tall is that?
> 
> I assume you mean that you want the text and table views to be tall enough to 
> show all of their contents, then stacked together and wrapped in a single 
> scroller. Conceptually that makes sense, but:
> 
> 1. The stack view is going to size itself, in the absence of explicit 
> constraints, based on the *intrinsic* sizes of the stacked views, and neither 
> text nor table view is going to report its full height as its intrinsic 
> height. Re-working them to provide that information is going to be very, very 
> painful.
> 
> 2. Neither text nor table view is *intended* to be full height. Instead, they 
> are intended to show a “window” of a fixed height onto a much taller virtual 
> height. That’s why they come pre-wrapped in individual scroll views. A table 
> view in particular is intended to prepare only the (relatively few) cells 
> that are actually visible at any one time. By forcing it to its “full” 
> height, you’re forcing it to keep every row in existence permanently. The 
> performance might be acceptable if the table is not very large, but it’s 
> still something of an abuse. Ditto the text view, although less so.
> 
> In such a situation, I think I would do one of the following:
> 
> — Rethink my UI so that I don’t have to stack the text and table views in 
> this way.

I think I’ll just do a NSSplitView and be done with it (for now).

> — Use only a table view, and place the text view as the first row of the 
> table. (With view-based table views, it’s easy to have more than one 
> prototype cell view.) It would still be a bit messy, since it would be a 
> variable-row-height table, but it’s likely less work than trying to achieve 
> the same effect using stack view constraints.

I just perused the Table View Programming Guide, and it wasn’t obvious what I 
would override. And I would want the text view as the last row. I’m guessing it 
would involve a complicated table delegate, and wouldn’t be able to use 
bindings (as much).

> — Use a (new-style) NSCollectionView, using two sections and custom flow 
> layouts for the sections.

Sounds interesting, but still has the same problem of table and text views 
weren’t designed to be fully expanded. Also, this surprise view layout would 
take away time from the interesting Core Data stuff I want to try. (I haven’t 
done basic load/save yet.) If I get to the point of publishing, you could add a 
pull request….

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: On NSIncrementalStore UUID Uniqueness

2017-01-19 Thread Daryle Walker

> On Jan 16, 2017, at 12:08 PM, Charles Srstka <cocoa...@charlessoft.com> wrote:
> 
>> On Jan 14, 2017, at 4:41 AM, Daryle Walker <dary...@mac.com 
>> <mailto:dary...@mac.com>> wrote:
>> 
>> Could I base the UUID off a hash of the URL? Maybe, but it wouldn’t survive 
>> file moves. There are file references in macOS, which would be more stable, 
>> but I read that there’s a bug in the URL class where it would degrade 
>> file-reference URLs to standard-file URLs, so that’ll be problematic. 
>> Another solution would to create bookmark data from a file URL and take a 
>> hash of that. But are multiple bookmark data blocks of the same file URL 
>> consistent enough for this idea to work?
> 
> The thing with file reference URLs degrading to file path URLs is in the 
> Swift is actually not a bug, it’s deliberate 
> (https://bugs.swift.org/browse/SR-2728 
> <https://bugs.swift.org/browse/SR-2728>). The Swift team decided that file 
> reference URLs are not appropriate for the Swift URL value type. However, if 
> you’re using Objective-C, file reference URLs will still work fine, and you 
> can always make an Objective-C wrapper that stores a file reference URL and 
> use that from Swift.

I looked at some code that gives a workaround for the file-reference URL 
problem. It grabs the reference ID as a 128-bit value, dumps it into 2 64-bit 
values, then sprinkles those onto a URL string template. Since UUIDs are 
128-bit values, I could just copy a reference ID directly into a UUID. However 
it means existing files would have a different style, possibly overlapping, 
than new files (which would take a random UUID). Maybe it’ll be better to 
always use a random UUID, the implementers do in practice.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: On NSIncrementalStore UUID Uniqueness

2017-01-19 Thread Daryle Walker

> On Jan 16, 2017, at 3:59 AM, Alastair Houghton <alast...@alastairs-place.net> 
> wrote:
> 
> On 14 Jan 2017, at 10:41, Daryle Walker <dary...@mac.com> wrote:
>> 
>> Could I base the UUID off a hash of the URL? Maybe, but it wouldn’t survive 
>> file moves. There are file references in macOS, which would be more stable, 
>> but I read that there’s a bug in the URL class where it would degrade 
>> file-reference URLs to standard-file URLs, so that’ll be problematic. 
>> Another solution would to create bookmark data from a file URL and take a 
>> hash of that. But are multiple bookmark data blocks of the same file URL 
>> consistent enough for this idea to work?
> 
> FYI, you can base a UUID off any identifier you please, so if you have *any* 
> stable identifier, you can use that.  The way you do so is:
> 
> 1. Generate a UUID for your namespace, if there isn’t a standard one.  
> (Standard ones exist for domain names, URLs, OIDs and X.500 DNs.  Otherwise 
> just generate a version 1 or 4 UUID, as appropriate.)
> 
> 2. Use that and your identifier to compute an SHA-1 hash.
> 
> 3. Use the SHA-1 hash to generate a version 5 UUID.

I looked at NSIncrementalStore subclasses on GitHub for inspiration. (Couldn’t 
find any NSAtomicStore ones.) While in theory we should take at least 
semi-heroic measures, in practice everyone goes “screw it” and calls the random 
UUID function (from NSProcessInfo). One guy even hard-coded a “1” as the UUID!

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Purge all remnants of an old incarnation of my app

2017-01-19 Thread Daryle Walker
I posted this on the Xcode list, but one of the respondents suggested adding it 
here too….

> On Jan 15, 2017, at 8:11 PM, Daryle Walker <dary...@mac.com> wrote:
> 
> I threw away an app I made in Xcode 7, including clearing its Git space and 
> replacing it with an empty branch. I created a new app with Xcode 8. However, 
> I used the same bundle ID for the two apps. When I first ran the new app, I 
> saw preference mismatch errors. I realized that, since I used the same ID for 
> both apps, the new app was looking at the old app’s data. I deleted the 
> preference file and the Xcode derived data folder. But even now, the new 
> app’s open-recent list has a file I opened in the old app.
> 
> I’m asking: where are all the locations used by both Xcode and the system 
> that automatically leave bundle-ID-marked files after compiling and running?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

Merging scrolling/clipping with NSStackView

2017-01-19 Thread Daryle Walker
Right now, my window has a table view sitting on top of a text view. Those 
templates from Interface Builder have those NSViews surrounded by a clip view 
surrounded by a scroll view. But I want to flip that around; put the table and 
text views together in a stack view, and surround that with clip and scroll 
views as necessary. 

The stack view should be as wide as the window. The table and text views should 
be as wide as their stack view. The inner views should be as tall as they need 
to be. (The text view should be one line high if there's no text.) I'm thinking 
of putting a horizontal line between the inner views

Any ideas how to do this?

Sent from my iPhone
___

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: On NSIncrementalStore UUID Uniqueness

2017-01-15 Thread Daryle Walker

> On Jan 14, 2017, at 2:32 PM, Jens Alfke <j...@mooseyard.com> wrote:
> 
> 
>> On Jan 14, 2017, at 2:41 AM, Daryle Walker <dary...@mac.com 
>> <mailto:dary...@mac.com>> wrote:
>> 
>>  I’m seemingly stuck since the data format doesn’t have a UUID field within 
>> it and I can’t base a UUID off of a hash of the file since it would change 
>> after each edit.
> 
> There’s really no way to store any custom metadata in the file? I assume it’s 
> some sort of database-like file (since it can be used to store CoreData 
> objects), so couldn’t you create an extra record and store a UUID in it?

No, my file format is straight-up dumb data.

I’ve read for years that Core Data can support custom storage formats. Looking 
into it, I see that there are caveats. My first thought experiment, e-mail 
messages, was stymied by each non-primitive data block needing to have a 
database-ish ID. My second thought experiment, mbox files, is now stymied that 
the file as a whole needs a database-ish ID too.  (Since mbox files can be 
multi-gigabyte, I’d make their loading read-only, letting me use each record’s 
byte offset as the base for an ID.)  These IDs need to be consistently 
derivable; randomly-generated IDs are no good.

If I continue this idea, I’ll stick in a constant UUID and hope Core Data 
doesn’t really need universally-unique IDs for all potential stores.

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: On NSIncrementalStore UUID Uniqueness

2017-01-14 Thread Daryle Walker

> On Jan 11, 2017, at 3:58 PM, Keary Suska <cocoa-...@esoteritech.com> wrote:
> 
> 
>> On Jan 11, 2017, at 11:16 AM, Jens Alfke <j...@mooseyard.com> wrote:
>> 
>> 
>>> On Jan 10, 2017, at 2:00 PM, Jean-Daniel <mail...@xenonium.com> wrote:
>>> 
>>> UUID means Universally unique identifier and it must be unique: 
>>> https://en.wikipedia.org/wiki/UUID 
>>> <https://en.wikipedia.org/wiki/UUID><https://en.wikipedia.org/wiki/UUID 
>>> <https://en.wikipedia.org/wiki/UUID>>
>>> To generate an UUID, use a standard system function (CFUUID, NSUUID, 
>>> libuuid, …)
>> 
>> This is not what I believe Daryle was asking, and it’s sent everyone off on 
>> a tangent about what UUIDs are.
>> 
>> My interpretation of the original question: Is an NSIncrementalStore’s UUID 
>> scoped to the specific database, or is it scoped to that _implementation_ of 
>> the store? That is, is the UUID generated at runtime or at compile time?
>> 
>> I don’t know the answer; just hoping to get the discussion back on track :)
> 
> The docs say:
>   "A unique identifier for the store at the given URL. It must be 
> uniquely and reproducibly derivable, such that multiple instances of your 
> store return the same UUID”
> 
> My reading is that the store UUID would be unique to a specific database 
> since it is only unique to the URL location of the store. I thin the docs use 
> “instance” in a strictly OOP sense.

Yes, this is what my question is about. Could I grab a UUID from a 
get-a-random-UUID site, hard code it as a type-level property in Swift, and use 
it for every instantiation (even for different files)? If this isn’t 
acceptable, I’m seemingly stuck since the data format doesn’t have a UUID field 
within it and I can’t base a UUID off of a hash of the file since it would 
change after each edit.

Could I base the UUID off a hash of the URL? Maybe, but it wouldn’t survive 
file moves. There are file references in macOS, which would be more stable, but 
I read that there’s a bug in the URL class where it would degrade 
file-reference URLs to standard-file URLs, so that’ll be problematic. Another 
solution would to create bookmark data from a file URL and take a hash of that. 
But are multiple bookmark data blocks of the same file URL consistent enough 
for this idea to work?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: Retaining non-document windows

2017-01-14 Thread Daryle Walker

> On Jan 4, 2017, at 7:16 PM, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Jan 4, 2017, at 14:11 , Jean-Daniel <mail...@xenonium.com> wrote:
>> 
>> When using storyboard, the only way to instantiate window is by getting a 
>> reference to the window controller (by using 
>> -instantiateControllerWithIdentifier:), so it should not be an issue.
> 
> The problem I was referring to is when the window [scene] is in the initial 
> controller. There’s no way (AFAIK) that you can statically set up a reference 
> to the WC in any combination of IB/code, and of course the storyboard 
> instantiation is not in your code.
> 
> Again AFAIK, you can get a reference to this WC from the window, and you can 
> get the [main] window from the NSApplication object, or from a view 
> controller’s view, but all of these things require you to defer getting the 
> reference until the objects are created and functional.
> 
> Or, you can subclass NSWindowController, and have the windowDidLoad override 
> add a controller reference to data structures somewhere.
> 
> But I think the old days when the template project provided a window 
> controller property on the app delegate for you are gone.
> 
> Of course, I’d be extremely happy to be wrong about this. (I assume the tea 
> leaves indicate that window controllers are on the way out, so don’t get too 
> used to them.)

Why would they go away, since they’re part of the document system (with 
NSDocument and NSDocumentController). The first thing I do with the default 
document-based project is to factor out the window (controller) code and 
storyboard out of the Document class and Main storyboard to separate files. 
Easier to handle early in case I add more code.

One big question I had was how to remove the window (controller) reference. I 
think there’s an NSNotification whenever a window closes; do I have to use that 
(or the equivalent window delegate method) to flag when to remove the pointer 
from my collection object (or set the single reference to NIL)?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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: What should we do if file-opening takes a long time?

2017-01-14 Thread Daryle Walker

> On Dec 31, 2016, at 9:03 PM, Charles Srstka <cocoa...@charlessoft.com> wrote:
> 
>> On Dec 31, 2016, at 7:35 PM, Graham Cox <graham@bigpond.com 
>> <mailto:graham@bigpond.com>> wrote:
>> 
>> NSProgress is thread safe and might be useful for this.
> 
> One thing to be careful about when using NSProgress with threads is not to 
> bind directly to it from your UI elements, since the updates will come in on 
> the same thread the changes were made on. Either register your observers 
> manually and call the main thread from 
> -observeValue:forKeyPath:ofObject:change:context:, or have your worker thread 
> call the main thread to update the NSProgress object.

[Just catching up on my e-mail now.]

Yeah, I just read that Cocoa Bindings is generally main-thread only, like the 
windows and views. I thought I could have a NSProgress subclass that takes a 
pointer to an existing progress object, KVO’s the heck out of all the remote 
object's attributes, then updates its own to match, but only posts from the 
main queue. The initializer would take the remote progress object, but it would 
also need the queue that the remote does its work on, so the local progress 
object can pass its cancel/pause/resume up to the remote object, right?

Would I have to KVO every attribute? Or is there a core list so I can use 
Progress’s included code to handle the rest? I’m also thinking of adding a 
Boolean flag to indicate completion. (You can’t use fraction-complete attribute 
since it’s floating-point.)

The “Progress” page has an “isOld” attribute that isn’t documented, also with 
some undocumented publish & subscribe API. Are those a mistake? Or an obsolete 
API (and we should use the documented members)?

— 
Daryle Walker
Mac, Internet, and Video Game Junkie
darylew AT mac DOT 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

What do NSArrayController, etc. do for me?

2017-01-13 Thread Daryle Walker
If my data model supports KVC/KVO, it seems like I should be able to bind my 
views to my data directly via Cocoa Bindings, without using NSArrayController 
or NSObjectController or the like. What advantage do those classes give me?

Sent from my iPhone
___

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


Opposite of windowDidLoad

2017-01-12 Thread Daryle Walker
I was thinking of adding a Cocoa Binding during my window-controller's did-load 
method. But where would the unbinding go? I see waiting until deinit or 
implementing NSWindowDelegate and using windowWillClose.

Is there a similar access point for view-controllers?

Sent from my iPhone
___

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


Refreshing Cocoa Bindings

2017-01-11 Thread Daryle Walker
I'm going to store a reference to a model in a NSViewController's 
representedObject field. The various contained views will reference that field 
through KVO (Is that possible?) for their bound values. If I change the value 
of the represented object (what it points to, not any attributes within), will 
the views automatically track to the new object? Or do I have to use a explicit 
method to let them know (i.e. clear their caches)?

Sent from my iPhone
___

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


On NSPersistentStore Modeling

2017-01-10 Thread Daryle Walker
I read about store coordinators and managed contexts using Core Data models 
(I.e. "momd" files). But persistent store subclasses use them too right? From 
looking at the docs for the atomic and incremental stores, their internal 
scheme have to match a specific model too; they can't support generic schemes 
for arbitrary models, right?

Sent from my iPhone
___

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


On NSIncrementalStore UUID Uniqueness

2017-01-10 Thread Daryle Walker
Been reading up on NSIncrementalStore, including its guide. I think I grok it 
more now. When initializing an instance, you're supposed to submit an UUID. Can 
a single value be used for all instances, or is it supposed to unique per 
instance?  If the latter, and the source data doesn't already have a UUID 
field, do you to take heroic measures to ensure uniqueness? Or is a casual 
effort enough?

Sent from my iPhone
___

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


  1   2   3   >