Re: /Library/Application Support off limits? (Davidap)

2021-04-21 Thread Jonathan Prescott via Cocoa-dev
Adobe, Google, etc., use the Apple security frame works and interfaces to 
temporarily elevate privileges to write their respective data to 
/Library/Application Support, which is actually where this data should go, 
based on Apple guidance.  There is extensive documentation on this whole issue 
in the Apple documentation.

Jonathan
___

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: sharing code between screensaver and regular app

2020-03-02 Thread Jonathan Prescott via Cocoa-dev
When you created the application, you should have created two pairs of files, 
AppDelegate.h/.m and ViewController.h/.m.  The AppDelegate is used to augment 
and tailor the behavior of the NSApplication that is implicitly created as part 
of the AppKit framework.  For your purposes, you may not need to implement this 
code (however, you should look at the AppDelegate documentation to make sure).  
The ViewController is derived from NSViewController, and is the container for 
your screen saver view (which is probably derived from ScreenSaverView, which 
is derived from NSView).  An instance of this view is a property of your 
ViewController.

If you look back at the link you referred to, you’ll see that is creating a 
ViewController that will be a container for you screen saver view.  Although 
it’s in Swift, it should be straightforward to translate back into Objective-C

Jonathan
___

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 is the preferred way to set NSTextView content from NSAttributedString?

2020-02-02 Thread Jonathan Prescott via Cocoa-dev
Looking at the documentation for NSTextView, it is highly recommended that you 
manipulate the NSTextStorage associated with the view.  NSTextStorage is a 
sub-class of NSMutableAttributedtString, so you have all of those capabilities 
as well.

I’m just getting into this as well for my console application related to my 
expert system interface.

Jonathan

> On Feb 2, 2020, at 3:37 PM, Jeff Younker  wrote:
> 
> Yes, I've set needsDisplay = true in my attempts to so far. Also needsLayout 
> = true.
> 
> The question I've got though is what is the recommended way of setting the 
> value to T2. There is no attributedString variable, just an accessor method, 
> so I've been trying a variety of insert methods.
> 
> -jeff
> 
> On Sun, Feb 2, 2020 at 12:19 PM Jonathan Prescott  <mailto:jprescot...@icloud.com>> wrote:
> Did you tell V that it needs to re-load it’s display?  There is a method on 
> NSView (from which NSTextView is derived) called “needsDisplay(sic)” which 
> sets a flag on the view so that the view will re-draw its content the next 
> display cycle.  So, after you set the content to T2, you need to call 
> “V.needsDisplay()” so that the next display cycle the view gets refreshed.  
> Need to check the spelling of the method.
> 
> Jonathan

___

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 is the preferred way to set NSTextView content from NSAttributedString?

2020-02-02 Thread Jonathan Prescott via Cocoa-dev
Did you tell V that it needs to re-load it’s display?  There is a method on 
NSView (from which NSTextView is derived) called “needsDisplay(sic)” which sets 
a flag on the view so that the view will re-draw its content the next display 
cycle.  So, after you set the content to T2, you need to call 
“V.needsDisplay()” so that the next display cycle the view gets refreshed.  
Need to check the spelling of the method.

Jonathan
___

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: UiView as slider with inertia

2018-10-01 Thread Jonathan Hull
What you want is UICollectionView.  Make the numbers your cells, and use 
-targetContentOffset(forProposedContentOffset:, withScrollingVelocity:) to 
provide the snapping behavior.

> On Sep 30, 2018, at 8:46 PM, Eric Dolecki  wrote:
> 
> I've been tasked with coming up with a few horizontal sliders that are really 
> sequential numbers with the selected value in the middle of the screen. They 
> want drag and release with inertia and also rubber banding on the ends. 
> Values snap into place. 0 1 2 3 4 5 ...
> 
> Does anyone have something like this to save me some time? I'm assuming 
> uipangesturerecognizer and some uikit dynamics.
> 
> Thanks!!
> Eric
> 
> Sent from my iPhone X.
> ___
> 
> 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/jhull%40gbis.com
> 
> This email sent to jh...@gbis.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


Lazy calculation of tooltip text

2018-07-06 Thread Jonathan Taylor
I have a UI item (text field) that displays a tooltip when the user hovers over 
it. However, the information to be displayed in the tooltip is dynamic and 
relatively expensive to compute. At the moment the tooltip is bound to a string 
property which I manually update twice a second. It seems that the right way to 
handle all this would be to compute the information only when I know the 
tooltip is about to display. However, googling and searching of headers has not 
led me to a way to do this. It seems that NSTextView has a method 
textView:willDisplayToolTip:forCharacterAtIndex: which would seem to offer the 
functionality I want. However, I can’t find anything equivalent for other view 
types.

Any suggestions on how I might supply tooltip text dynamically, when the 
tooltip is about to display?

[University of Glasgow: The Times Scottish University of the Year 2018]
___

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: Creating NSTableView programmatically

2017-12-12 Thread Jonathan Mitchell

> On 12 Dec 2017, at 19:56, Richard Charles  wrote:
> 
> I always assumed the reason bindings never came over to iOS was they consumed 
> too much cpu power and were too difficult to understand. It seems evident 
> that 10 or 20 years from now Apple anticipates the bulk of it programmers 
> coming out of school will use iPads with the new style documentation. Cocoa 
> bindings do not fit very well into this picture.
I am not sure if stringent power concerns were the overriding factor for 
excluding bindings from iOS. 
Bindings are driven by observations, which do exist on iOS. 
I think that some developers use reactive frameworks such as ReactiveCocoa to 
achieve UI binding on IOS - but I am not sure that would count as a 
simplification.

Cocoa bindings are okay though they lack flexibility and features when compared 
to the likes of WPF bindings.
WPF bindings are just about as tricky to get right - though the use of a GC 
makes life generally easier in a managed world.

Bindings are actually a fairly essential technology for medium to large scale 
data driven macOS applications.
Trying to manually glue hundreds of controls and data paths together quickly 
becomes a major development obstacle.

J

___

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: Creating NSTableView programmatically

2017-12-11 Thread Jonathan Mitchell
For NSTableCellView see
https://developer.apple.com/documentation/appkit/nstablecellview

objectValue is a property on NSTableCellView not on NStableView.

The NSTableViewDelegate method 
- (NSView *)tableView:(NSTableView *)tableView 
viewForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row
provides the required NSTableView instances on demand.

You also need to bind the NSTableView's content object to the 
NSArrayController’s arrangedObjects.

The nib makes all this easier  though its still fiddly.
I would get it working in a nib first and then work backwards from there.


> On 11 Dec 2017, at 10:59, Eric Matecki  wrote:
> 
> 
> Hello,
> 
> I'm trying to implement in Objective-C on macOS *programmatically* the "Real 
> World Example" at the bottom of this page :
> https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CocoaBindings/Concepts/WhatAreBindings.html
> 
> I want to do it programmatically instead of using IB to really understand 
> what happens.
> 
> Just creating the "Attacker" NSTableView causes me already a lot of trouble.
> My code is at the bottom of this message.
> 
> I can't just bind "value" of the attacker tableview to the array controller's 
> "arrangedObjects.name",
> I get a "this class is not key value coding-compliant for the key value" 
> exception.
> 
> So I create a column (I think this is mandatory anyway...).
> In my delegates tableView:viewForTableColumn:row: I create a text field 
> (NSTextView).
> (I create a textfield for now, will probably be a NSButton in the final 
> version).
> 
> I now see a table with four rows (the number of entries in my array), each 
> with a text field I can edit.
> But they start empty and don't change my array of combattants.
> 
> How do I bind this text field to the right "thing" ?
> 
> According to the last paragraph of this page:
> https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/TableView/PopulatingViewTablesWithBindings/PopulatingView-TablesWithBindings.html
> I have to :
> """
> When you make the connection to the table view’s Content binding, the 
> objectValue property of the NSTableViewCell used as the cell for the table 
> column is configured such that for each item in the model array, the table 
> updates the objectValue property to the current row’s Person object.
> """
> But NSTableViewCell doesn't seem to exists (a search on Apple's dev doc gives 
> 27 results... all about *UI*TableViewCell)
> 
> So I need to bind "value" from the text field to "objectValue.name" from... 
> something...
> Whatever I try I get either an exception for not KV compliance, or it doesn't 
> seem to do anything.
> 
> Please shed some light on this...
> Thanks.
> 
> CODE:
> 
> #include "Cocoa/Cocoa.h"
> 
> //===
>  cCombattant
> 
> @interface  cCombattant : NSObject
> 
> @property (copy) NSString*  weapon1;
> @property (copy) NSString*  weapon2;
> @property (copy) NSString*  weapon3;
> @property (copy,readwrite) NSString*  name;
> @propertyNSString**  selectedWeapon;
> 
> - (cCombattant*)initWithName: (NSString*)  iName;
> 
> //DEBUG
> - (void)addObserver: (NSObject *)observer
> forKeyPath: (NSString *)keyPath
>options: (NSKeyValueObservingOptions)options
>context: (void *)context;
> 
> //DEBUG
> - (void)removeObserver: (NSObject *)observer
>forKeyPath: (NSString *)keyPath;
> @end
> 
> 
> @implementation  cCombattant
> 
> - (cCombattant*)initWithName: (NSString*)  iName
> {
>self = [super  init];
> 
>[self  setWeapon1: @"Dagger"];
>[self  setWeapon2: @"Sword"];
>[self  setWeapon3: @"Pike"];
>[self  setSelectedWeapon: &_weapon1];
>[self  setName: iName];
> 
>return  self;
> }
> 
> //DEBUG
> - (void)addObserver: (NSObject *)observer
> forKeyPath: (NSString *)keyPath
>options: (NSKeyValueObservingOptions)options
>context: (void *)context
> {
>printf( "[%p addObserver: %p forKeyPath: %s options: XXX context: %p]\n", 
> self, observer, [keyPath UTF8String], /*options,*/ context );
>int bkpt=bkpt;
>[super  addObserver: observer  forKeyPath: keyPath  options: options  
> context: context];
> }
> 
> //DEBUG
> - (void)removeObserver: (NSObject *)observer
>forKeyPath: (NSString *)keyPath
> {
>printf( "[%p removeObserver: %p forKeyPath: %s]\n", self, observer, 
> [keyPath UTF8String] );
>int bkpt=bkpt;
>[super  removeObserver: observer  forKeyPath: keyPath];
> }
> 
> @end
> 
> //===
>  cDelegate
> 
> @interface  cDelegate : NSObject < NSTableViewDelegate >
> 
> - (cDelegate*)init;
> 
> @end
> 
> 
> @implementation  cDelegate
> 
> 
> - (cDelegate*)init
> {
>self = [super  init];
>return  self;
> }
> 
> - (NSView 

Re: NSDocument -canCloseDocumentWithDelegate::: not called when terminating

2017-08-30 Thread Jonathan Mitchell

> On 30 Aug 2017, at 18:30, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Aug 30, 2017, at 06:18 , Jonathan Mitchell <li...@mugginsoft.com 
> <mailto:li...@mugginsoft.com>> wrote:
>> 
>> My documents have a lot of variable user cancellable activity that must run 
>> prior to document closure regardless of whether the document is dirty or not.
> 
>> My solution is to run a termination preflight that processes my clean 
>> documents prior to allowing actual termination,
> 
> 
> Instead, the “applicationWillTerminate:” override of your app delegate seems 
> like the right place, especially because it explicitly permits you to delay 
> terminate while you do stuff, without having to run the run loop manually.  
> That’s the *point* of the “applicationWillTerminate:” mechanism.

Thanks for the thoughts.

Using the applicationWillTerminate is probably a less hacky approach like you 
say but it would mean refactoring to accommodate this one troublesome situation 
- I would likely still need to retain the code that handles normal document 
closing as well.

I am not sure that the NSApp -terminate: override is such an issue as the 
problem only occurs when -terminate: is called. If another termination method 
appears on the scene it will likely have its own foibles.

The doc close logic is quite tricky with copies of the NSDocument instance 
being sent to both local and remote URLs. Getting it all to hang together at 
termination in a way that integrates with the NSDocument architecture is 
challenging.
As you say running the loop manually mimics what applicationWillTerminate tries 
to achieve in the first place.

I will keep an eye on how the preflight code works out in the knowledge that I 
can fall back to an “applicationWillTerminate” style approach.
___

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


NSDocument -canCloseDocumentWithDelegate::: not called when terminating

2017-08-30 Thread Jonathan Mitchell
This is one from the archives:

https://lists.apple.com/archives/cocoa-dev/2012/Jul/msg00740.html

In short NSDocument -canCloseDocumentWithDelegate::: gets called on documents 
when closing the document window but only for dirty documents when closing the 
app via NSApp -terminate: (i.e.: the application Quit menu item).
My documents have a lot of variable user cancellable activity that must run 
prior to document closure regardless of whether the document is dirty or not.
Trying to fudge the document dirty flag as and when required just sounds like a 
maintenance headache.

My solution is to run a termination preflight that processes my clean documents 
prior to allowing actual termination,
My experience is that intervening in the NSDocument machinery at critical 
points can be a recipe for disaster if things are not quite right.

If anyone has attempted this in the past comments would be appreciated.

NSApplication subclass
==

- (void)terminate:(id)sender
{
   // The logic here is quite complex
   // 
https://developer.apple.com/documentation/appkit/nsapplication/1428417-terminate?language=objc
   // The receiver calls NSDocumentController to check if documents can be 
closed.
   // If those methods don't handle their callbacks accurately then then this 
method never returns (even in termination does not occur)
   // and I think we end up in an inner run loop.
   //
   // If the termination process succeeds then this method does not return.
   // If the termination process is cancelled then this method does return;

   self.isTerminating = YES;

   // preflight
   // see https://lists.apple.com/archives/cocoa-dev/2012/Jul/msg00740.html
   // when we call terminate: non edited document instances do not get 
processed like diirty docs hence the preflight
   BOOL preflight = [[BPDocumentController sharedDocumentController] 
preflightCloseAllDocumentsOnApplicationTerminate];
   if (preflight) {
   [super terminate:sender];
   }

   self.isTerminating = NO;
}


NSDocumentController subclass
=

- (BOOL)preflightCloseAllDocumentsOnApplicationTerminate
{
   // see https://lists.apple.com/archives/cocoa-dev/2012/Jul/msg00740.html
   // when we call NSApp -terminate: non edited document instances do not get 
processed like dirty docs hence this preflight
   BOOL success = YES;

   // this method is only available if within NSApp -terminate:
   BOOL appTerminating = [(BPApplication *)NSApp isTerminating];
   if (!appTerminating) {
   return NO;
   }

   // we need to preflight non edited documents
   NSArray *cleanDocuments = [self.documents linq_where:^BOOL(BPDocument * doc) 
{
   return !doc.isDocumentEdited;
   }];

   for (NSDocument *doc in cleanDocuments) {
   self.cleanDocumentTerminateInfo = nil;

   // this method is called by default on dirty docs but in order to retain 
our sanity and ensure that the doc close logic
   // is called in all situations we call it here too
   [doc canCloseDocumentWithDelegate:self 
shouldCloseSelector:@selector(onTerminateCleanDocument:shouldClose:contextInfo:)
 contextInfo:NULL];

   // process events until our close selector gets called
   while (!self.cleanDocumentTerminateInfo) {
   NSEvent *event = [NSApp nextEventMatchingMask:NSEventMaskAny 
untilDate:[NSDate distantFuture] inMode:NSDefaultRunLoopMode dequeue:YES];
   [NSApp sendEvent:event];
   }

   success = [self.cleanDocumentTerminateInfo[@"shouldClose"] boolValue];
   if (!success) {
   break;
   }
   }

   self.cleanDocumentTerminateInfo = nil;

   return success;
}

- (void)onTerminateCleanDocument:(NSDocument *)doc 
shouldClose:(BOOL)shouldClose contextInfo:(void  *)contextInfo
{
   self.cleanDocumentTerminateInfo = @{@"document" : doc, @"shouldClose" : 
@(shouldClose)};
}

___

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: NSMutableParagraphStyle -paragraphSpacingBefore

2017-08-22 Thread Jonathan Mitchell

> On 22 Aug 2017, at 18:17, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Aug 22, 2017, at 10:02 , Jonathan Mitchell <li...@mugginsoft.com> wrote:
>> 
>> I don’t seem to be having much luck getting NSMutableParagraphStyle 
>> -paragraphSpacingBefore to render.
> 
> To render where? I have never found a way of getting it to be honored at the 
> *top* of a text container, only after a non-empty, non-trivial paragraph of 
> text.
Yes. That might well be the behaviour.

In this case I was trying to adjust the before spacing of the second paragraph.
I hadn’t defined an explicit paragraph style for the first paragraph (which I 
presumed would use the default para style).
Once I set the 1st para to explicitly use [NSParagraphStyle 
defaultParagraphStyle] it rendered ok.

Thanks

J
___

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


NSMutableParagraphStyle -paragraphSpacingBefore

2017-08-22 Thread Jonathan Mitchell
macOS 10.12
I don’t seem to be having much luck getting NSMutableParagraphStyle 
-paragraphSpacingBefore to render.
 NSMutableParagraphStyle -paragraphSpacing seems fine.

Any thoughts?

I know I can work around it if needs be.

J
___

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: UIDocumentBrowserViewController and file package documents

2017-06-21 Thread Jonathan Hull
That part is really confusing me as well (I am also using a package document).  
I started by using the documents directory, but I keep getting an error that 
the browser doesn’t have access.  Then I switched to the temp directory, and 
now it works part of the time, and the other times I still get the same error.

Where are we supposed to create our package?  Does the browser copy it to a 
specific place? or do we need to copy it?

Here is the error:
[ERROR] Could not get attribute values for item file:. Error: 
Error Domain=NSFileProviderInternalErrorDomain Code=1 "The reader is not 
permitted to access the URL."

Thanks,
Jon


> On Jun 21, 2017, at 5:41 AM, davel...@mac.com wrote:
> 
>> 
>> On Jun 20, 2017, at 5:29 PM, Kyle Sluder  wrote:
>> 
>> On Tue, Jun 20, 2017, at 03:40 PM, davel...@mac.com wrote:
>>> I'm trying out the new UIDocumentBrowserViewController in iOS 11 (using
>>> the iPad simulator). I can get it to create a new document (which is a
>>> file package) for my app, but tapping on the document in the
>>> UIDocumentBrowserViewController does not cause the delegate method
>>> documentBrowser(_ controller: UIDocumentBrowserViewController,
>>> didPickDocumentURLs documentURLs: [URL]) to get called.
>>> 
>>> It does get called for another document type that is a flat file (not a
>>> file package), but it doesn't work with the file package document created
>>> by NSFileWrapper.
>>> 
>>> Am I doing something wrong or is this a bug with file packages?
>> 
>> Please file a bug report and send me the number so I can ensure the
>> correct team sees it.
>> 
>> Thanks,
>> --Kyle
>> 
>>> 
>>> Thanks,
>>> Dave
> 
> I have one more idea to try and then if that doesn't work, I'll try to make a 
> small sample project today and submit the bug report (and I'll email you the 
> #).
> 
> The one thing I'm not certain about is the WWDC video shows making an empty 
> file and adding it to the project as a resource and then copying it when the 
> new document button is pressed. Do I just need to make an empty directory for 
> that? My idea was to create an empty document with my app (in the simulator) 
> and then copy that empty document directory to the Xcode project. Are there 
> any special flags/attributes that need to be set on that directory to make it 
> a correct package?
> 
> Thanks,
> Dave Reed
> 
> 
> 
> ___
> 
> 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/jhull%40gbis.com
> 
> This email sent to jh...@gbis.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: Release mode bindings crash and release pools

2017-06-17 Thread Jonathan Mitchell

> On 17 Jun 2017, at 16:36, Charles Srstka <cocoa...@charlessoft.com> wrote:
> 
>> On Jun 17, 2017, at 8:36 AM, Jonathan Mitchell <li...@mugginsoft.com 
>> <mailto:li...@mugginsoft.com>> wrote:
> 
> 
> Just tested it on 10.9; it works :-)
> 
> import Foundation
> 
> class C: NSObject {
> @objc dynamic var foo = "Foo"
> }
> 
> let c = C()
> 
> let observer = c.observe(\.foo) { obj, _ in
> print("Foo changed: now it's \(obj.foo)")
> }
> 
> c.foo = "Bar"
> 
> Running it on my Mavs VirtualBox VM, this outputs:
> 
> $ ./kvotest
> Foo changed: now it's Bar
> 
> Charles

Thanks for taking the time to test that.
I haven’t had time this week to take look at the new 10.13 APIs.

Will the above translate to Obj-C?

J
___

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: Release mode bindings crash and release pools

2017-06-17 Thread Jonathan Mitchell

> On 17 Jun 2017, at 14:21, Charles Srstka <cocoa...@charlessoft.com> wrote:
> 
>> On Jun 17, 2017, at 5:32 AM, Jonathan Mitchell <li...@mugginsoft.com 
>> <mailto:li...@mugginsoft.com>> wrote:
>> 
>>> On 16 Jun 2017, at 23:18, Quincey Morris 
>>> <quinceymor...@rivergatesoftware.com 
>>> <mailto:quinceymor...@rivergatesoftware.com>> wrote:
>>> 
>>> On Jun 16, 2017, at 14:41 , Jonathan Mitchell <li...@mugginsoft.com 
>>> <mailto:li...@mugginsoft.com>> wrote:
>>>> 
>>>> I sometimes use the default NSObject bind: to set up a simple one way 
>>>> operation as you describe as opposed to a discrete observation.
>>> 
>>> With macOS 10.13, the new block/closure-based KVO “addObserver” method is 
>>> probably an easier way, although you do have to remove it manually.
>>> 
>> The block/closure improvements are long overdue IMHO.
>> 
>> I use a home brewed approach using BPBlockValueTransformer : 
>> NSValueTransformer with bindings that gives a lot more flexibility.
>> A trivial example involving a closure would be:
>> 
>>BPBlockValueTransformer *blockValueTransformer = [BPBlockValueTransformer 
>> valueTransformerWithBlock:^id(NSNumber *value) {
>>   strongify(self);
>>   return ([value boolValue] || self.isFree)? @“Freedom for all" : 
>> @“Freedom for no-one";
>>}];
>>[self.titleTextField bind:NSValueBinding toObject:self.repObjCon 
>> withKeyPath:@"selection.isHidden" options:@{NSValueTransformerBindingOption 
>> : blockValueTransformer}];
>> 
>> The downside is that you cannot establish the binding in the NIB.
> 
> It’s definitely overdue; I’ve been using a blocks-based wrapper around KVO 
> for years. 
Is that a publicly available wrapper?

> 
> A couple of notes, though, re-reading the message this replied to. The new 
> blocks-based API, ‘observe()’, is actually part of the Swift overlay, which 
> means it works on older macOS versions, not just 10.13. Also, you don’t have 
> to remove it manually, and that’s in fact one of its major features—it 
> automatically deregisters itself whenever the observer falls out of scope. So 
> as long as you make sure you don’t set up a retain cycle with captured 
> values, you can just stash the observer in an ivar, and when your object gets 
> deallocated, your observer will be unregistered. Much easier than what we had 
> to do before.
It would be good if I could get this to work all the way back to 10.9 (that’s 
my deployment target).

Accurately managing observation and object lifetimes is such a big time sink 
that any improvement is always welcome.

J
___

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: Release mode bindings crash and release pools

2017-06-17 Thread Jonathan Mitchell

> On 17 Jun 2017, at 01:54, Charles Srstka  wrote:
> 
>>  it’s preferred that bindings go either through an NSObjectController, an 
>> NSViewController, or something else that implements NSEditorRegistration.

I think that is a crucial aspect in all this.
I while back I configured bindings in contravention of the above and found 
myself literally re-inventing NSEditorRegistration (just to get everything to 
hang together) until the penny dropped.

In my case I route my object bindings through an NSObjectController hosted in 
my NSViewController subclass - I find the that the extra level of indirection 
gives flexibility.

The NSAutoUnbinder support is also crucial.
The public classes that implement it are:

NSViewController.
NSTableCellView
NSWindowController

J
___

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: Release mode bindings crash and release pools

2017-06-17 Thread Jonathan Mitchell

> On 16 Jun 2017, at 23:18, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Jun 16, 2017, at 14:41 , Jonathan Mitchell <li...@mugginsoft.com> wrote:
>> 
>> I sometimes use the default NSObject bind: to set up a simple one way 
>> operation as you describe as opposed to a discrete observation.
> 
> With macOS 10.13, the new block/closure-based KVO “addObserver” method is 
> probably an easier way, although you do have to remove it manually.
> 
The block/closure improvements are long overdue IMHO.

I use a home brewed approach using BPBlockValueTransformer : NSValueTransformer 
with bindings that gives a lot more flexibility.
A trivial example involving a closure would be:

BPBlockValueTransformer *blockValueTransformer = [BPBlockValueTransformer 
valueTransformerWithBlock:^id(NSNumber *value) {
   strongify(self);
   return ([value boolValue] || self.isFree)? @“Freedom for all" : 
@“Freedom for no-one";
}];
[self.titleTextField bind:NSValueBinding toObject:self.repObjCon 
withKeyPath:@"selection.isHidden" options:@{NSValueTransformerBindingOption : 
blockValueTransformer}];

The downside is that you cannot establish the binding in the NIB.
___

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: Release mode bindings crash and release pools

2017-06-16 Thread Jonathan Mitchell

> On 16 Jun 2017, at 22:32, Quincey Morris 
>  wrote:
> 
> On Jun 16, 2017, at 13:48 , Charles Srstka  wrote:
>> 
>> This is incorrect.
> 
> It’s incorrect as a 2-way binding, but it works as a pair of so-called 1-way 
> bindings, with the proviso that they may need to be unbound manually, to 
> prevent reference cycles, which it sounds like is what Jerry is doing.
> 
> The thing that I always said that no one believed is that there’s really no 
> such thing as 1-way binding, and NSObject’s default implementation of the 
> “bind:…” method does *not* establish a binding. It’s *part* of the 
> implementation of a proper 2-way binding (as explained in the documentation 
> you referenced), and for a given receiver class the method only establishes a 
> 2-way binding if it’s an override that provides the rest of the functionality.
> 
I sometimes use the default NSObject bind: to set up a simple one way operation 
as you describe as opposed to a discrete observation.
It works fine.

I haven’t quite figured out yet how NSAutoUnbinder breaks the view <-> 
controller retain cycle when the binding object is the controller.


___

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: Property in class mirrored to user defaults

2017-06-16 Thread Jonathan Taylor
Thankyou Charles and Keary for your replies. I somehow hadn't thought of using 
NSDefaults as backing for the properties. There are a lot of properties 
involved, but with a macro or something I should be able to set it up without a 
massive code bloat. Will give that a go.
Cheers
Jonny

On 12 Jun 2017, at 16:01, Charles Srstka <cocoa...@charlessoft.com> wrote:

>> On Jun 12, 2017, at 4:04 AM, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
>> wrote:
>> 
>> Hi all,
>> 
>> This feels like a very basic question, but one that I have not had any luck 
>> searching for (maybe I am using the wrong terms?).
>> 
>> At the moment I have properties in a (singleton) class that are bound to UI 
>> elements. At the moment they have the same automatic values every time the 
>> app is launched, although the user can change them while it is running. What 
>> I would like is for the user's previous choice to be remembered when the app 
>> is next launched. Obviously this would seem to be a job for NSUserDefaults. 
>> I am not sure quite what the right way to structure things is, though.
>> 
>> All the simple examples I have seen bind to NSUserDefaults and then if the 
>> program actually wants to know what the value is, it simply accesses the 
>> values directly on NSUserDefaults. I would prefer not to do that, though 
>> (see below).
>> 
>> What I ~think~ I would like is to still be able to access the values as 
>> properties of my class. That seems to me like the natural way, and it would 
>> seem odd to have two categories of value, some accessed through properties 
>> on the class, and some accessed some other way via NSUserDefaults. However, 
>> if I bind the UI elements to the shared user defaults object, is that not 
>> what will happen? Or is there some way that I can "link" my class and the 
>> user defaults object, so that the properties are saved in user defaults but 
>> I can still access them in a fairly seamless way from my class? I do like 
>> the idea of having the properties (and their types) explicitly declared as 
>> part of my class, rather than being mysterious objects that only exist in 
>> the user defaults.
>> 
>> Does anyone have any advice on how I can achieve this, or on how I should be 
>> thinking about all this differently?
>> Thanks
>> Jonny
> 
> If performance isn’t an issue, as it usually isn’t for properties linked to 
> UI elements, and you don’t want to bind the UI elements directly to an 
> NSUserDefaultsController, you can just use UserDefaults as the backing for a 
> property, like this:
> 
> class MyClass: NSObject { 
>   // this is a property only so we can make key paths that will go 
> through it
>   @objc private let userDefaults: UserDefaults
>   private static let fooDefaultsKey = "Foo"
>   
>   @objc private static let keyPathsForValuesAffectingFoo: Set = 
> ["\(#keyPath(userDefaults)).\(MyClass.fooDefaultsKey)"]
>   @objc dynamic var foo: String {
>   get { return UserDefaults.standard.string(forKey: 
> MyClass.fooDefaultsKey) ?? "" }
>   set { UserDefaults.standard.set(newValue, forKey: 
> MyClass.fooDefaultsKey) }
>   }
>   
>   override init() {
>   self.userDefaults = UserDefaults.standard
>   
>   super.init()
>   }
> }
> 
> This is pretty cool; on recent releases of macOS, it’ll respond to changes in 
> the defaults even if they come from outside the process. So, if you observe 
> the “foo” property, and then manually use /usr/bin/defaults to change the 
> defaults, your notifications in the app will fire.
> 
> Alternately, you can just set up the property at init time and then update 
> the defaults whenever it changes, like this. You won’t get the cool 
> observation behavior, though, unless you use KVO’s infamously ugly 
> observation APIs (the slick new closure-based one won’t work here, since 
> we’re stuck with using string keys for this).
> 
> class MyClass: NSObject { 
>   private static let fooDefaultsKey = "Foo"
>   
>   @objc dynamic var foo: String {
>   didSet { UserDefaults.standard.set(self.foo, forKey: 
> MyClass.fooDefaultsKey) }
>   }
>   
>   override init() {
>   self.foo = UserDefaults.standard.string(forKey: 
> MyClass.fooDefaultsKey) ?? ""
>   
>   super.init()
>   }
> }
> 
> Charles
> 

___

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: Release mode bindings crash and release pools

2017-06-15 Thread Jonathan Mitchell

> On 15 Jun 2017, at 20:03, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Jun 15, 2017, at 04:46 , Jonathan Mitchell <li...@mugginsoft.com> wrote:
>> 
>> The crash occurs when the pool gets drained.
> 
>> Wrapping my -bind: calls in a release pool solves the issue too.
> 
> The information you’ve provided doesn’t make a lot of sense by itself. If 
> draining an autorelease pool is leading to a crash, then putting the affected 
> objects in a different autorelease pool and draining *that* should also crash.
Thanks for the reply.

Sorry that wasn’t clear.
The crash occurs when the default application created  thread pool gets drained.
It doesn’t crash if I supply a local thread pool that just wraps the -bind:.

Its the timing of when the relevant pool gets drained that seems to be 
important.
I don’t know what effect the release optimisation is having to cause this issue 
to appear.

> 
> Have you tried turning on Zombies to find out which incorrect reference is 
> being followed?
> 
Yes.
The NSViewController is calling its internal implementation that removes itself 
from the responder chain - _removeFromResponderChain
This method calls [NSWindow nextResponder] and the crash occurs there as the 
NSWindow is a zombie.

The nextResponder property uses assign memory semantics so it is prone to this 
sort of thing.
In my NSViewController subclass I already set self.nextResponder to nil in 
dealloc.
But I don’t set self.view.nextResponder to nil in dealloc and this causes the 
crash in loc_307c88: as view.nextResponder == deallocated NSWindow instance.
But setting self.view.nextResponder to nil in dealloc would affect responder 
chain patching for all view controllers and may have unwanted results.
So I will need to think about that.

void -[NSViewController _removeFromResponderChain](void * self, void * _cmd) {
r14 = self;
if ([self _viewControllerSupports10_10Features] == 0x0) goto .l1;

loc_307c3c:
r12 = r14->view;
rax = [r12 nextResponder];
if (rax == 0x0) goto .l1;

loc_307c63:
rbx = rax;
if (rbx == r14) goto loc_307c88;

loc_307c6b:
rax = [rbx nextResponder];
r12 = rbx;
if (rax != 0x0) goto loc_307c63;

.l1:
return;

loc_307c88:
[r12 setNextResponder:[r14 nextResponder]];
return;
}

J
___

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


Release mode bindings crash and release pools

2017-06-15 Thread Jonathan Mitchell
My macOS 10.12 ARC app has a gazillion bindings.

Many are made in the NIBS but a lot are dynamically applied in code.

In release mode I see the odd crash that can be traced back to NSAutoUnbinder 
getting dealloc'd in a release pool.
With build optimisations set to 0 there is no issue.
With build optimisations set to s there is an issue (a views window has been 
deallocated but the controller dealloc queries the responder chain - which uses 
assign semantics - and boom).

The issue occurs when I inadvertently create a binding when my view controller 
is about to be torn down.
An NSAutoUnbinder gets created during a bind call and added to the thread 
release pool.
The crash occurs when the pool gets drained.

My bindings are such that a dynamic binding can in theory get called when the 
view controller is getting torn down so I would like a general solution that 
mitigates the possible issue.

Two questions:

1. Does anyone have any insight into why the release pool draining seems to be 
an issue in release mode - and I know that trying to second guess the macro 
effect of optimisations is pretty thankless. Does the optimisation affect the 
ARC calls?

2. Wrapping my -bind: calls in a release pool solves the issue too. I can 
easily add a category method that wraps each -bind: call in a release pool. But 
what is the over head for this like?

I can of course crank the release optimisation level down to 0 but I have no 
guarantee that the issue will still not occur in some situations.

Thanks

J

___

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


Property in class mirrored to user defaults

2017-06-12 Thread Jonathan Taylor
Hi all,

This feels like a very basic question, but one that I have not had any luck 
searching for (maybe I am using the wrong terms?).

At the moment I have properties in a (singleton) class that are bound to UI 
elements. At the moment they have the same automatic values every time the app 
is launched, although the user can change them while it is running. What I 
would like is for the user's previous choice to be remembered when the app is 
next launched. Obviously this would seem to be a job for NSUserDefaults. I am 
not sure quite what the right way to structure things is, though.

All the simple examples I have seen bind to NSUserDefaults and then if the 
program actually wants to know what the value is, it simply accesses the values 
directly on NSUserDefaults. I would prefer not to do that, though (see below).

What I ~think~ I would like is to still be able to access the values as 
properties of my class. That seems to me like the natural way, and it would 
seem odd to have two categories of value, some accessed through properties on 
the class, and some accessed some other way via NSUserDefaults. However, if I 
bind the UI elements to the shared user defaults object, is that not what will 
happen? Or is there some way that I can "link" my class and the user defaults 
object, so that the properties are saved in user defaults but I can still 
access them in a fairly seamless way from my class? I do like the idea of 
having the properties (and their types) explicitly declared as part of my 
class, rather than being mysterious objects that only exist in the user 
defaults.

Does anyone have any advice on how I can achieve this, or on how I should be 
thinking about all this differently?
Thanks
Jonny
___

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: Drawing a 5 Sided Star Shape

2017-06-02 Thread Jonathan Mitchell

> On 2 Jun 2017, at 12:56, Dave  wrote:
> 
> Hi,
> 
> I want to draw a 5 sided Star Shape using UIBezierPath. I’ve search for a 
> general purpose algorithm, but I can’t find anything that I can get to work 
> with Cocoa/Objective-C. 
> 
You could take a peek at https://www.paintcodeapp.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: KVO - deallocation with observers attached

2017-06-02 Thread Jonathan Mitchell

> On 1 Jun 2017, at 00:51, Ken Thomases <k...@codeweavers.com> wrote:
> 
> On May 31, 2017, at 5:02 PM, Jonathan Mitchell <li...@mugginsoft.com> wrote:
>> 
>> It is common for deallocating objects to abort if they have observers still 
>> registered.
>> 
>> The Data_Test object is deallocated with non nil -observationInfo and yet it 
>> does not abort.
>> Why does this occur?
> 
> It's not clear to me that the KVO machinery is obligated to set 
> observationInfo to nil when an object is no longer being observed.  Note that 
> observationInfo is *not* an object pointer.  It's a pointer to void.  Among 
> other things, that means that there's no memory management involved in the 
> setter.  That is, it's not a strong reference or even a weak one.  So, for 
> example, it's not necessary for KVO to nil it out to free memory.

Thanks for the input.
I wasn’t able to get to the bottom of this despite poking around with Hopper 
through the foundation framework.
There is an NSKVODeallocate foundation function that can get called when an 
observed object gets deallocated.
It raises the familiar KVO exception if -observationInfo is not nil.

- observationInfo does return a void* but it dereferences to an 
NSKeyValueObservationInfo :  NSObject instance.
Its obviously private API though.

I was able to track the comings and goings of NSKeyValueObservationInfo using 
the memory graph debugger and malloc stack logging but enlightenment did not 
strike.

I was able to make my test project behave as I anticipated but my real world 
app doesn’t seem so compliant.

I am just trying to eradicate the possibility of crashes that occur when the 
observing object deallocs and the observed object keeps pumping notifications 
to the old observers address.

Thanks

J

___

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: Relative URLs, and string encodings

2017-06-02 Thread Jonathan Taylor
>> My attempt like:
>> [NSURL URLWithString:[path 
>> stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding] 
>> relativeToURL:relativeTo];
> 
> Ah, you want NSUTF8StringEncoding instead. Generally speaking, URL encoding 
> always uses UTF-8 nowadays.

Thankyou for your reply Jens. That's reassuring. (And soon after sending that I 
discovered that my proposed use of NSUnicodeStringEncoding was badly broken 
because it prevented url.path.UTF8String from working. Surprise, surprise: 
using your recommended UTF8 makes that work!

> You mean an open or close (aka “curly”) quote? They’re easily typed with 
> Option-[ and Option-Shift-[.

Ah yes, I knew that once, back in the day before text editors started 
auto-creating the open/close quotes themselves. I only write them manually in 
LaTeX these days.

Cheers
Jonny
___

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

Relative URLs, and string encodings

2017-06-01 Thread Jonathan Taylor
Can anyone help me with the seemingly simple task of creating a relative NSURL 
for a filesystem object? The catch here (sorry!) is that I really do need 
backward compatibility to 10.7, which rules out 
fileURLWithFileSystemRepresentation:isDirectory:relativeToURL: (which I suspect 
is the “right” way of doing this).

My attempt like:
[NSURL URLWithString:[path 
stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding] 
relativeToURL:relativeTo];

This had been working ok for some time, but I have just found it to be broken 
for filenames containing unusual characters. In particular, it fails when given 
a filename containing a “smart quote” (not easily created directly with the 
keyboard, but auto-generated as part of a time machine backup, based on the 
machine name).

Although I do not recall why I used stringByAddingPercentEscapesUsingEncoding, 
I think it must have been because it failed on some other filename pattern if I 
did not do that.

String encodings is something I know basically nothing about, I am afraid. I am 
speculating that what is happening is that the fancy apostrophe is not ASCII 
and so my code does not work for that filename. I can change the encoding to 
NSUnicodeStringEncoding, and things seem ok, but I don’t know whether that will 
now definitely work for all filenames, or whether I have just stored up an even 
more obscure problem for the future.

So, finally getting to two actual questions:
1. Will unicode encoding give me a robust solution here?
2. Is there a differnet, better way (pre-10.9) I should be using to create a 
relative URL?

Thanks for any advice
Jonny.
___

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: switching text field between editable and non-editable

2017-05-31 Thread Jonathan Mitchell

> On 31 May 2017, at 21:13, Ken Thomases  wrote:
> 
> On May 31, 2017, at 1:51 PM, J.E. Schotsman  wrote:
>> 
>> I have a hard time achieving what the message title says.
>> Depending on user settings I want a text field to be either editable or 
>> non-editable.

The following works for me.

@implementation NSTextField (CocoaDev)

- (void)bp_styleAsEditableTextField
{
[self setSelectable:YES];
[self setEditable:YES];
[self setDrawsBackground:YES];
[self setBezeled:YES];
[self.cell setScrollable:YES]; // required so that text scrolls 
horizontally when editing
[self.cell setWraps:NO];
[self.cell setLineBreakMode:NSLineBreakByWordWrapping]; // setting to 
truncate here kills the horiz scrolling during edit

[self setContentCompressionResistancePriority:1 
forOrientation:NSLayoutConstraintOrientationHorizontal];
}

- (void)bp_styleAsEditableWrappingTextField
{
[self setSelectable:YES];
[self setEditable:YES];
[self setDrawsBackground:YES];
[self setBezeled:YES];

[self.cell setLineBreakMode:NSLineBreakByWordWrapping];
}

- (void)bp_styleAsLabel
{
[self setSelectable:NO];
[self setEditable:NO];
[self setDrawsBackground:NO];
[self setBezeled:NO];

[self.cell setLineBreakMode:NSLineBreakByTruncatingTail]; // truncate the 
tail
[self setContentCompressionResistancePriority:1 
forOrientation:NSLayoutConstraintOrientationHorizontal];
}

- (void)bp_styleAsWrappingLabel
{
[self setSelectable:NO];
[self setEditable:NO];
[self setDrawsBackground:NO];
[self setBezeled:NO];

[self.cell setLineBreakMode:NSLineBreakByWordWrapping];
}

@end
___

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


KVO - deallocation with observers attached

2017-05-31 Thread Jonathan Mitchell
It is common for deallocating objects to abort if they have observers still 
registered.

However in some cases it seems that an object can get deallocated with 
observers attached and not abort.

I have instrumented my test case thoroughly and overridden -setObservationInfo: 
to log the observation changes as below.

The Data_Test object is deallocated with non nil -observationInfo and yet it 
does not abort.
Why does this occur?

I am sorting through some observer related crash reports just trying to figure 
out possible causes.

The Data_Test object is heavily observed throughout its lifetime both by 
bindings and explicit observations.

macOS 10.12

2017-05-31 22:49:01.616632+0100 MyApp Data_Test (0x11336d100) SetObservationInfo
2017-05-31 22:49:01.616656+0100 MyApp oldObservationInfo : 
 (
 Context: 0x10075a4b8, Property: 
0x6144abc0>
 
Context: 0x0, Property: 0x608000a51280>
)
2017-05-31 22:49:01.616692+0100 MyApp newObservationInfo : 
 (
 Context: 0x10075a4b8, Property: 
0x6144abc0>
)
2017-05-31 22:49:04.188226+0100 MyApp Data_Test (0x11336d100) dealloc

Thanks

Jonathan
___

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: inactive menu item

2017-05-24 Thread Jonathan Mitchell

> On 24 May 2017, at 10:07, J.E. Schotsman  wrote:
> 
> Hello,
> 
> I have a popup button with a menu item that I have set disabled in the xib.
> Every time the popup is enabled the item is enabled too!
> Why isn’t the latent state of the item preserved?
> I can solve the problem by binding the enabled state of the item to a value 
> that is always false but this shouldn’t be necessary IMHO.
> 
> Jan E.

I imagine this is because in the nib auto enables state is on for the popup 
button menu.
See the attributes inspector.

J


___

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: Context leak detected, msgtracer returned -1 ?

2017-05-22 Thread Jonathan Mitchell

> On 22 May 2017, at 22:24, Greg Parker <gpar...@apple.com> wrote:
> 
> 
>> On May 22, 2017, at 8:52 AM, Jonathan Mitchell <li...@mugginsoft.com 
>> <mailto:li...@mugginsoft.com>> wrote:
>> 
>> Context leak detected, msgtracer returned -1
>> 
> 
> The context is an IOAccelContext, which itself is deep in the graphics 
> machinery. The log complains once for every 512 objects allocated. Try 
> setting a breakpoint on IOAccelLogContextLeak or fprintf. 
> 
> You should also file a bug report that this log is too vague.
> 
> 
> -- 
> Greg Parker gpar...@apple.com <mailto:gpar...@apple.com> Runtime 
> Wrangler
> 
Thanks for that.

I can now see that an observation is triggering a button redraw.
I am processing a collection at this stage so the button redraw code is 
probably getting hammered.
This is in a tight loop and [NSView displayIfNeeded] is called repeatedly.
Removing this display update request silences the warning.

#0  0x7fff8967b5c4 in IOAccelLogContextLeak ()
#1  0x7fff8967c75d in IOAccelCommandQueueCreateWithQoS ()
#2  0x7fff7e1de805 in -[MTLIOAccelCommandQueue 
initWithDevice:descriptor:] ()
#3  0x7fff7b4f4d45 in CIMetalCommandQueueCreate ()
#4  0x7fff7b4e621c in CI::MetalContext::init(void const*) ()
#5  0x7fff7b3e332f in +[CIContext(Internal) 
internalContextWithMTLDevice:options:] ()
#6  0x7fff7b3ddcd8 in -[CIContext initWithOptions:] ()
#7  0x7fff7b3dd9f2 in +[CIContext contextWithOptions:] ()
#8  0x7fff788b96e9 in -[NSCIImageRep 
CGImageForProposedRect:context:hints:] ()
#9  0x7fff785879ff in -[NSImage 
_newSnapshotRepForRep:rect:context:processedHints:] ()
#10 0x7fff785542c2 in -[NSImage 
_snapshotRepForRep:rect:context:processedHints:] ()
#11 0x7fff78a0fcdb in __71-[NSImage 
drawInRect:fromRect:operation:fraction:respectFlipped:hints:]_block_invoke.1352 
()
#12 0x7fff78553543 in -[NSImage 
_usingBestRepresentationForRect:context:hints:body:] ()
#13 0x7fff785907e8 in -[NSImage 
drawInRect:fromRect:operation:fraction:respectFlipped:hints:] ()
#14 0x7fff78587480 in -[NSImage 
_drawMappingAlignmentRectToRect:withState:backgroundStyle:operation:fraction:flip:hints:]
 ()
#15 0x7fff78586d93 in -[NSButtonCell drawImage:withFrame:inView:] ()
#16 0x0001004efc7f in -[BPTimelineButtonCell 
drawImage:withFrame:inView:] at BPTimelineButtonCell.m:77
#17 0x7fff78586650 in -[NSButtonCell 
_configureAndDrawImageWithRect:cellFrame:controlView:] ()
#18 0x7fff78586285 in -[NSButtonCell drawInteriorWithFrame:inView:] ()
#19 0x0001004ef525 in -[BPTimelineButtonCell 
drawInteriorWithFrame:inView:] at BPTimelineButtonCell.m:28
#20 0x7fff7858531a in -[NSButtonCell drawWithFrame:inView:] ()
#21 0x0001004ef42c in -[BPTimelineButtonCell drawWithFrame:inView:] at 
BPTimelineButtonCell.m:19
#22 0x7fff785850d1 in -[NSControl drawRect:] ()
#23 0x7fff7857cf99 in -[NSView _drawRect:clip:] ()
#24 0x7fff785ccf2f in -[NSView 
_recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#25 0x7fff785cd39a in -[NSView 
_recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#26 0x7fff785cd39a in -[NSView 
_recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#27 0x7fff785cd39a in -[NSView 
_recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#28 0x7fff785cd39a in -[NSView 
_recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#29 0x7fff785cd39a in -[NSView 
_recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#30 0x7fff785cd39a in -[NSView 
_recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#31 0x7fff785cd39a in -[NSView 
_recursiveDisplayAllDirtyWithLockFocus:visRect:] ()
#32 0x7fff7857aad2 in -[NSView 
_recursiveDisplayRectIfNeededIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:topView:]
 ()
#33 0x7fff785786d8 in -[NSView 
_displayRectIgnoringOpacity:isVisibleRect:rectIsVisibleRectForView:] ()
#34 0x7fff78573fca in -[NSView displayIfNeeded] ()
#35 0x0001001eb5be in -[BPTimelineButton setButtonHighlight:] at 
BPTimelineButton.m:211
#36 0x0001001eb227 in -[BPTimelineButton highlightForOffState] at 
BPTimelineButton.m:134
#37 0x0001001eb197 in -[BPTimelineButton stateDidChange] at 
BPTimelineButton.m:123
#38 0x0001001eb29e in -[BPTimelineButton setEnabled:] at 
BPTimelineButton.m:147
#39 0x00010005011d in -[BPPayslipTimelineButton setButtonStatus:] at 
BPPayslipTimelineButton.m:145
#40 0x000100051104 in -[BPPayslipTimelineButton 
observeValueForKeyPath:ofObject:change:context:] at 
BPPayslipTimelineButton.m:277

___

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 coco

Context leak detected, msgtracer returned -1 ?

2017-05-22 Thread Jonathan Mitchell
Hi

On occasion I see the following in the Xcode console when running my Obj-C app:

Context leak detected, msgtracer returned -1

I have tried setting symbolic breakpoints on NSLog etc but to no avail.

Is the context in question a CGContext?

Thanks

J
___

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: Times in other cities

2017-05-15 Thread Jonathan Mitchell
You might want to err on the side of caution and ensure that the Calendar 
object is explicitly set to Gregorian rather than using the current system 
setting.

Jonathan

> On 15 May 2017, at 13:50, Eric E. Dolecki <edole...@gmail.com> wrote:
> 
> Thanks for your reply. Does this look safe to use?
> 
> // London
> let locale = TimeZone.init(abbreviation: "BST")
> let cal = Calendar.current
> let date = Date()
> let comp = cal.dateComponents(in:locale!, from: date)
> 
> // Local (right now for me it's Boston)
> let hour = Calendar.current.component(.hour, from: date)
> 
> print("HOUR OFFSET: \(comp.hour! - hour)") //HOUR OFFSET: 5
> 
> It's okay if the modifier is negative (Los Angeles from Boston, etc.)
> 
> 
> 
> 
> 
> 
> On Sun, May 14, 2017 at 9:29 PM Jens Alfke <j...@mooseyard.com> wrote:
> 
>> 
>>> On May 14, 2017, at 5:47 PM, Eric Dolecki <edole...@gmail.com> wrote:
>>> 
>>> I have a clock. If like to present the times in a few major cities.  Say
>> London, England. Based on the user's current time zone, present the correct
>> hour, min, and second for London. If I can see how to do it for one city, I
>> should be good for others.
>> 
>> Get an NSTimeZone instance based on a GMT offset or a name
>> Create an NSDateFormatter and set its timeZone property.
>> Use the formatter to convert [NSDate date] to a string.
>> 
>> If you want to display the time in some other way, like an analog clock,
>> use NSDateComponents instead of NSDateFormatter; then you can get the
>> hours, minutes and seconds.
>> 
>> —Jens
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/lists%40mugginsoft.com
> 
> This email sent to li...@mugginsoft.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: disable group of controls

2017-04-05 Thread Jonathan Mitchell

> On 5 Apr 2017, at 12:05, J.E. Schotsman  wrote:
> 
> 
>> On 05 Apr 2017, at 11:48, Jack Carbaugh  wrote:
>> 
>> Get a list of the controls then loop through it, setting each enabled 
>> property to false. The container holding them will hold a reference to them
> 
> That way you lose the latent enabled state.
> When the embedder is set to disabled some of the sub controls may already be 
> disabled.
You could create a simple queue for each control (an associated object might be 
handy here) and then push and pop the sub control state.

J
___

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: disable group of controls

2017-04-05 Thread Jonathan Mitchell

> On 5 Apr 2017, at 10:45, J.E. Schotsman  wrote:
> 
> 
>> On 03 Apr 2017, at 21:00, J.E. Schotsman wrote:
>> 
>> What is the Cocoa way of enabling/disabling a group of controls?
>> In Carbon I used to use a user pane for that.
>> I thought I would try an NSBox but then I realized it is not a control.
> 
> Nobody?
> I thought this would be a simple and solved problem.
> I tried subclassing MyEmbedder:NSControl and embedding in a custom view of 
> class MyEmbedder.
> Alas, setting the isEnabled property of the custom view has no effect on the 
> embedded controls.
> What am I missing?

I don’t think you are missing anything.
There is no built in support for this AFAIK.

For disabling groups of controls I generally just bind the relevant controls 
enabled property to a bool flag.

J
___

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: Can't use +initialize, now what?

2017-03-30 Thread Jonathan Hull

> On Mar 29, 2017, at 4:24 PM, Charles Srstka  wrote:
> 
>> On Mar 29, 2017, at 3:41 PM, Greg Parker  wrote:
>> 
>>> On Mar 29, 2017, at 9:02 AM, Charles Srstka >> > wrote:
>>> 
 On Mar 29, 2017, at 10:51 AM, Jens Alfke > wrote:
 
> On Mar 29, 2017, at 6:57 AM, Daryle Walker    >> wrote:
> 
> 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)”
 
 Huh, I haven’t heard of that. And I’m confused by “the Objective-C method” 
 — what’s that? Not the +initialize method being compiled, because that’s 
 in Swift. The superclass method?
 
 Guess I’ll follow that Radar link and read the bug report myself. Oh, 
 wait. :(
>>> 
>>> You actually can this time, since Swift’s bug reporter is actually open to 
>>> the public. https://bugs.swift.org/browse/SR-3114 
>>> >>  >
>>> 
>>> Basically, with Whole Module Optimization turned on, +initialize wasn’t 
>>> getting called. Their solution was to just get rid of +initialize.
>> 
>> You don't even need WMO. Many arrangements of Swift code can bypass ObjC 
>> +initialize.
>> 
>> Invocation of +initialize is a feature of objc_msgSend(). Swift code does 
>> not always use objc_msgSend() when calling methods: some methods are 
>> inlined, some are called via virtual table, some are called directly. None 
>> of these paths will provoke +initialize. 
>> 
>> Changing Swift's generated code to guarantee +initialize would be 
>> prohibitively expensive. Imagine an is-initialized check in front of every 
>> inlined call. It would be more expensive than +initialize in ObjC because 
>> +initialize checking is free once you pay the cost of objc_msgSend(). (The 
>> ObjC runtime checks +initialize on uncached dispatch, and never caches 
>> anything until +initialize completes. Most dispatches are cached so they pay 
>> nothing for +initialize support.)
>> 
>> +initialize in Swift isn't safe and is too expensive to make safe, so we're 
>> taking it away instead.
> 
> I wonder if an equivalent Swift-native feature could be added, something like 
> a typeInit block? If the block weren’t there, nothing special would happen, 
> and if the block were present, the compiler could basically generate the code 
> in the example I gave, but add the static var access to the front of every 
> initializer and static/class member. That shouldn’t impact performance too 
> much, and wouldn’t impact at all in the case that there’s no type initializer.

I hope so as well.  My favorite candidate so far would be a reflection 
capability to get a list of all classes/structs/enums adhering to a protocol.  
Then you could build your own initializable protocol fairly easily (and can 
even build whatever facility you want to guarantee a particular ordering or 
timing). The reason, I favor it over a specific method, is that it also enables 
a bunch of other cool patterns like extensible factories, and easy plug-ins.





___

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-13 Thread Jonathan Mitchell

> On 12 Mar 2017, at 21:23, Daryle Walker <dary...@mac.com> wrote:
> 
> 
> 
> 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. 
For NSDocument pdfPrintOperation  The docs say :

Important
This property does not copy the document’s printInfo to the PDF printing 
operation object. Your app should maintain a separate NSPrintInfo instance 
specifically for creating PDFs and assign it to the printInfo property of the 
operation object.

So just just set the printInfo on the operation.

As to how you configure the printInfo it depends on what output you require - 
in general its just a bunch of print settings for page size, margins etc.
However there are a few save related settings.

// flag as a PDF save job
[printInfo setJobDisposition:NSPrintSaveJob];

// Set the target destination for the file
[printInfoDictionary setObject:pdfInfo.URL forKey:NSPrintJobSavingURL];

Jonathan
___

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

struts and springs layout

2017-03-10 Thread Jonathan Mitchell
In Xcode 8 we can use struts and springs style layout until we add an explicit 
constraint.

The idea seems to be that the strut + spring definition get turned into 
constraints.

However, querying NSView -constraints returns nothing in this case, nor does 
the debug view hierarchy.

Is it just that the constraints are private in this case?

And what relevance does NSView -translatesAutoresizingMaskIntoConstraints add 
to the mix now now that we seem to have an auto detection of when we add 
constraints? 
Is it just a legacy behaviour now?

I don’t use the strut and spring method, normally adding whatever constraints I 
need.
But sometimes I think I am missing trick by not using the simpler s + s route 
in some cases.

However a lot of my UI features wrapping text and this is just a pain to 
implement pre 10.11.

Even on 10.12 s + s and text wrapping and textfields don’t seem to get on well.

Thanks

J



___

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: ncurses type wrapper for NStextview

2017-03-06 Thread Jonathan Mitchell

> On 6 Mar 2017, at 21:43, Julie Porter <jpor...@delectra.com> wrote:
> 
>  I am looking for something much simpler along the lines of
> 
> textmoveto(3,4)
> displaytext(Hello World)
> 

This is probably not what you were thinking of but it does provide for 
positional layout to a pdf view though not an NSTextView..
It is normally driven by an XML mapping file but you can call the required 
methods directly.
You can define all the font characteristics etc in the mapping file.

https://github.com/ThesaurusSoftware/PDFPageBuilder

Search for the following:

[self addTextItem:attrString rect:elementRect];

Jonathan


___

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: Binding NSTextField to an array

2017-03-06 Thread Jonathan Mitchell
Sounds like NSValueTransformer is in fact what you need.
It can take in your NSArray ref and spit out a single NSString that the 
NSTextField binding can live with.

Defining NSValueTransformer subclass for every binding can be a pain.
So I use a block approach. This has the big advantage that you can capture 
other variables if required - like calling a weak self method:

BPBlockValueTransformer * fooTransformer = [BPBlockValueTransformer 
valueTransformerWithBlock:^id(NSArray *a)  {
return [welf soSomethingWith:a];
}];
[self.fooView bind:NSValueBinding toObject:self withKeyPath:@“foo” 
options:@{NSValueTransformerBindingOption: fooTransformer}];


// subclass
@interface BPBlockValueTransformer : NSValueTransformer

+ (instancetype)valueTransformerWithBlock:(id(^)(id value))block;
@property (nonatomic,strong) id (^transform)(id value);

@end

@implementation BPBlockValueTransformer

+ (instancetype)valueTransformerWithBlock:(id(^)(id value))block
{
BPBlockValueTransformer *transformer = [[self alloc] init];
transformer.transform = block;

return transformer;
}

+ (Class)transformedValueClass
{
return [NSObject class];
}

- (id)transformedValue:(id)value
{
return self.transform(value);
}

@end


> On 6 Mar 2017, at 13:32, Jeremy Hughes  wrote:
> 
>> From what I understand of your example, you’re not “binding” anything in a 
>> Cocoa sense.
> 
> In the case of the single value, the text field is set up via the Bindings 
> pane of Interface Builder so that “Value" says “Bind to File’s Owner” with a 
> model key path of self.value. (And “value" is declared as dynamic so that 
> Swift will take care of KVO.) This works fine. Is this not a Cocoa binding?
> 
> What I don’t understand is why this works for a single value but doesn’t work 
> for an array of values, where I change the model key path to self.values.
> 
>> What you is an NSArrayController. Bind your text field to the array 
>> controller. Supply the array controller with content, and have it derive the 
>> selected value, be it single or multiple.
> 
> OK. I now have an array controller that is bound to File’s Owner with a model 
> key path of self.values, and I then bind the text field to the array 
> controller with a Controller Key value of “selection” (although I’m not sure 
> that’s right, because the array is not actually displayed anywhere for users 
> to select items).
> 
> Now I get the following error:
> 
> Cannot create number from object <_NSControllerObjectProxy: 0x600070b0> 
> of class _NSControllerObjectProxy
> 
> Jeremy
> 
> 
> ___
> 
> 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/lists%40mugginsoft.com
> 
> This email sent to li...@mugginsoft.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: Attributed strings - and bounding rects

2017-03-04 Thread Jonathan Mitchell
> I’m still not out of the wood yet though.


Sorry. I should have provided more details.

What I do to support table cell view wrapping is this. However, I have to 
support back to 10.9 so it may be possible to use some of the newer auto 
NSTextField line wrapping stuff.

1. Create a nib containing a wrapping cell view and associate it with a column 
that we want to wrap the content of. View based tableviews use Auto Layout for 
interior layout but in IB it doesn’t generally add and constrains to the 
default table cell views. So make a BPWrappingTableCellView nib that contains 
an NSTextField configured to wrap and constrained to the width and height of 
the cell.

columnCellNib = [[NSNib alloc] initWithNibNamed:@"BPWrappingTableCellView" 
bundle:nil];
[self.tableView registerNib:columnCellNib forIdentifier:@"action”];

2. Now the height of a row in the tableview must equal the height of the 
tallest cell in the row. There is a NSTableViewDelegate call for this. IN this 
example I have only one column that I need to wrap. If you have more you will 
need to find out which column has the tallest content.

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
// calculate height of row based on height of cell view in variable height 
column
id obj = self.arrayController.arrangedObjects[row];
CGFloat height = [tableView bp_heightOfRowForString:obj.description 
variableHeightColumnIdentifier:@"action"];
return height;
}

3. Calculate height of cell using a worker cell. This is an NSTableView 
category method.

#pragma mark -
#pragma mark Row height support

- (CGFloat)bp_heightOfRowForString:(NSString *)text 
variableHeightColumnIdentifier:(NSString *)identifier
{
/*
 
 Calculate height of row to accomodate wrapping text field in the 
description column.
 On 10.11 it might be possible to just use the fields Automatic setting.
 
 
http://stackoverflow.com/questions/7504546/view-based-nstableview-with-rows-that-have-dynamic-heights
 
 */
// we use a layout worker cell for height calcs.
if (!self.layoutCellView) {
self.layoutCellView = [self makeViewWithIdentifier:identifier 
owner:nil];
}

// reset size
CGFloat width = [self tableColumnWithIdentifier:identifier].width;
[self.layoutCellView setFrameSize:NSMakeSize(width, 10)];

// set the cell text
self.layoutCellView.textField.stringValue = text;

// layout to calculate size
self.layoutCellView.textField.preferredMaxLayoutWidth = width - 
self.layoutCellView.textField.frame.origin.x - 10;
[self.layoutCellView layoutSubtreeIfNeeded];
CGFloat height = self.layoutCellView.frame.size.height;

if (height < 30) height = 30;
if (height > 150) height = 150;

return height;
}

4. Deal with column resizing:

- (void)tableViewColumnDidResize:(NSNotification *)aNotification
{
// notify table view of row height change if variable height column width 
changes
NSTableColumn *tableColumn = aNotification.userInfo[@"NSTableColumn"];
NSTableView *tableView = tableColumn.tableView;
[tableView bp_columnDidResize:tableColumn 
variableHeightColumnIdentifiers:@[@"action"]];
}

Another NSTableView category method.
- (void)bp_columnDidResize:(NSTableColumn *)tableColumn 
variableHeightColumnIdentifiers:(NSArray *)columnIds
{
/*
 
 Trigger row height recalculation when change table column width
 
 */
if (self.numberOfRows > 0 && [columnIds 
containsObject:tableColumn.identifier]) {
 NSIndexSet *rowIndexSet = [NSIndexSet 
indexSetWithIndexesInRange:NSMakeRange(0, self.numberOfRows)];
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0];
[self noteHeightOfRowsWithIndexesChanged:rowIndexSet];
[NSAnimationContext endGrouping];
}
}

HTH

J


___

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: Attributed strings - and bounding rects

2017-03-03 Thread Jonathan Mitchell
Hi

I needed to do this for my pdf builder  implementation:

Using the NSLayoutManager directly gives the best level of control.
 
https://github.com/ThesaurusSoftware/PDFPageBuilder/blob/master/PDFPageBuilder/TSPageTextItem.m#L95

NSRect boundingRect = self.containerRect;

// if no rect height defined then use default
BOOL containerHasExplicitHeight = YES;
if (boundingRect.size.height == 0) {
boundingRect.size.height = self.pageHeight - 
self.containerRect.origin.y ;
containerHasExplicitHeight = NO;
}

// allocate text container and layout manager
NSTextContainer *textContainer = [[NSTextContainer alloc] 
initWithContainerSize:boundingRect.size];
textContainer.lineFragmentPadding = 0;  // defaults to non zero

NSLayoutManager *layoutManager = [[NSLayoutManager alloc] init];
[layoutManager addTextContainer:textContainer];
layoutManager.usesFontLeading = YES;

// allocate text storage and assign layout manager
self.textStorage = [[NSTextStorage alloc] 
initWithAttributedString:self.attributedString];
[self.textStorage addLayoutManager:layoutManager];

// do glyph layout
// NOTE: cannot quite get glyphRangeForBoundingRect configured correctly 
here
//self.glyphRange = [layoutManager glyphRangeForBoundingRect:boundingRect 
inTextContainer:textContainer];
self.glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];

// get rect used for actual glyph layout
self.usedTextRect = [layoutManager usedRectForTextContainer:textContainer];

Jonathan

> On 3 Mar 2017, at 13:28, Igor Ranieri <i...@elland.me> wrote:
> 
> Hi Peter.
> 
> 
> Have you tried also passing `usesLineFragmentOrigin` as one of the options? 
> It works here.
> 
> Here’s some code I’m currently using to achieve a similar effect:
> 
> let sizeLimit = CGSize(width: 80.0, height: CGFloat.greatestFiniteMagnitude)
> let size = attrString.boundingRect(with: sizeLimit, options: 
> [.usesLineFragmentOrigin, .usesFontLeading], context: nil).integral.size
> 
> And it returns the expected size.
> 
> 
> best,
> elland
> 
> 
>> On 3. Mar 2017, at 14:18, Peter Hudson <peter.hud...@me.com> wrote:
>> 
>> Hi All
>> 
>> I have done the following to try to determine the rect required to draw an 
>> attributed string( and thus the height of a row in a table view  - on MacOS 
>> ) 
>> 
>> I am trying to constrain my column width to 60 - and let the possible height 
>> of the row be a max of 1000.
>> 
>> 
>> let aString = anAttributedString
>> let constrainedSize = NSMakeSize(60.0, 1000.0)
>> let optns = NSStringDrawingOptions.usesFontLeading
>> let cntxt = NSStringDrawingContext()
>> cntxt.minimumScaleFactor = 1.0
>> 
>> let aRect = aString?.boundingRect(with: constrainedSize, options: optns, 
>> context: cntxt)
>> 
>> 
>> 
>> After the call to boundingRect,  aRect has its width set to 60 and its 
>> height set to 18.  
>> 
>> This is not however correct for the contents of the attributed string - I 
>> would expect the height to be at least 200 or so with the width constrained 
>> to 60.
>> 
>> Any help gratefully received.
>> 
>> Peter
>> 
>> 
>> 
>> ___
>> 
>> 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/igor%40elland.me
>> 
>> This email sent to i...@elland.me
> 
> 
> ___
> 
> 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/lists%40mugginsoft.com
> 
> This email sent to li...@mugginsoft.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: Xcode Framework wrapper for Library ( Exposing library headers)

2017-02-06 Thread Jonathan Mitchell
Its been a while since I wrapped my little noggin around this issue but perhaps 
this will help:

https://github.com/mugginsoft/Single-Object-Prelink-Framework-Demo 
<https://github.com/mugginsoft/Single-Object-Prelink-Framework-Demo>

There is a thread too, but the Apple list server seems to be on the beer again:
https://lists.apple.com/archives/xcode-users/2014/Apr/msg00079.html 
<https://lists.apple.com/archives/xcode-users/2014/Apr/msg00079.html>

Jonathan

> On 6 Feb 2017, at 22:04, Mr steve davis <southwestmons...@googlemail.com> 
> wrote:
> 
> 
> I would be so grateful if someone could help me, I have been banging my head 
> a against a brick wall for days on this now.
> Here’s a sample project if it helps… 
> http://www.thingsidoatwork.co.uk/MyProject.zip 
> <http://www.thingsidoatwork.co.uk/MyProject.zip>
> 
> I'm creating a Framework wrapper round a static library. The header 
> (MyLibrary.h) needs to be accessable from the ViewController.m file in 
> MyProject
> 
> MyProject
>   MyFramework
>   MyLibrary.h
>   libMyLibrary.a
> 
> 
> 
> #import "ViewController.h"
> @import MyFramework;
> 
> @implementation ViewController
> 
> - (void)viewDidLoad {
>[super viewDidLoad];
> 
>[[[MyLibrary alloc]init]test];
> }
> 
> 
> I have set MyLibrary.h to public
> MyFramework.h contains the line #import 
> 'Embedded Binaries' is set to MyFramework
> When I run the above code I get...
> 
> 
> Undefined symbols for architecture x86_64:
>  "_OBJC_CLASS_$_MyLibrary", referenced from:
>  objc-class-ref in ViewController.o
> ld: symbol(s) not found for architecture x86_64
> clang: error: linker command failed with exit code 1 (use -v to see 
> invocation)
> 
> 
> The only way I have found to solve this problem is to create a private Class 
> in MyFramework (called TestClass) and allocate MyLibrary. I assume this 
> forces MyLibrary to be linked at runtime and accessable from ViewController.
> But this is ugly as hell, what am I missing? 
> 
> #import "TestClass.h"
> #import "MyLibrary.h"
> 
> @implementation TestClass
> - (id)init {
>if (self = [super init]) {
> 
>[MyLibrary alloc]; //solves the problem of MyLibrary being accessable 
> from  ViewController
>}
>return self;
> }
> @end
> 
> 
> Is there a compiler flag I’m missing that would help? I have tried all-load 
> -ObjC etc but no luck.
> ___
> 
> 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/lists%40mugginsoft.com
> 
> This email sent to li...@mugginsoft.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: Overriding the release mehod

2017-01-25 Thread Jonathan Hull
One of my favorite things about this list is that the standard response to a 
question is to ask about the underlying motivation.  It shows that they are 
prepared to think deeply about your problem and don’t want to just give you a 
cookie cutter answer.  One of the main signs of an intelligent person in my 
mind :-)

Thanks,
Jon

> On Jan 25, 2017, at 3:38 PM, Greg Parker  wrote:
> 
> What Are You Trying To Do™ is in fact precisely the correct response to your 
> question. Some overrides of -release need to call [super release]. Others do 
> not. It depends on … what they are trying to do.
> 
> Overriding release to unregister an observer is almost certainly a bad idea, 
> but yes, such an override ought to call [super release] if the object is 
> expected to be retained and released and deallocated normally. 
> 
> 
> -- 
> Greg Parker gpar...@apple.com  Runtime 
> Wrangler
> 
> 
>> On Jan 25, 2017, at 8:23 AM, Dave  wrote:
>> 
>> I hate it when people as that question! There are some memory leaks in a 3rd 
>> party package. It overrides release to unregister an observer but doesn’t 
>> call super. If I call super the leaks go away and all is well. I just want 
>> to know where is it documented really, I can’t find it searching the docs.
>> 
>> Cheers
>> Dave
>> 
>>> On 25 Jan 2017, at 15:55, Mike Abdullah  wrote:
>>> 
>>> You’re inevitably going to get asked this:
>>> Why on earth are you overriding release? It’s an incredibly niche thing to 
>>> do, and the answer probably depends a lot on why you’re overriding it.
>>> 
 On 25 Jan 2017, at 16:52, Dave  wrote:
 
 Hi,
 
 Does [suoer release] need to be called if you override this method? I’m 
 99.9% sure it does, but I can’t find it anywhere it actually says it 
 in black and white.
 
 All the Best
 Dave
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
> 
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/cocoa-dev/jhull%40gbis.com
> 
> This email sent to jh...@gbis.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-20 Thread Jonathan Mitchell

> On 20 Jan 2017, at 21:36, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Jan 20, 2017, at 02:47 , Jonathan Mitchell <li...@mugginsoft.com 
> <mailto:li...@mugginsoft.com>> wrote:
>> 
>> NSTableView might go something like this:
>> 
>> @implementation TSTableView
>> 
>> - (NSSize)intrinsicContentSize
>> {
>>  NSSize  size   = [super intrinsicContentSize];
>>  NSInteger   nr  = [self numberOfRows];
>>  CGFloat rh  = [self rowHeight];
>>  CGFloat ih  = [self intercellSpacing].height;
>>  size.height = rh * nr + ih * MAX(nr, 1);
>>  return size;
>> }
> 
> My concern about this approach is timing. It needs to be supported by other 
> code that triggers autolayout whenever the number of rows changes. Further, 
> if the row height is not fixed (either because the height varies from row to 
> row, or because the row height is a logical height influenced by the 
> system-wide font size settings), it gets even more complicated.
Absolutely. Getting from raw concept to actual implementation for a particular 
use case can be a painful process.
And sometimes it is just not worth the candle.
I wince at the thought of the number of hours I have spent wrangling with auto 
layout.

___

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-20 Thread Jonathan Mitchell

> On 19 Jan 2017, at 18:25, Quincey Morris 
>  wrote:
> 
> On Jan 19, 2017, at 06:39 , Daryle Walker  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.
> 
Everything Quincey says is right.
No surprise there then.

However, subclassing NSTableView and NSTextView to provide intrinsicContentSize 
does not have to be awful for a simple scenario (though these sort of things 
can descend into awfulness sometimes…)

Obviously you need to obtain raw NSTableView and NSTextView instances sans 
NSScollView containers.

NSTableView might go something like this:

@implementation TSTableView
 
- (NSSize)intrinsicContentSize
{
NSSize  size   = [super intrinsicContentSize];
NSInteger   nr  = [self numberOfRows];
CGFloat rh  = [self rowHeight];
CGFloat ih  = [self intercellSpacing].height;
size.height = rh * nr + ih * MAX(nr, 1);
return size;
}

For textviews I do something like:

@interface TSTextView : NSTextView

// primitives
@property (assign, nonatomic) CGFloat borderOffsetX;
@property (assign, nonatomic) CGFloat borderOffsetY;
@end


@implementation TSTextView

#pragma mark -
#pragma mark Life cycle

- (instancetype)initWithFrame:(NSRect)frameRect textContainer:(nullable 
NSTextContainer *)container
{
self = [super initWithFrame:frameRect textContainer:container];
if (self) {
[self commonInit];
}
return self;
}

- (nullable instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
[self commonInit];
}
return self;
}

- (void)commonInit
{
_borderOffsetX = 1;
_borderOffsetY = 3;
self.usesFontPanel = NO;
self.usesFindPanel = NO;

}
#pragma mark -
#pragma mark Auto layout

- (NSSize)intrinsicContentSize
{
NSTextContainer* textContainer = [self textContainer];
NSLayoutManager* layoutManager = [self layoutManager];
[layoutManager ensureLayoutForTextContainer: textContainer];
NSSize size = [layoutManager usedRectForTextContainer: textContainer].size;

return NSMakeSize(NSViewNoInstrinsicMetric, size.height);
}

#pragma mark -
#pragma mark Accessors

- (void)setString:(NSString *)string
{
[super setString:string];
[self invalidateIntrinsicContentSize];
}

#pragma mark -
#pragma mark Text change notifications

- (void)didChangeText
{
[super didChangeText];
[self invalidateIntrinsicContentSize];
}

#pragma mark -
#pragma mark Focus ring

- (void)drawFocusRingMask
{
if (self.editable) {
NSRectFill(self.focusRingMaskBounds);
}
}

- (NSRect)focusRingMaskBounds {
NSRect r = [self bounds];
return NSMakeRect(r.origin.x - self.borderOffsetX, r.origin.y - 
self.borderOffsetY, r.size.width + self.borderOffsetX * 2, r.size.height + 
self.borderOffsetY * 2);
}


___

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-19 Thread Jonathan Mitchell

> On 19 Jan 2017, at 14:39, Daryle Walker <dary...@mac.com> wrote:
> 
> 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?
> 
Adding the subviews to the NSStackView should be standard fare.
However, I always find getting the constraints correctly configured painful.

The trick with stack views and multiple subviews, IMHO, is to ensure that the 
subviews correctly constrain their height.
You may also need to constrain the bottom of the last subview to the bottom of 
the stackview, depending on how you want things to lay out.

For scrolling I use an NSStackView subclass 
(https://github.com/mugginsoft/TSStackView) that includes the following to 
embed it in a scroll view.
Looks like I had to use a flipped NSClipView to get things to work out.

The subclass is getting on a bit so parts of it may be redundant if you are 
targeting the more recent versions of MacOS.

#pragma mark -
#pragma mark Embedding
- (NSScrollView *)scrollViewContainer
{
NSScrollView *scrollView = nil;

if (self.scrollViewAllocated) {
scrollView = [self enclosingScrollView];
}
else {
self.scrollViewAllocated = YES;

// allocate scroll view
scrollView = [[NSScrollView alloc] initWithFrame:NSMakeRect(0, 0, 100, 
100)];
scrollView.translatesAutoresizingMaskIntoConstraints = NO;

// allocate flipped clip view
TSClipView *clipView = [[TSClipView alloc] 
initWithFrame:scrollView.contentView.frame];
scrollView.contentView = clipView;
NSAssert(scrollView.contentView.isFlipped, @"ScrollView contenView must 
be flipped? Use TSClipView");

// configure the scrollview
scrollView.borderType = NSNoBorder;
scrollView.hasHorizontalScroller = YES;
scrollView.hasVerticalScroller = YES;
scrollView.autohidesScrollers = YES;

// stackview is the document
scrollView.documentView = self;

// constrain stackview to match dimension of scrollview
NSDictionary *viewsDict = NSDictionaryOfVariableBindings(self);
NSString *vfl = nil;
if (self.orientation == NSUserInterfaceLayoutOrientationVertical) {
vfl = @"H:|-0-[self]-0-|";
} else {
vfl = @"V:|-0-[self]-0-|";
}
self.stackViewConstraints = [NSLayoutConstraint 
constraintsWithVisualFormat:vfl options:0 metrics:nil views:viewsDict];

[scrollView addConstraints:self.stackViewConstraints];
}

return scrollView;
}

@interface TSClipView : NSClipView

@end

@implementation TSClipView

- (BOOL)isFlipped
{
return YES;
}
@end

HTH

Jonathan


___

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: Cocoa-dev Digest, Vol 13, Issue 518

2017-01-03 Thread Jonathan Prescott
I think that your expectation that presentViewController would retain a strong 
reference to the view controller is not right.  I would put the release after 
the dismissal code has run.  Now, you really don’t need the view controller.

Jonathan

> On Dec 17, 2016, at 3:00 PM, cocoa-dev-requ...@lists.apple.com wrote:
> 
> Send Cocoa-dev mailing list submissions to
>   cocoa-dev@lists.apple.com
> 
> To subscribe or unsubscribe via the World Wide Web, visit
>   https://lists.apple.com/mailman/listinfo/cocoa-dev
> or, via email, send a message with subject or body 'help' to
>   cocoa-dev-requ...@lists.apple.com
> 
> You can reach the person managing the list at
>   cocoa-dev-ow...@lists.apple.com
> 
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Cocoa-dev digest..."
> 
> 
> Today's Topics:
> 
>   1. Releasing modal view controller properly (Andreas Falkenhahn)
> 
> 
> --
> 
> Message: 1
> Date: Sat, 17 Dec 2016 17:07:10 +0100
> From: Andreas Falkenhahn <andr...@falkenhahn.com>
> To: cocoa-dev@lists.apple.com
> Subject: Releasing modal view controller properly
> Message-ID: <1688568431.20161217170...@falkenhahn.com>
> Content-Type: text/plain; charset=us-ascii
> 
> I'm not using ARC so I need to take care of releasing objects manually.
> I'm creating and presenting a modal UIViewController like this:
> 
>MyViewController *vc = [[MyViewController alloc] init];
> 
>vc.modalPresentationStyle = UIModalPresentationFormSheet;
>vc.preferredContentSize = CGRectMake(320, 320);
> 
>[self presentViewController:vc animated:YES completion:nil]
>[vc release];
> 
> When touching the modal view's close button my code does the following:
> 
>[[self presentingViewController] dismissViewControllerAnimated:YES 
> completion:nil];
> 
> Unfortunately, the app crashes right after the modal view has completed
> its transition animation.
> 
> When I disable the line "[vc release]", I don't get any crashes and it
> works fine. Can anybody explain why? I was expecting that 
> presentViewController()
> retained the view controller so that it is safe for me to release it
> right after making the call to presentViewController() because I don't
> need it any longer but apparently, there's something wrong in my code
> but I don't see it...
> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.com
> 
> 
> 
> --
> 
> ___
> 
> Cocoa-dev mailing list  (Cocoa-dev@lists.apple.com)
> 
> Do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins (at) lists.apple.com
> 
> https://lists.apple.com/mailman/listinfo/cocoa-dev
> 
> 
> End of Cocoa-dev Digest, Vol 13, Issue 518
> **



smime.p7s
Description: S/MIME cryptographic signature
___

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


NSPredicateEditor query

2016-12-14 Thread Jonathan Mitchell
I have an NSPredicateEditor configured to generate my queries.

I have two questions:

1. I want my users to be able to construct queries from a simple initial 
predicate.
Ideally I would like the initial predicate to operate on a single key path and 
look something like:

@"(self.fullName CONTAINS[cd] '')”

However I would also like the composite predicate row to be visible initially - 
This is the row that says “”Any / All of the following are true”;
The following works but always logs Warning - unable to find template matching 
predicate 1 == 1

@"(self.fullName CONTAINS[cd] '') AND (1 == 1)”

Is there a workaround for this?

2. The second query is connected.

I would also like to offer the ability to add additional composite predicate 
operators (Any/All).
The default UI doesn’t seem to implement this.

Is the solution simply to implement an action that takes the current predicate 
format, append an “AND ()” statement and regenerate the predicate?


Thanks

J
___

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: Using floating point instructions

2016-12-06 Thread Jonathan Mitchell

> On 6 Dec 2016, at 15:27, G 3  wrote:
> 
> Is there a way to fix this problem?
> 
Have you tried lowering the release build optimisation level to match the level 
used for debug build?.
It might get you on the right track.

J


___

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: Substituting instance of cell subclass for instance of superclass

2016-11-12 Thread Jonathan Mitchell

> On 12 Nov 2016, at 01:34, James Walker  wrote:
> 
> However, the new cell has failed to copy much of the state of the old one.  
> Things like title, font, target, action, bezelStyle...  I can manually copy 
> anything that I notice is missing, but I'm just wondering why the keyed 
> archiver approach here doesn't work.

It might be that NSButton archives the missing properties and applies them to 
the unarchived cell during initialisation.


___

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: Programmatically Clear Dirty NSDocument

2016-11-07 Thread Jonathan Mitchell

> On 7 Nov 2016, at 18:46, Richard Charles  wrote:
> 
> NSChangeUndone

try NSChangeCleared



___

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: Prioritizing drawing of the important stuff

2016-11-01 Thread Jonathan Taylor
Hi everyone,

Thankyou all for your replies. Plenty of food for thought there - much 
appreciated. Looks like timers and flow control is the way forward then, if I 
want to tackle this. I just thought I'd see if there was anything built in to 
the standard UI frameworks that might be able to help, but it seems not.

To answer one of Quincey's comments:

>> The low priority thing only really runs  when *nothing* else at all is 
>> happening.
> 
> This shouldn’t be happening, on most Macs. An average desktop Mac has at 
> least 2 CPU cores (4 logical CPUs), which should allow at least 2 
> compute-bound tasks to proceed simultaneously...

The reason for this is that the coalescing, post-when-idle NSNotifications I 
was talking about were being posted to the main queue. Hence all the main queue 
time was being taken up in ultra-smooth drawing of sliders etc, since that of 
course also happens on the main queue (UI drawing...). I agree that it looks as 
if I should bite the bullet and run all this stuff multithreaded. The thing is, 
a lot of it doesn't fundamentally ~need~ to run multithreaded - one thread 
should be enough to get drawing responsiveness that I'm pretty happy with, if I 
could just find a way to control what priorities the different aspects are 
being treated with. Sounds like timers, flow control and/or multiple 
threads/queues is the way to go if I want to solve this properly.

Cheers
Jonny.
___

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: Prioritizing drawing of the important stuff

2016-10-29 Thread Jonathan Taylor
The point, though, is that the slider will happily update pretty much as as 
often as the CPU allows. The issue is how to control what the OS considers to 
be "smooth enough" slider updates - there's a point at which I'd much rather 
have it "only" update the slider and the quick-to-draw image 10 times/sec, and 
have a bit of time spare to do the low-priority drawing, rather than updating 
the slider and easy image 60 times/sec.

On 29 Oct 2016, at 12:27, Slipp Douglas Thompson <apple+cocoa-...@slippyd.com> 
wrote:

> You could just set up a simple debounce timer— reset it back to 0sec elapsed 
> time whenever the slider is updated, and if it reaches a small delay then the 
> HQ image is rendered (and remains on-screen until the slider is later moved 
> and the process repeats).  No need to rely on GCD or threading.
> 
> — Slipp
> 
>> On Oct 29, 2016, at 4:37 AM, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
>> wrote:
>> 
>> Hi all,
>> 
>> This is a bit of a general question, but hopefully people may have some 
>> suggestions. I've got some drawing code that synthesizes an image in a 
>> window, which will change in response to sliders (e.g. changing the camera 
>> perspective). My problem is how to make it so that the redrawing of the 
>> image is as responsive as possible as the slider moves.
>> 
>> At the moment I just respond to KVO notifications from the slider by 
>> redrawing. This works fairly well. However, after further development work 
>> my program is now a bit more complicated. Effectively, I have two images, 
>> one of which is expensive to draw and one less so. What I would like is to 
>> have the quick-to-draw one update fairly often, and the more expensive one 
>> at lower priority. Does anyone have any suggestions about how to achieve 
>> this?
>> 
>> Ideally, I would like the quick image to continue to update responsively as 
>> the slider moves. I am less bothered about how responsive the slow image is. 
>> One way I could do this is to treat it as low priority, either though a low 
>> priority GCD thread or through coalescing post-when-idle NSNotifications. My 
>> experiments so far, though, suggest that this is a rather binary thing. The 
>> low priority thing only really runs  when *nothing* else at all is 
>> happening. This can lead to a scenario where (as far as I can tell via 
>> Instruments) the OS is spending every moment of idle time redrawing a moving 
>> slider at some outrageous frequency, making it look ultra-smooth, but not 
>> dedicating *any* time at all to doing my low-priority drawing.
>> 
>> So, I think this basically boils down to a question of load balancing. Is 
>> there a good way to balance the time my code spends on different drawing 
>> activities, making sure all do happen to some extent, but some more often 
>> than others? Importantly (and most challengingly I think) this includes UI 
>> drawing activities that the OS undertakes on my behalf (which I have less 
>> control over).
>> 
>> I fear there is no easy solution to this, but if anyone has any suggestions 
>> for things I should look at, that would be really helpful.
>> 
>> Cheers
>> Jonny.
>> ___
>> 
>> 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/apple%2Bcocoa-dev%40slippyd.com
>> 
>> This email sent to apple+cocoa-...@slippyd.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: Prioritizing drawing of the important stuff

2016-10-29 Thread Jonathan Taylor
Hi Jeff,

Thanks for your reply. Unless I am misunderstanding you, though, I think we are 
talking about two slightly different things? It seems that what you are 
referring to is useful in the case where there is a "low quality" and "high 
quality" method for redrawing the *same* image. In that case, inLiveResize 
would be useful for knowing which of the two to use. In my case, though, I have 
two separate images. In fact, one is an xy cross section through a 3D dataset, 
and one is a 3D rendering (which clearly takes longer to compute). It makes 
sense for the xy cross section redraw to be more responsive, since it is 
cheaper to draw, but I don't want the 3D rendering to be neglected entirely. 

Is there a way that what you describe can help there, or are we talking about 
two slightly different things here?

Cheers
Jonny.

On 29 Oct 2016, at 11:24, Jeff Szuhay <j...@szuhay.org> wrote:

> Actually, there is. This sounds a lot like the resize logic built into the 
> framework.
> 
> In Apple’s “View Programming Guide” there is a section dedicated to “Drawing 
> During Live Window Resizing”
> You already have the fast and slow methods for drawing so you can use them if 
> you pay attention to 
> 
>   -(BOOL) inLiveResize
> 
> Also, you can override viewWillStartLiveResize: and viewDidEndLiveResize: 
> methods on your NSView.
> 
> There is also a demo app that uses bindings to change the window shape and 
> transparency based on its size that might be helpful.
> 
> So, I think I am saying this problem is not new and has been addressed in 
> several different ways in the NSView class.
> 
> 
>> On Oct 29, 2016, at 2:37 AM, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
>> wrote:
>> 
>> Hi all,
>> 
>> This is a bit of a general question, but hopefully people may have some 
>> suggestions. I've got some drawing code that synthesizes an image in a 
>> window, which will change in response to sliders (e.g. changing the camera 
>> perspective). My problem is how to make it so that the redrawing of the 
>> image is as responsive as possible as the slider moves.
>> 
>> At the moment I just respond to KVO notifications from the slider by 
>> redrawing. This works fairly well. However, after further development work 
>> my program is now a bit more complicated. Effectively, I have two images, 
>> one of which is expensive to draw and one less so. What I would like is to 
>> have the quick-to-draw one update fairly often, and the more expensive one 
>> at lower priority. Does anyone have any suggestions about how to achieve 
>> this?
>> 
>> Ideally, I would like the quick image to continue to update responsively as 
>> the slider moves. I am less bothered about how responsive the slow image is. 
>> One way I could do this is to treat it as low priority, either though a low 
>> priority GCD thread or through coalescing post-when-idle NSNotifications. My 
>> experiments so far, though, suggest that this is a rather binary thing. The 
>> low priority thing only really runs  when *nothing* else at all is 
>> happening. This can lead to a scenario where (as far as I can tell via 
>> Instruments) the OS is spending every moment of idle time redrawing a moving 
>> slider at some outrageous frequency, making it look ultra-smooth, but not 
>> dedicating *any* time at all to doing my low-priority drawing.
>> 
>> So, I think this basically boils down to a question of load balancing. Is 
>> there a good way to balance the time my code spends on different drawing 
>> activities, making sure all do happen to some extent, but some more often 
>> than others? Importantly (and most challengingly I think) this includes UI 
>> drawing activities that the OS undertakes on my behalf (which I have less 
>> control over).
>> 
>> I fear there is no easy solution to this, but if anyone has any suggestions 
>> for things I should look at, that would be really helpful.
>> 
>> Cheers
>> Jonny.
>> ___
>> 
>> 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/jeff%40szuhay.org
>> 
>> This email sent to j...@szuhay.org
> 


___

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

Prioritizing drawing of the important stuff

2016-10-29 Thread Jonathan Taylor
Hi all,

This is a bit of a general question, but hopefully people may have some 
suggestions. I've got some drawing code that synthesizes an image in a window, 
which will change in response to sliders (e.g. changing the camera 
perspective). My problem is how to make it so that the redrawing of the image 
is as responsive as possible as the slider moves.

At the moment I just respond to KVO notifications from the slider by redrawing. 
This works fairly well. However, after further development work my program is 
now a bit more complicated. Effectively, I have two images, one of which is 
expensive to draw and one less so. What I would like is to have the 
quick-to-draw one update fairly often, and the more expensive one at lower 
priority. Does anyone have any suggestions about how to achieve this?

Ideally, I would like the quick image to continue to update responsively as the 
slider moves. I am less bothered about how responsive the slow image is. One 
way I could do this is to treat it as low priority, either though a low 
priority GCD thread or through coalescing post-when-idle NSNotifications. My 
experiments so far, though, suggest that this is a rather binary thing. The low 
priority thing only really runs  when *nothing* else at all is happening. This 
can lead to a scenario where (as far as I can tell via Instruments) the OS is 
spending every moment of idle time redrawing a moving slider at some outrageous 
frequency, making it look ultra-smooth, but not dedicating *any* time at all to 
doing my low-priority drawing.

So, I think this basically boils down to a question of load balancing. Is there 
a good way to balance the time my code spends on different drawing activities, 
making sure all do happen to some extent, but some more often than others? 
Importantly (and most challengingly I think) this includes UI drawing 
activities that the OS undertakes on my behalf (which I have less control over).

I fear there is no easy solution to this, but if anyone has any suggestions for 
things I should look at, that would be really helpful.

Cheers
Jonny.
___

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: iOS: Preventing a singleton from being deallocated when the app is in the background.

2016-10-19 Thread Jonathan Mitchell

> On 19 Oct 2016, at 22:14, Jens Alfke  wrote:

>  So that’s not what the problem is.
> 
It may be that the a separate instance of the singleton is getting created via 
the normal alloc - init sequence outside of the normal singleton accessor.
That should be trivial to check for.
___

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: PDFKit on 10.12

2016-10-05 Thread Jonathan Mitchell

> On 5 Oct 2016, at 07:52, Antonio Nunes <devli...@sintraworks.com> wrote:
> 
> On 04 Oct 2016, at 14:26, Jonathan Mitchell <li...@mugginsoft.com> wrote:
>> 
>> PDFKit seems a bit disturbed on Sierra.
>> The 10.12 beta 3 seems to improve things but there are still some rendering 
>> stutters etc.
> 
> 1. Why are you referring to a beta, when 10.12 has been out for weeks now?

Oops. that should have been 10.12.1 Beta (16B2338c)..

> Whatever is going on with PDFKit, it’s not good.


I agree with that.

PDFKit is long in the tooth and the documentation is a bit patchy.
However there is no way I can just write it off.

My solution involves assembling multipage PDFs from templates that incorporate 
a static base PDF over which I write text derived from my object model.
The composed PDF is then viewed, printed or exported.
On 10.9 to 10.11 peace reigns.

The 10.12 issues are rather unpredictable.
Some documents render fine others don’t.
Obviously this makes tracking down the source of the issues tough.
It also makes it difficult to come up with meaningfully directed bug reports to 
send back in to bugreporter.apple.com.

It would be helpful if someone from the PDFKit development team would chip in 
with insight into how the kit has changed in 10.12.

If not I might need to go down the route of a TSI.

Jonathan


___

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

PDFKit on 10.12

2016-10-04 Thread Jonathan Mitchell
PDFKit seems a bit disturbed on Sierra.
The 10.12 beta 3 seems to improve things but there are still some rendering 
stutters etc.

Has PDFKit been reworked - there doesn’t seem to be any mention of it in the 
release notes?
If so it might be a question of waiting for the internal gremlins to be hunted 
down rather than me wasting too much time on this.

Before 10.12 PDFPage -(void)drawWithBox:(PDFDisplayBox)box was called.

In 10.12 PDFPage -(void)drawWithBox:(PDFDisplayBox)box 
toContext:(CGContextRef)context was defined.

However, on 10.12.0 when printing NSPrintThumbnailView calls 
drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context not toContext:.
My only solution here has been to override the private  PDFPage 
-(void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context

In addition screen rendering seems to be suffering.
Rendering now has to target the CGContextRef given in PDFPage 
drawWithBox:toContext:

I render additional text onto the PDF using NSLayoutManager using a flipped 
NSGraphicsContext.

Pre 10.12 this worked fine. Now it is flakey - often I just get a PDFPage rect 
filled with red (printing seems okay).
Perhaps I am not handling the context correctly.

It would seem that the actual generation is now called on a background thread 
and that [NSGraphicsContext currentContext] can be nil.
I try to deal with this but all is still not quite what it was.

- (void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context
{
[super drawWithBox:box inContext:context];
   
  BOOL hasInitialNSGraphicsContext = NO;

if ([NSGraphicsContext currentContext]) {
[NSGraphicsContext saveGraphicsState];
hasInitialNSGraphicsContext = YES;
}
else {
CGContextSaveGState(context);
}

// life is much easier if we use a flipped co-ordinate system.
// NSLayoutManager expects a flipped NSGraphicsContext to be present.
NSGraphicsContext *flippedGC = [NSGraphicsContext 
graphicsContextWithGraphicsPort:context flipped:YES];
[NSGraphicsContext setCurrentContext:flippedGC];

// define the flip transform
NSAffineTransform* xform = [NSAffineTransform transform];
[xform translateXBy:0.0 yBy:self.mediaBoxRect.size.height];
[xform scaleXBy:1.0 yBy:-1.0];
[xform concat];

// draw all map items
… do my drawing here

if (hasInitialNSGraphicsContext) {
[NSGraphicsContext restoreGraphicsState];
}
else {
CGContextRestoreGState(context);
}

}

Jonathan
___

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: Mystery Threads

2016-09-30 Thread Jonathan Mitchell

> On 30 Sep 2016, at 10:57, Gerriet M. Denkmann  wrote:
> 
> 
> 
> But I just cannot see anything which forces my function to run 16 times 
> longer in the first case.
> 
> Any ideas where to look for a reason?

https://github.com/apple/swift-corelibs-libdispatch/blob/ab16f5e62859ff2f54996b8838f8304a8d125102/src/apply.c


___

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: Stupid objective-c question

2016-09-23 Thread Jonathan Mitchell

> On 23 Sep 2016, at 10:04, Quincey Morris 
>  wrote.
> 
> As previously mentioned, the safest way to do this is:
> 
>> static void* kMyContext = 
> 
Thats a neat trick. It’s not an initialisation that I have seen before and on 
first glance I thought it was a typo but it works.
I normally go with:

static char myContext;

However, being able to ditch the address of operator has some appeal.


___

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: Package installation on MacOS Sierra

2016-09-20 Thread Jonathan Mitchell
Sorry. This was a false alarm.
It turns out that I was anticipating a new installation into /Applications.
However I had a prior installation in username/Downloads so that got updated 
instead.

J

> On 18 Sep 2016, at 22:22, Jonathan Mitchell <li...@mugginsoft.com> wrote:
> 
> Hi
> 
> I have a MacOS package that installs into /Applications on 10.11.
> On 10.12 it appears to install into the user’s Downloads folder.
> 
> Is this change related to the new feature in MacOS 12 to encapsulate 
> downloaded apps into a read only container?
> 
> Thanks
> 
> J
> ___
> 
> 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/lists%40mugginsoft.com
> 
> This email sent to li...@mugginsoft.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

Package installation on MacOS Sierra

2016-09-18 Thread Jonathan Mitchell
Hi

I have a MacOS package that installs into /Applications on 10.11.
On 10.12 it appears to install into the user’s Downloads folder.

Is this change related to the new feature in MacOS 12 to encapsulate downloaded 
apps into a read only container?

Thanks

J
___

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: C callbacks with NSNotificationCenter?

2016-09-07 Thread Jonathan Mitchell

> Of course, I can't use this code in a normal C function because there are
> references to "self" and the selector thing doesn't look like it's compatible 
> to
> C. So I could just subclass AVPlayerItem and voila, everything's fine.
I forgot to say that as long as your c function is in a .m file you can create 
and manipulate Obj-C objects freely.

void testNsObjectInCfunc() {
NSString *q = @"Am I alive";
}

Self is just a pointer to an object so within your c Functions you can cast it 
to the right type and call methods etc at will.
Obj-C methods are C functions that receive self as a parameter.

Note that using the CF objects is generally more of a challenge than using 
NSObject objects.

Jonathan
___

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: C callbacks with NSNotificationCenter?

2016-09-07 Thread Jonathan Mitchell

> On 7 Sep 2016, at 17:09, Andreas Falkenhahn  wrote:
> 
> 
> Still, I'm wondering: Is it also possible to have NSNotificationCenter call
> a C function for me whenever the notification triggers? Can this somehow
> be achieved or am I forced to use full Objective C here?
> 
I would go about this by creating a singleton Obj-C object to handle all my 
notifications.
I would then register C Function pointers with this, perhaps using an 
NSMapTable or its CF equivalent to track the relationship between the incoming 
notification and the desired c function.
When the notification comes in I look up my map and call the C function.

HTH

J


___

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: Unusual Conditional Formatting

2016-09-07 Thread Jonathan Mitchell
A couple of suggestions.

> Here is what I have so far: I used a category on NSNumber to add a 
> "valueType" attribute as described at 
> http://nshipster.com/associated-objects/.
> 
> The formatter checks this and the user preference when formatting an incoming 
> value.  It sets some instance variables on itself to remember what it last 
> saw so that it can correctly default its interpretation of an entered value 
> when trying to send it back.
> 


On your associated object setter add KVO support.

- (void)setValueType:(int)valueType
{
[self willChangeValueForKey:@"valueType"];
objc_setAssociatedObject(self, @selector(valueType), @(valueType), 
OBJC_ASSOCIATION_RETAIN);
[self didChangeValueForKey:@"valueType"];
}



> The binding for the values is indirect - to the effect of "myThing.value" - 
> and if I change "myThing" but the new thing has the same numeric value, the 
> formatter does not always seem to trigger to render the value in the correct 
> format - it holds that of the previous thing.  If I change the value from 
> another control, when the bindings update the field, the formatting is 
> suddenly corrected.

The formatter will only receiver the value part of “myThing.value”.
It may well be that the formatter doesn’t re-format because the actual value 
doesn’t change - formatting may be an expensive operation.
In this case you may want to reformat so:

1.  consider Manual triggering of reformat if valueType changes.
2. Try overriding NSFormatter -stringForObjectValue: - that should give you a 
low enough foothold into the rendering.

HTH

J


___

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: slicing in Swift

2016-09-06 Thread Jonathan Hull
I realized my comment may not have been clear. Here is the actual code (written 
in Mail):

var numbers: [UInt64] = …

func numbers( upTo nbr: Int ) -> [UInt64]
{
return Array( numbers[ 0 ..< nbr ] )
}

Thanks,
Jon

> On Sep 6, 2016, at 5:42 PM, Jonathan Hull <jh...@gbis.com> wrote:
> 
> You can explicitly create an array with the slice by using ‘Array(slice)’.  
> Honestly, I am not sure of the actual value of slices because of issues like 
> this.  I would rather have those methods return an Array which is some sort 
> of copy on write slice internally.
> 
> Thanks,
> Jon
> 
>> On Sep 6, 2016, at 5:33 PM, Gerriet M. Denkmann <gerr...@mdenkmann.de> wrote:
>> 
>> var numbers: [UInt64] = …
>> 
>> func numbers( upTo nbr: Int ) -> [UInt64] 
>> {
>>  let slice = numbers[ 0 ..< nbr ] 
>>  return slice
>>  //  Cannot convert return expression of type ‘ArraySlice' 
>> to return type '[UInt64]' 
>> 
>>  //  workaound:
>>  var outCopy:[UInt64] = []
>>  for i in 0 ..< nbr { outCopy.append( numbers[i] ) }
>>  return outCopy
>> }
>> 
>> Any better way to do this?
>> 
>> Gerriet.
>> 
>> 
>> ___
>> 
>> 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/jhull%40gbis.com
>> 
>> This email sent to jh...@gbis.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/jhull%40gbis.com
> 
> This email sent to jh...@gbis.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: slicing in Swift

2016-09-06 Thread Jonathan Hull
You can explicitly create an array with the slice by using ‘Array(slice)’.  
Honestly, I am not sure of the actual value of slices because of issues like 
this.  I would rather have those methods return an Array which is some sort of 
copy on write slice internally.

Thanks,
Jon

> On Sep 6, 2016, at 5:33 PM, Gerriet M. Denkmann  wrote:
> 
> var numbers: [UInt64] = …
> 
> func numbers( upTo nbr: Int ) -> [UInt64]  
> {
>   let slice = numbers[ 0 ..< nbr ] 
>   return slice
>   //  Cannot convert return expression of type ‘ArraySlice' 
> to return type '[UInt64]' 
> 
>   //  workaound:
>   var outCopy:[UInt64] = []
>   for i in 0 ..< nbr { outCopy.append( numbers[i] ) }
>   return outCopy
> }
> 
> Any better way to do this?
> 
> Gerriet.
> 
> 
> ___
> 
> 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/jhull%40gbis.com
> 
> This email sent to jh...@gbis.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: Dynamic-width Collection View

2016-08-10 Thread Jonathan Hull
The main issue is that the cell doesn’t (and shouldn’t) have any idea about 
what size the collectionView is.  You could actually use the delegate though 
(which has a wider view) and provide the size that way.

That said, I did additional research and found other people with your issue.  
Relevant posts:
https://github.com/imyoungyang/DynamicHeight

http://stackoverflow.com/questions/25895311/uicollectionview-self-sizing-cells-with-auto-layout

My recommendation would be to remove the preferredAttributes stuff, and give 
your cell’s content view an explicit width constraint. Then in the 
collectionView:layout:sizeForItemAtIndexPath: method of your 
FlowLayoutDelegate, set the constant of the width constraint to the desired 
width (you are passed the collectionView). Then return the result of 
contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize).  Note: 
I haven’t actually tried this… all code written in mail.

Thanks,
Jon

> On Aug 10, 2016, at 2:27 PM, Doug Hill <cocoa...@breaqz.com> wrote:
> 
> Jonathon,
> 
> Thanks for the feedback.
> 
> A question that comes to mind is, what about making cells the same size as 
> the collection view requires going through subclassing the collection view 
> layout? Apple documentation IMPLIES this should work. It even documents that 
> developers should use preferredLayoutAttributesFittingAttributes for this 
> very purpose.
> 
> The reason I don't want to subclass flow layout is that I pretty much want 
> the exact functionality the default flow layout provides:
> 
> 1. Automatically calculating layout rects that flow across lines.
> 2. Calculating the height of cells dynamically at runtime via 
> 'estimatedItemSize'
> 
> Given that, I'm open to ideas on what I should override in a layout subclass. 
> Particularly ones that don't require me to reimplement #1 and #2 above.
> 
> Doug Hill
> 
>> On Aug 10, 2016, at 2:16 PM, Jonathan Hull <jh...@gbis.com 
>> <mailto:jh...@gbis.com>> wrote:
>> 
>> Because you are trying to make the width of the cell the same size as the 
>> collection view, I would strongly consider writing a small subclass of flow 
>> layout.  It honestly sounds like less work than what you are dealing with 
>> now.
>> 
>> Thanks,
>> Jon
>>  
>>> On Aug 10, 2016, at 1:29 PM, Doug Hill <cocoa...@breaqz.com 
>>> <mailto:cocoa...@breaqz.com>> wrote:
>>> 
>>>> 
>>>> On Aug 10, 2016, at 11:10 AM, Doug Hill <cocoa...@breaqz.com 
>>>> <mailto:cocoa...@breaqz.com>> wrote:
>>>> 
>>>> I'm currently trying to implement something that seems basic but has been 
>>>> driving me nuts: making a Collection View with cells that are 
>>>> dynamic-width and height at runtime.
>>>> 
>>> 
>>> Again, looking for any ideas, pointers, etc. about any of this, including 
>>> whether I'm going about this the wrong way.
>>> 
>>> Doug Hill
> 

___

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: Mixed-state checkboxes

2016-07-08 Thread Jonathan Taylor
Thanks Quincey, that makes sense what you're saying about it being more an 
action method, and your suggested approach sounds nice. 

However, I have not managed to quite get things working based on what I think 
you were describing. I have set up an action on the checkbox, and based on your 
comment about "With no setter, the binding won’t try to update the property, 
it’ll basically be read-only" I changed the bound property to read-only. Maybe 
that was not what you had intended, but with Xcode 5 at least there did not 
seem to be a way I could explicitly say that the binding should only be used 
for reading only. Anyway, if I do that, I get an error: "this class is not key 
value coding-compliant for the key globalChannelEnableState". I wonder if I 
have misunderstood what you were meaning?

Also, when you write:
> You don’t need to dispatch anything to a later iteration of the main event 
> loop. (Even in your current code — the setter will automatically generate the 
> KVO notification, so doing it again later is redundant.)
which of the three choices of code (switched by #if statements...) are you 
referring to, from the code I originally posted? For me, in the first and third 
options the will/didChangeValue calls are essential to avoid the checkbox being 
left displaying '-' state. Is that not the behaviour you would expect here?

One option would be to take up your suggestion of the action method, but 
abandon the binding altogether and just set the actual state of the UI element 
directly from my code. I'd definitely be interested in understanding what it 
sounded like you were suggesting with a "basically read-only" binding though...

Cheers
Jonny



On 8 Jul 2016, at 18:35, Quincey Morris <quinceymor...@rivergatesoftware.com> 
wrote:

> On Jul 8, 2016, at 05:36 , Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
> wrote:
>> 
>> My setter code currently looks like this:
>> 
>> -(void)setGlobalChannelEnableState:(NSInteger)state
> 
> In the circumstances you describe, a setter method is effectively an action 
> method, not a setter — that is, it becomes a method that’s called when your 
> code needs to do something, rather than a way to set some state. As you’ve 
> found, the real setter method tends to work against you here, because you 
> have to figure out what the binding expects with the changed value it thinks 
> it’s setting.
> 
> So, I think a cleaner approach is to leave out the setter method entirely, 
> and use a real action method instead. With no setter, the binding won’t try 
> to update the property, it’ll basically be read-only. When the checkbox is 
> clicked, the action method is still invoked — it’s a NSButton, after all. All 
> the action method has to do is retrieve the current global state via the 
> getter, then set the individual states needed to flip it, sandwiched between 
> one pair of will/didChange calls for the key “globalChannelEnableState”.
> 
> You don’t need to dispatch anything to a later iteration of the main event 
> loop. (Even in your current code — the setter will automatically generate the 
> KVO notification, so doing it again later is redundant.)
> 


___

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

Mixed-state checkboxes

2016-07-08 Thread Jonathan Taylor
Hi all,

I'm trying to work out the correct way to handle a mixed-state checkbox 
(NSButton checkbox with allowsMixedState=YES), bound to a property on my 
controller. I am intending it to serve as an "applies to all" type control at 
the head of a column of checkboxes - so if other checkboxes in the column are 
toggled, it will display a state of on (if all in column are on), off (if all 
are off), or mixed if there is a mixture of states in the column. 

My property has no backing variable, but a manually-implemented getter and 
setter. I am happy with how the getter is working - it scans the column and 
returns the appropriate state. What I am not sure about is how to handle the 
setter.

It seems that allowsMixedState makes it possible to *present* the mixed state, 
but also means that the user can click through the three states in order. What 
I believe the normal interface would be in my situation is for a user click on 
a box in on (or off) state to switch it to off (or on), and a click on mixed 
state puts it to either on or off (not sure which). What I would not expect is 
for a click when in off state to put it into MIXED state. In this interface (if 
I have described it clearly!) it makes no sense for the user to actively put 
the checkbox into mixed state.

So... my question is how to implement the correct behaviour? 

1. It would be great if there was a flag I could set that says "behave like I 
want", but I can't see one!

2. Failing that, I believe what I need to do is to spot the setter being called 
with a value of -1 (mixed), and overrule that. However, I haven't found a way 
of doing that that "feels right" - all successful approaches feel like a hack 
rather than the right way of doing it. My setter code currently looks like this:

-(void)setGlobalChannelEnableState:(NSInteger)state
{
if (state == -1)
{
#if 0
// Checkbox remains in '-' state if I use this code
[self willChangeValueForKey:@"globalChannelEnableState"];
state = 1;
[self didChangeValueForKey:@"globalChannelEnableState"];
#elif 1
// Works. Schedule another call in a moment, to update the 
value to 'on'
dispatch_async(dispatch_get_main_queue(), ^{ 
self.globalChannelEnableState = 1; });
return;
#else
// Also works. Change the input state and fall through to the 
code that does the actual updating (below)
state = 1;
dispatch_async(dispatch_get_main_queue(),
   ^{
   [self 
willChangeValueForKey:@"globalChannelEnableState"];
   [self 
didChangeValueForKey:@"globalChannelEnableState"];
   });
#endif
}

// Update state for all individual channels [code not shown here]
}


Can anybody comment, and maybe suggest a more elegant way of handling this? For 
brevity, I have not shown the getter code, but remember that there is no 
backing variable and the getter just examines the current program state to 
determine what the correct value is.

Thanks for any comments
Jonny.
___

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: Emailing from a daemon process

2016-07-07 Thread Jonathan Mitchell

> On 7 Jul 2016, at 17:13, Carl Hoefs  wrote:
> 
> I have a daemon app built on Foundation (aka "command line tool") running in 
> the background and I need it to issue a textual email on certain conditions. 
> 
> The solutions for emailing that I've been able to find (NSWorkspace, 
> NSSharingService, LSOpenCFURLRef) all involve launching an email client like 
> Mail.app, which is inappropriate for a backgraound daemon process.
> 
> Is there a way to fire off a simple email from an ObjC Foundation-only app 
> running in the background on OS X 10.10.5 (not Server)? I'm told that ages 
> ago there was a handly class named NSMailDelivery, but it's long gone...


Not sure if this will pass muster. It seems reasonably alive in some forks.

https://github.com/MailCore/MailCore

It is a framework though.

J



___

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

NSTextView pagination

2016-07-07 Thread Jonathan Mitchell
Is there a recommended way to change the content of an NSTextView subclass 
during an NSPrintOperation preview?
My subclass needs to adjust its content depending on the NSPrintInfo page 
orientation.
Drawing into the margin with NSView -drawPageBorderWithSize: is not an 
appropriate solution in this case.

I have tried manipulating the views attributed string content in
- (BOOL)knowsPageRange:(NSRangePointer)range
but this logs CG warnings and can behave unpredictably - presumably because the 
content is getting manipulated at an inappropriate point.
It also doesn’t produce the correct paginated output.

Any ideas?

I could supply a new view that would correspond to the new page orientation (if 
I could get an appropriate   notification) but NSPrintOperation’s -view is 
readonly.

Thanks

Jonathan



___

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: Prioritize my own app's disk access

2016-07-06 Thread Jonathan Taylor
On 6 Jul 2016, at 18:01, Quincey Morris <quinceymor...@rivergatesoftware.com> 
wrote:
> On Jul 6, 2016, at 03:06 , Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
> wrote:
>> 
>> a single lost frame will be fairly catastrophic for the scientific experiment
> 
> If this is genuinely your scenario, then nothing mentioned in this thread is 
> going to satisfy your requirements. It is pure whimsy to expect any 
> prioritization mechanic to ensure that the capture is buffered around random 
> unrelated user interactions with the Mac.

All fair points, but the fact is that in practice it works remarkably well at 
the moment. There is still some spare i/o and cpu capacity, and in practice the 
8GB of ram *does* act as a very effective, and very large, buffer. There is a 
clear indication displayed if a backlog starts building, and even a backlog of 
1000 frames is easily recoverable without loss. 

A colleague had tried to transfer some old data to another machine for analysis 
during an experiment, and it became clear this was causing a backlog to build 
in the live recording. It was no problem just to cancel the Finder copy 
operation, and the live recording recovered and cleared the backlog. My 
question was just intended to explore whether there was something easy I could 
do to make that sort of low-priority background request more likely to work 
without causing conflicts. It sounds like the answer is probably not! (Though I 
have definitely learned some very useful stuff in the process)
___

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: Prioritize my own app's disk access

2016-07-06 Thread Jonathan Taylor
Thanks for your reply Alastair. Definitely interested in thinking about your 
suggestions - some responses below that will hopefully help clarify:

> The first thing to state is that you *can’t* write code of this type with the 
> attitude that “dropping frames is not an option”.  Fundamentally, the problem 
> you have is that if you generate video data faster than it can be saved to 
> disk, there is only so much video data you can buffer up before you start 
> swapping, and if you swap you will be dead in the water --- it will kill 
> performance to the extent that you will not be able to save data as quickly 
> as you could before and the result will be catastrophic, with far more frames 
> dropped than if you simply accepted that there was the possibility the 
> machine you were on was not fast enough and would have to occasionally drop a 
> frame.

I should clarify exactly what I mean here. Under normal circumstances I know 
from measurements that the i/o can keep up with the maximum rate at which 
frames can be coming in. I very rarely see any backlog at all reported, but 
might occasionally see a transient glitch (if CPU load momentarily spikes) of 
the order of 10MB backlog that is soon cleared. With that as the status quo, 
and 8GB of RAM available, something has gone badly, badly wrong if we enter vm 
swap chaos. 

When I say "dropping frames is not an option", what I mean is that a single 
lost frame will be fairly catastrophic for the scientific experiment, and so my 
priorities in order are: (1) ensure the machine specs leave plenty of headroom 
above my actual requirements, (2) try and do anything relatively simple I can 
do to ensure my code is efficient and marks threads/operations/etc as high or 
low priority where possible, (3) identify stuff that the user should avoid 
doing (which looks like it includes transferring data off the machine while a 
recording session is in progress - hence this email thread!), (4) not worry too 
much about what to do when we *have* already ended up with a catastrophic 
backlog (i.e. whether to drop frames or do something else), because at that 
point we have failed in the sense that the scientific experiment will basically 
need to be re-run.

I should also clarify that (in spite of my other email thread running in 
parallel to this) I am not doing any complex encoding of the data being 
streamed to disk - these are just basic TIFF images and metadata. The encoding 
I referred to in my other thread is optional offline processing of 
previously-recorded data.

> The right way to approach this type of real time encoding problem is as 
> follows:
> 
> 1. Use statically allocated buffers (or dynamically allocated once at encoder 
> or program startup).  DO NOT dynamically allocate buffers as you generate 
> data.
> 
> 2. Knowing the rate at which you generate video data, decide on the maximum 
> write latency you need to be able to tolerate.  This (plus a bit as you need 
> some free to encode into) will tell you the total size of buffer(s) you need.

OK.

> 3. *Either*
> 
>   (i)  Allocate a ring buffer of the size required, then interleave encoding 
> and issuing I/O requests.  You should keep track of where the 
> as-yet-unwritten data starts in your buffer, so you know when your encoder is 
> about to hit that point.  Or
> 
>   (ii) Allocate a ring *of* fixed size buffers totalling the size required; 
> start encoding into the first one, then when finished, issue an I/O request 
> for that buffer and continue encoding into the next one.  You should keep 
> track of which buffers are in use, so you can detect when you run out.
> 
> 4. When issuing I/O requests, DO NOT use blocking I/O from the encoder 
> thread.  You want to be able to continue to fetch video from your camera and 
> generate data *while* I/O takes place.  GCD is a good option here, or you 
> could use a separate I/O thread with a semaphore, or any other asynchronous 
> I/O mechanism (e.g. POSIX air, libuv and so on).
> 
> 5. If you find yourself running out of buffers, drop frames until buffer 
> space is available, and display the number of frame drops to the user.  This 
> is *much* better than attempting to use dynamic buffers and then ending up 
> swapping, which is I think what’s happening to you (having read your later 
> e-mails).

I am making good use of GCD here (and like it very much!). There are quite a 
few queues involved, and one is a dedicated disk-writing queue. The main 
CPU-intensive work going on in parallel with this is some realtime image 
analysis, but this is running on a concurrent queue.

Hopefully my detail above explains why I really do not want to drop frames 
and/or use a ring buffer. Effectively I have a buffer pool, but if I exhaust 
the buffer pool then (a) something is going badly wrong, and (b) I prefer to 
expand the buffer pool as a last-ditch attempt to cope with the backlog rather 
than terminating the experiment right then and there.

> Without knowing 

Re: Prioritize my own app's disk access

2016-07-05 Thread Jonathan Taylor
Thanks everyone for your replies on this second question of mine. Some 
responses below:

On 5 Jul 2016, at 18:20, Quincey Morris  
wrote:

> What worries me about the Darwin-level (i.e. Unix-level) API suggestions that 
> others have made is that you don’t know how these interact with Cocoa apps. 
> You didn’t actually say whether your app is a Cocoa app, but if so …

It is indeed a cocoa app.

> I think the best modern approach is to route your CPU and IO usage via GCD. 
> That is, from the point where some callback gives you raw video, use 
> dispatch_async to schedule the processing on a GCD queue, and use the GCD I/O 
> primitives to actually do the I/O.
> That will allow you to specify a quality of service (“user interactive” is 
> the highest), which should interact properly with other apps, e.g. the Finder 
> doing a large copy.
> That should take care of CPU and IO. For memory, I agree with Jens that you 
> should preallocate and reuse memory buffers, rather than re-allocating them, 
> as far as possible.

Interesting. I know and love GCD queues, but have not played with the I/O 
stuff. As far as the quality of service goes, I can't see the APIs for that 
(looking in the 10.9 SDK, at least). Am I looking in the wrong place? Text 
search for variants on "user interactive" haven't brought up anything for me in 
the "dispatch" folder.

If I am honest, I suspect I will probably leave things as-is - the for the same 
pragmatic reasons I mentioned in my other email. Unless and until I have 
problems with i/o throughput when my own app is running unmolested, I think 
I'll probably just reiterate advice to users not to leave large copy operations 
running in the background while also recording to disk! I thought I would ask 
the question just in case there was an easy solution I should know about, but 
it sounds as if (understandably) any solution would be fairly involved and 
require some structural changes to my code. That's not to say that it isn't 
very interesting to broaden my mind and understand better what APIs are out 
there, for the next time...


On 5 Jul 2016, at 17:19, Jens Alfke  wrote:

> In addition to increasing I/O priority, there may be other ways to make your 
> disk writes more efficient. For example you can preallocate space for the 
> file before writing to it. Writing in larger chunks may also help. (Of course 
> you may have tried these already.)

I confess that currently I am using pure cocoa -writeToFile:atomically calls. I 
am fully aware that this is very unlikely to be the best way to do high 
performance IO, but it's great in terms of convenience. Again, I'm afraid (in 
the very specific context of a not-that-widely-distributed program running on 
dedicated computers) my question was fishing for a low-hanging fruit that might 
allow me a quick fix that left my own code as-is but encouraged the Finder to 
play nicely along with my not-entirely-optimal code :-)

> Using wired memory for your buffers is also a good idea, since if any of 
> those buffers get paged out things will really go to hell.

Buffer paging is indeed what eventually brings the program (and machine) to its 
knees if things go *really* badly wrong in terms of a backlog. I'm not seeing 
how this would solve a fundamental problem of i/o bandwidth being inadequate, 
but I can see that this would be a good thing to do in terms of preventing some 
*transient* condition from tipping things from one stable state (streaming to 
disk successfully) to another stable, but disastrous, state (thrashing the disk 
due to paging, meaning the frames can't be saved fast enough, more backlog, 
more thrashing, etc).

> Also, I assume you’ve profiled the code and are confident that it’s being 
> constrained by I/O bandwidth and not CPU time? (It’s possible that I/O 
> requests made by real-time threads get higher priority; I can’t remember if 
> this is the case, as it’s a long time since I’ve had to deal with this sort 
> of stuff.)

Yes. Definitely measured as an i/o bandwidth issue in this case. I am presuming 
(though have not profiled on this level of detail) that the problem is 
primarily one of seek times on a magnetic disk - a Finder copy going on in the 
background is competing with my own writes in terms of where the disk head 
needs to be...
___

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: Property synthesis trouble - 32 vs 64 bit builds

2016-07-05 Thread Jonathan Taylor
On 5 Jul 2016, at 22:22, "Gary L. Wade"  wrote:
> You might need to write some lower level stuff, but some of the things in 
> there can be done, albeit differently. Apple knows I've submitted a number of 
> bugs and incident reports to get codecs supported in later frameworks. Do the 
> same. It may happen.


... ah, and I've just seen this reply from Gary as well. That's good to know - 
maybe I should take a fresh look if I do commit to the switch to a 64-bit build.
___

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: Property synthesis trouble - 32 vs 64 bit builds

2016-07-05 Thread Jonathan Taylor
>> Quicktime.
> 
> Oh, you poor thing. That’s one nasty API. (Actually dozens of nasty APIs.) O_o

Yep. I rely on code that I worked out years ago, with the help of examples on 
the internet, and I do my best to leave that code untouched!

>> My code has been 32-bit only since I first wrote it, because I make use of 
>> the APIs in QuickTime/ImageCompression.h for encoding movies. It's my 
>> understanding (as of last time I checked) that no equivalent functionality 
>> is available in the newer APIs.
> 
> AVFoundation is supposed to be the replacement for QuickTime, and definitely 
> supports video encoding. I’ve only used it for audio, though, so I don’t know 
> the details of its video support.

Unless it has been enhanced, I think the support for proper compression was 
lacking, and as a result any generated movie files would be enormous.

___

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: Property synthesis trouble - 32 vs 64 bit builds

2016-07-05 Thread Jonathan Taylor
Thanks everyone for your replies - some responses below:

On 5 Jul 2016, at 20:55, Greg Parker  wrote:
> A synthesized property must use one of the following types of storage:
> 1. An ivar in that class that @synthesize creates.
> 2. An ivar in that class that you defined yourself.
> 
> @synthesize on 32-bit macOS doesn't support #1. The problem is that 32-bit 
> macOS doesn't support non-fragile ivars. Allowing @synthesize to create ivars 
> would make it too easy to accidentally change ivar layout and break 
> compatibility.
> 
> No platform allows @synthesize to bind to a superclass ivar. That would make 
> it too easy to accidentally bind to an unrelated superclass ivar when you 
> really wanted to create a new ivar.

That last statement is a surprise to me. I had believed that the 32-bit code I 
posted was doing just that - MutableSettings binding its property to the ivar 
in ImmutableSettings. Certainly it's not clear to me how that statement *and* 
your statement that #1 is not supported on 32-bit could both be true (there is 
no backing ivar that I declare in the mutable subclass). I also ~think~ the 
code is working correctly on a 32-bit platform (and has been for several years).

I'm not meaning to be argumentative, just trying to get my head around this :-) 
  

On 5 Jul 2016, at 18:12, Quincey Morris  
wrote:
> I’d recommend a different approach, especially if there’s no behavior for the 
> property other than getting or setting an instance variable (which I assume, 
> because you’re trying to use synthesis):
> [...]
> It may sound weird to make the property (internally) settable in an immutable 
> class, but the instance variable is always modifiable in the superclass 
> anyway, so it’s kinda the same thing. Having a private setter there doesn’t 
> really change anything.

Interesting. It does indeed sound weird, but I agree that it shouldn't actually 
be any different to what I'm currently doing. I might just give that a go!

Does this approach have any specific advantages compared to the approach 
suggested by Keary (i.e. basically don't do any synthesis, and just write a 
getter in the base class and a setter in the subclass)?

> Side note:
> 
> Why are you even supporting 32-bit architectures on the Mac? The only good 
> reason I can think of is if you must still update users running OS X 10.5. 
> Users of 10.6.8 and above can (and should) use 64-bit versions of apps.

Quicktime. My code has been 32-bit only since I first wrote it, because I make 
use of the APIs in QuickTime/ImageCompression.h for encoding movies. It's my 
understanding (as of last time I checked) that no equivalent functionality is 
available in the newer APIs. That, plus a big dose of "if it ain't broke, don't 
fix it", as a scientist for whom this Cocoa application of mine is a very 
helpful tool for me and my colleagues, but is just a means to an end rather 
than a product in its own right.

I have only now started looking at 64 bit (knowing I am losing the quicktime 
functionality) because I wanted to look at interfacing with libraries that are 
64-bit only.
___

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: Property synthesis trouble - 32 vs 64 bit builds

2016-07-05 Thread Jonathan Taylor
Thanks for that information - that’s very helpful. It sounds from what you are 
saying as if there is nothing wrong with me redefining the *property* in the 
subclass (as read-write), but that it’s just the synthesis itself that is the 
problem? Assuming that is the case, I can easily(*) rectify that by writing 
explicit setters/getters, so I will do that.

(*) there are rather a lot of these properties in the actual original code, but 
it just involves a lot of typing!


On 5 Jul 2016, at 16:12, Keary Suska <cocoa-...@esoteritech.com> wrote:

> 
>> On Jul 5, 2016, at 5:36 AM, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
>> wrote:
>> 
>> I have a problem with property synthesis in my code, which I hope somebody 
>> can advise on. I find I have to write different property synthesis code for 
>> 32- or 64-bit builds in order to avoid compiler errors.
>> 
>> A minimal demonstration of the problem can be found below - build as part of 
>> a fresh project on Xcode 5 or 6, with ARC disabled. It surprises me that I 
>> have to write different synthesis code for 32- or 64-bit builds - and this 
>> then makes me worry that I am doing something more fundamentally wrong. Can 
>> anyone comment (or explain)?
>> 
>> [I appreciate that this code may be old-fashioned in style - I am not even 
>> sure what is or is not the recommended style these days. It seems to work 
>> though - and, importantly, as far as I can tell the synthesized property 
>> myFlag on MutableSettings *does* map to the same backing variable, even on a 
>> 64-bit build where I am not able to specify the backing variable in the 
>> synthesis statement]
> 
> 32 vs 64 is likely coincidental, and probably has more to do with compiler 
> differences. I.e., at that time, there were additional compiler “features” 
> for 64 bit vs 32 bit. So my thought is that what you are doing is wrong in 
> both cases, but you are simply getting different compiler errors.
> 
> The essential issue I believe is that you cannot re-synthesize in a subclass. 
> You will have to specify the setter explicitly. The issue in the second 
> (64-bit) case is that when you specify @synthesize with an instance variable 
> you are specifying a *new* instance variable on that class, but the compiler 
> correctly warns you that that instance variable has already been defined in 
> the superclass and therefore cannot also be defined in the subclass. The 32 
> bit compiler seems to be letting you get away with this error, but it could 
> have horrible unintended consequences.

___

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: Prioritize my own app's disk access

2016-07-05 Thread Jonathan Taylor
Thanks Alastair. Mark Allan’s email set me off reading things in that area, and 
I am indeed reading the man page for setiopolicy_np at this very moment!

Certainly sounds like the API I am looking for although, as you say, it’s not 
clear where the “default” policy fits into the hierarchy. The man page states 
that [IOPOL_IMPORTANT] "is the default I/O policy for new threads”, and so if 
true then that would suggest that all a program can do is DOWNgrade its 
priority. However, the man page is evidently not entirely correct, based on the 
result you got, so who knows!

I also wonder what priority the Finder would use for copying a folder. I might 
hope it would set itself to STANDARD or THROTTLE; if it does do that, then that 
would suggest that even this is not proving enough to prevent my code getting 
backlogged…


On 5 Jul 2016, at 16:34, Alastair Houghton <alast...@alastairs-place.net> wrote:

> On 5 Jul 2016, at 13:36, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
> wrote:
>> 
>> This is a long shot, but I thought I would ask in case an API exists to do 
>> what I want. One of the roles of my code is to record video to disk as it is 
>> received from a camera. A magnetic hard disk can normally keep up with this, 
>> but if the user is also doing other things on the computer (e.g. long file 
>> copy in the Finder) then we are unable to keep up, and accumulate an 
>> ever-increasing backlog of frames waiting to be saved. This eventually leads 
>> to running out of memory, thrashing, and an unresponsive computer. Dropping 
>> frames is not an option. In this case, the computer is a dedicated 
>> workstation running my code, so it *is* correct for me to consider my code 
>> to be the number 1 priority on the computer.
>> 
>> What I am wondering is whether there is some way I can communicate this 
>> requirement, to cause other apps such as the finder to get disk access at 
>> lower priority. Or alternatively, a way that I can demand high priority 
>> temporarily, at times when I identify that we have accumulated a save 
>> backlog?
> 
> Take a look at get/setiopolicy_np().  It isn’t clear from the documentation 
> exactly what the default behaviour is; when I tried calling getiopolicy_np() 
> I got IOPOL_DEFAULT, which isn’t even mentioned as a value on the man page, 
> but you may find that setting your thread/process’s IO policy to 
> IOPOL_IMPORTANT solves your problem.


___

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

Prioritize my own app's disk access

2016-07-05 Thread Jonathan Taylor
This is a long shot, but I thought I would ask in case an API exists to do what 
I want. One of the roles of my code is to record video to disk as it is 
received from a camera. A magnetic hard disk can normally keep up with this, 
but if the user is also doing other things on the computer (e.g. long file copy 
in the Finder) then we are unable to keep up, and accumulate an ever-increasing 
backlog of frames waiting to be saved. This eventually leads to running out of 
memory, thrashing, and an unresponsive computer. Dropping frames is not an 
option. In this case, the computer is a dedicated workstation running my code, 
so it *is* correct for me to consider my code to be the number 1 priority on 
the computer.

What I am wondering is whether there is some way I can communicate this 
requirement, to cause other apps such as the finder to get disk access at lower 
priority. Or alternatively, a way that I can demand high priority temporarily, 
at times when I identify that we have accumulated a save backlog?

I can see reasons why this is probably not possible, but I thought I’d ask if 
anyone has any suggestions that might be relevant here.
Thanks for any suggestions
Jonny.
___

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

Property synthesis trouble - 32 vs 64 bit builds

2016-07-05 Thread Jonathan Taylor
Hi all,

I have a problem with property synthesis in my code, which I hope somebody can 
advise on. I find I have to write different property synthesis code for 32- or 
64-bit builds in order to avoid compiler errors.

A minimal demonstration of the problem can be found below - build as part of a 
fresh project on Xcode 5 or 6, with ARC disabled. It surprises me that I have 
to write different synthesis code for 32- or 64-bit builds - and this then 
makes me worry that I am doing something more fundamentally wrong. Can anyone 
comment (or explain)?

[I appreciate that this code may be old-fashioned in style - I am not even sure 
what is or is not the recommended style these days. It seems to work though - 
and, importantly, as far as I can tell the synthesized property myFlag on 
MutableSettings *does* map to the same backing variable, even on a 64-bit build 
where I am not able to specify the backing variable in the synthesis statement]

Cheers
Jonny


@interface ImmutableSettings : NSObject
{
BOOL_myFlag;
}
@property (readonly) BOOL myFlag;
@end

@interface MutableSettings : ImmutableSettings
@property (readwrite) BOOL myFlag;
@end

@implementation ImmutableSettings

-(id)init
{
if (!(self = [super init]))
return nil;
_myFlag = true;
return self;
}
@synthesize myFlag = _myFlag;

@end

@implementation MutableSettings
// This is very odd - I get errors on 64-bit builds if I specify a backing 
variable for synthesis,
// but I get errors on 32-bit builds if I *don't* specify a backing variable!?
#if defined(__x86_64__)
// On 32-bit builds I get an error here:
// "Synthesized property 'myFlag' must either be named the same as a 
compatible instance variable or must explicitly name an instance variable"
@synthesize myFlag;
#else
// On 64-bit builds I get an error here:
// "Property 'myFlag' attempting to use instance variable '_myFlag' 
declared in super class 'ImmutableSettings'"
@synthesize myFlag = _myFlag;
#endif

@end

___

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: NSArrayController - error inserting object at arranged object index N

2016-06-24 Thread Jonathan Mitchell

> On 23 Jun 2016, at 23:03, Quincey Morris 
> <quinceymor...@rivergatesoftware.com> wrote:
> 
> On Jun 23, 2016, at 13:39 , Jonathan Mitchell <li...@mugginsoft.com 
> <mailto:li...@mugginsoft.com>> wrote:
>> 
>> Do you mean something like this?
>> NSMutableArray *proxy = [NSArrayController 
>> mutableArrayValueForKey:@"content"];
> 
> That wasn’t what I had in mind. I meant that you would make the array a 
> property of a real model object, and update *that* property, without 
> referring to the array controller directly at all. If you do a KVO compliant 
> update under those circumstances, the array controller will get a KVO 
> notification and update its internal state automatically. You shouldn’t need 
> to re-filter manually.
> 
Okay. I see what you mean now.
Yes - I think that would work.

The downside would be having to implement the compliant accessor methods in the 
real model object (in my case the array is a constructed property of an 
NSViewController subclass which obtains its array data from a non native Obj-C 
model)
This would be beneficial if the array property was also being observed 
externally.

My usage case scenario is mainly bindings based and so the NSArrayController 
provides an effective and concise means of providing a KVO compliant to-many 
property to the likes of NSTableView etc. I think this is the essence point you 
were making about using NSArrayControllers in code previously. I find them 
hugely useful for UI related bindings. Outside of that their utility is less 
obvious.

Thanks for taking the time and effort to respond to this - i definitely 
improved my knowledge by thinking about your points.
KVO compliance for to-many properties was always something I was a bit wooly 
about and I suspect that many others will be too,
IMHO getting to grips with this is one of the most difficult aspects of AppKit.

J
___

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: unnamed function586 $$ AMDRadeon X4000GLDriver

2016-06-23 Thread Jonathan Mitchell

> On 23 Jun 2016, at 21:39, Ken Thomases  wrote:
> 
> O
> 
> Are there any logs generated from the above call (other than your app's crash 
> log)?  Browse around within Console.app's log list to see.
Had a poke around but nothing significant that I can see.
> 
>>   CIFilter *colorFilter = [CIFilter filterWithName:@"CIColorControls"];
>>   [colorFilter setDefaults];
>>   [colorFilter setValue:image forKey:kCIInputImageKey];
>>   [colorFilter setValue:[NSNumber numberWithFloat:saturationValue]  
>> forKey:kCIInputSaturationKey];
>>   [colorFilter setValue:[NSNumber numberWithFloat:brightnessValue] 
>> forKey:kCIInputBrightnessKey];
>>   [colorFilter setValue:[NSNumber numberWithFloat:contrastValue] 
>> forKey:kCIInputContrastKey];
> 
> Any chance these values are out of valid range?
No. Everything looks sane. The range of arguments passed into the method is 
very small so there isn’t much variation.
> 
>> 
>>   CIImage *filterImage = [colorFilter valueForKey:kCIOutputImageKey];
>> 
>>   [filterImage drawAtPoint:NSZeroPoint // << this is the call site that 
>> eventually aborts
>>   fromRect:bounds
>>  operation:NSCompositeCopy
>>   fraction:alphaValue]; 
> 
> What does it mean to use a potentially non-1.0 fraction for a copy to an 
> as-yet-uninitialized image?  No idea if that might contribute to the problem. 
>  Maybe clearing the image to some background color first would help.
> 
> Also, have you considered using -[CIContext createCGImage:fromRect:] to 
> create the image instead of drawing into a focus-locked NSImage?  To get an 
> NSImage from the CGImage, you can use [[NSImage alloc] initWithCGImage:… 
> size:NSZeroSize].

Thanks for the suggestions I will give them a go.

J


___

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: NSArrayController - error inserting object at arranged object index N

2016-06-23 Thread Jonathan Mitchell

> On 23 Jun 2016, at 17:51, Quincey Morris 
>  wrote:
> 
> 
>> My workaround was to set controller.clearsFilterPredicateOnInsertion == YES 
>> and reset the filterPredicate following -addObject:
>> 
>> It might be possible to subclass NSArrayController …
> 
> There’s no need to work around at all. The correct, straightforward solution 
> is to update the content array (i.e. the unfiltered objects being managed via 
> the array controller) directly in a KVO compliant manner, using 
> ‘mutableArrayValueForKey:’.
> 

Do you mean something like this?

NSMutableArray *proxy = [NSArrayController mutableArrayValueForKey:@"content"];
[proxy addObject:object];
[proxy filterUsingPredicate:self.filterPredicate];

This does work but is very slow even with a small collection (the subclass 
returned is an instance of NSKeyValueSlowMutableArray).
Perhaps NSArrayController does not override all the required KVC  methods for 
the content key?

[self.submissionsArrayController addObject:object];
self.submissionsArrayController.filterPredicate = self.filterPredicate;

The above amounts to the same thing and seems much more performant.

I suppose I could make my NSViewController class KVC compliant for the content 
array but that seems overkill in this case.

Thanks

J


___

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

unnamed function586 $$ AMDRadeon X4000GLDriver

2016-06-23 Thread Jonathan Mitchell
On a rare occasion I encounter the following abort while rendering an image in 
an NSImage category.
The method (shown below) gets called frequently to render resources as 
grayscale.
Looks like the driver has issues but beyond that I am stuck.
Any ideas?

Thread 1 (main-thread)
#0  0x7fff9972ef06 in __pthread_kill ()
#1  0x00010183642d in pthread_kill ()
#2  0x7fff8d3426e7 in abort ()
#3  0x7fff9b3ace5c in gpusGenerateCrashLog ()
#4  0x0001127259dc in 
___lldb_unnamed_function586$$AMDRadeonX4000GLDriver ()
#5  0x7fff9b3ae204 in gpusSubmitDataBuffers ()
#6  0x000112762813 in 
___lldb_unnamed_function1027$$AMDRadeonX4000GLDriver ()
#7  0x000112778d37 in 
___lldb_unnamed_function1175$$AMDRadeonX4000GLDriver ()
#8  0x7fff91a1f22f in glReadPixels_Exec ()
#9  0x7fff91f0ceb9 in CI::GLContext::readback_bitmap(CI::Bitmap*, 
CI::swizzle_info) ()
#10 0x7fff91dd43d9 in CI::image_get_cgimage(CI::Context*, CI::Image*, 
CGRect, CGColorSpace*, CI::PixelFormat) ()
#11 0x7fff91db606a in -[CIContext 
createCGImage:fromRect:format:colorSpace:] ()
#12 0x7fff91db476e in -[CIContext drawImage:inRect:fromRect:] ()
#13 0x7fff9ba09801 in -[CIImage(NSAppKitAdditions) 
drawInRect:fromRect:operation:fraction:] ()
#14 0x7fff9ba09914 in -[CIImage(NSAppKitAdditions) 
drawAtPoint:fromRect:operation:fraction:] ()
#15 0x000100028f47 in -[NSImage(Test) 
bp_grayscaleImageWithAlphaValue:saturationValue:brightnessValue:contrastValue:] 
at 

NSImage category:

- (NSImage *)bp_grayscaleImageWithAlphaValue:(CGFloat)alphaValue
  saturationValue:(CGFloat)saturationValue
  brightnessValue:(CGFloat)brightnessValue
contrastValue:(CGFloat)contrastValue
{
NSSize size = [self size];
NSRect bounds = { NSZeroPoint, size };
NSImage *tintedImage = [[NSImage alloc] initWithSize:size];

[tintedImage lockFocus];

CIImage *image = [CIImage imageWithData:[self TIFFRepresentation]];
   
CIFilter *colorFilter = [CIFilter filterWithName:@"CIColorControls"];
[colorFilter setDefaults];
[colorFilter setValue:image forKey:kCIInputImageKey];
[colorFilter setValue:[NSNumber numberWithFloat:saturationValue]  
forKey:kCIInputSaturationKey];
[colorFilter setValue:[NSNumber numberWithFloat:brightnessValue] 
forKey:kCIInputBrightnessKey];
[colorFilter setValue:[NSNumber numberWithFloat:contrastValue] 
forKey:kCIInputContrastKey];

CIImage *filterImage = [colorFilter valueForKey:kCIOutputImageKey];

[filterImage drawAtPoint:NSZeroPoint // << this is the call site that 
eventually aborts
fromRect:bounds
   operation:NSCompositeCopy
fraction:alphaValue]; 

[tintedImage unlockFocus];

return tintedImage;
}


___

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: NSArrayController - error inserting object at arranged object index N

2016-06-23 Thread Jonathan Mitchell

> On 23 Jun 2016, at 14:27, Jonathan Mitchell <li...@mugginsoft.com> wrote:
> 
> The following raises with NSInternalInconsistencyException when :
> 
> 1. an NSArrayController filter is in place, 
> 2. controller.clearsFilterPredicateOnInsertion = NO
> 3. added content object is rejected by the filter.
> 
> Is this behaviour by design?
> 

It would seem there is some intention here according to the header:

- (void)insertObject:(id)object atArrangedObjectIndex:(NSUInteger)index;// 
inserts into the content objects and the arranged objects (as specified by 
index in the arranged objects) - will raise an exception if the object does not 
match all filters currently applied

-addObject: obviously calls  - insertObject: atArrangedObjectIndex: (the 
exception stack trace agrees)

The logic of this is a bit puzzling though as setting 
controller.clearsFilterPredicateOnInsertion == NO seems to designed to fail.
What’s the point of a filter that raises when it filters?

It is possible to catch the exception raised from -addObject: and proceed.
In some cases this may be acceptable but the object that was to be added won’t 
appear in the NSArrayController content collection which may be an issue if the 
filterPredicate is subsequently changed.

My workaround was to set controller.clearsFilterPredicateOnInsertion == YES and 
reset the filterPredicate following -addObject:

It might be possible to subclass NSArrayController but it might turn into a bit 
of a rabbit hole.

> #import “AppDelegate.h"
> 
> @interface AppDelegate ()
> 
> @property (weak) IBOutlet NSWindow *window;
> @end
> 
> @implementation AppDelegate
> 
> - (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
> 
>NSArrayController *controller = [[NSArrayController alloc] 
> initWithContent:@[@"foo"].mutableCopy];
>controller.filterPredicate = [NSPredicate predicateWithBlock:^BOOL(id  
> _Nonnull evaluatedObject, NSDictionary * _Nullable bindings) {
>return [evaluatedObject isKindOfClass:[NSString class]];
>}];
>controller.clearsFilterPredicateOnInsertion = NO;
>[controller addObject:@"bar"];
>[controller addObject:@1]; // raises
> }
> @end
> ___
> 
> 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/lists%40mugginsoft.com
> 
> This email sent to li...@mugginsoft.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 - error inserting object at arranged object index N

2016-06-23 Thread Jonathan Mitchell
The following raises with NSInternalInconsistencyException when :

1. an NSArrayController filter is in place, 
2. controller.clearsFilterPredicateOnInsertion = NO
3. added content object is rejected by the filter.

Is this behaviour by design?

#import “AppDelegate.h"

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

NSArrayController *controller = [[NSArrayController alloc] 
initWithContent:@[@"foo"].mutableCopy];
controller.filterPredicate = [NSPredicate predicateWithBlock:^BOOL(id  
_Nonnull evaluatedObject, NSDictionary * _Nullable bindings) {
return [evaluatedObject isKindOfClass:[NSString class]];
}];
controller.clearsFilterPredicateOnInsertion = NO;
[controller addObject:@"bar"];
[controller addObject:@1]; // raises
}
@end
___

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: TableView crash with Delegate

2016-06-14 Thread Jonathan Mitchell

> On 14 Jun 2016, at 12:26, Gerriet M. Denkmann  wrote:
> 
> 
> But no problem, as long one keeps in mind (as you recommended) that 
> awakeFromNib “can get called many times”.
> 
You may be experiencing this, as described in docs for view based table views:

NSTableView - (__kindofNSView 

 *)makeViewWithIdentifier:(NSString 

 *)identifier
 owner:(id)owner

This method is usually called by the delegate in 
tableView:viewForTableColumn:row: 
,
 but it can also be overridden to provide custom views for the identifier. Note 
that awakeFromNib 

 is called each time this method is called, which means that awakeFromNib is 
also called on owner, even though the owner is already awake.

This has thrown me for loop in the past - especially when the above note was 
only in the headers.

J

> 
> Kind regards,
> 
> Gerriet.
> 
> 
> ___
> 
> 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/lists%40mugginsoft.com
> 
> This email sent to li...@mugginsoft.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

Tick marks on scroll bars

2016-06-13 Thread Jonathan Taylor
Hi all,

Does anyone know a way of implementing "tick marks" on a scroll bar, in the way 
that Xcode does to mark code lines where there is an error/warning? From 
reading header files, I can't see any obvious built-in API to implement this 
feature, but perhaps somebody knows of a custom class that somebody has written 
to implement this functionality? It's something I would like to use, and would 
do if it was comparatively simple to do so, but it's not crucial enough that it 
would be worth my time to write a custom subclass from scratch to do it I 
suspect (I have no experience of customizing controls, even if to an expert it 
might be comparatively simple!).

Thanks for any suggestions...
Jonny
___

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: Simplest way to generate audio tones?

2016-05-29 Thread Jonathan Hull
Here it is for iOS (I assume that this is low-level enough that it is almost 
the same cross-platform):
https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html#//apple_ref/doc/uid/TP40009767-CH2-SW6

My first thought would be to either create a buffer (as you say) or file with 
the sound you want, and then play that…

Thanks,
Jon

> On May 28, 2016, at 10:44 PM, Graham Cox <graham@bigpond.com> wrote:
> 
> Probably should have mentioned this is Mac, not iOS.
> 
> Yes, there are Audio Units, but they’re not really what I’m after. You can’t 
> simply create a generator audio unit and use it in an app to generate tones 
> (as far as I’m aware) - it has to be part of the whole Core Audio signal 
> chain. I’m looking for a much higher level approach if possible. I’m thinking 
> perhaps AVAudioPlayer might be suitable, as it has an init method that takes 
> an NSData object that is a sound buffer. I can definitely make one filled 
> with sine values, but as usual the documentation lets me down - it states 
> that the buffer must be formatted according to the supported formats listed 
> in "Multimedia Programming Guide”, but I can find no such guide and the 
> mention on the page isn’t a link.
> 
> 
> —Graham
> 
> 
> 
>> On 29 May 2016, at 3:36 PM, Jonathan Hull <jh...@gbis.com> wrote:
>> 
>> This is way out of my area of expertise, but it appears you want AudioUnits:
>> http://www.cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html
>> 
>> Thanks,
>> Jon
>> 
>> 
>>> On May 28, 2016, at 8:24 PM, Graham Cox <graham@bigpond.com> wrote:
>>> 
>>> Hi all,
>>> 
>>> I’m looking for general pointers to the simplest/quickest way to generate 
>>> an audio tone (sine wave) of a given frequency and duration. Most of the 
>>> audio APIs seem concerned with playing samples rather than generating 
>>> tones, so it’s not immediately obvious where to look.
>>> 
>>> —Graham
> 
> 


___

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: Simplest way to generate audio tones?

2016-05-28 Thread Jonathan Hull
This is way out of my area of expertise, but it appears you want AudioUnits:
http://www.cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html

Thanks,
Jon


> On May 28, 2016, at 8:24 PM, Graham Cox  wrote:
> 
> Hi all,
> 
> I’m looking for general pointers to the simplest/quickest way to generate an 
> audio tone (sine wave) of a given frequency and duration. Most of the audio 
> APIs seem concerned with playing samples rather than generating tones, so 
> it’s not immediately obvious where to look.
> 
> —Graham
> 
> 
> 
> ___
> 
> 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/jhull%40gbis.com
> 
> This email sent to jh...@gbis.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: iOS - the joy of observers and NSInternalInconsistancyException for KVO

2016-05-19 Thread Jonathan Mitchell

> On 19 May 2016, at 17:55, Jonathan Mitchell <li...@mugginsoft.com> wrote:
> 
> That way the observed object can get deallocated before the observer.
Should say 
That way the observed object cannot get deallocated before the observer.

J

___

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: iOS - the joy of observers and NSInternalInconsistancyException for KVO

2016-05-19 Thread Jonathan Mitchell

> 
> Is there any safer KVO technique to prevent or detect the dreaded "An 
> instance of xx was deallocated while key value observers were still 
> registered with it"?
> 
I have a ton of observers in NSViewController subclasses.
Generally when I use an observer I make 100% sure I have a strong property 
reference (held by the NSViewController instance) to the observed object.
That way I know that the observed object will live as long as the 
NSViewController.
That way the observed object can get deallocated before the observer.
I then always make sure to remove my observers in NSViewController -dealloc.

If you want the observer to stop observing on command then use a delegate 
pattern or a notification to explicitly request that.

It is a futile task IMHO to dig into the KVO machinery and try and second guess 
it.

Jonathan



___

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: Set font on NSTextView that uses bindings?

2016-05-19 Thread Jonathan Mitchell

> On 19 May 2016, at 04:47, Rick Mann  wrote:
> 
> I seem to be unable to set the font used in an NSTextView that uses bindings 
> to set the text content. The property it's bound to creates a plain NSString 
> (no attributes).
> 
> I've tried setting the font, setting the typing attributes, setting the font 
> on textStorage, all to no avail.
> 
> Any ideas? Thanks.
> 
Try setting the text field to allow rich text.
Or use the attributedString binding to bind your string and use a value 
transformer to add in the required text attributes.
I find that I can get a lot more flexibility from my bindings by building them 
in code.

I use the block based transformer shown below to build ad hoc transformers.
You could do the same thing to do you attributed string conversion.
The beauty about using this block approach is that you can capture any other 
dependencies need for the transformation.
This can great increase the bindings scope.

eg:

BPBlockValueTransformer *blockValueTransformer = [BPBlockValueTransformer 
valueTransformerWithBlock:^id(NSNumber *gender)  {
return [gender integerValue] == BPGenderUnknown ? @NO : @YES;
}];
[self.genderPromptImageView bind:NSHiddenBinding toObject:self 
withKeyPath:@"employee.gender"
 options:@{NSValueTransformerBindingOption: 
blockValueTransformer}];

The transformer class:
=

@interface BPBlockValueTransformer : NSValueTransformer

+ (instancetype)valueTransformerWithBlock:(id(^)(id value))block;
@property (nonatomic,strong) id (^transform)(id value);

@end

@implementation BPBlockValueTransformer

+ (instancetype)valueTransformerWithBlock:(id(^)(id value))block
{
BPBlockValueTransformer *transformer = [[self alloc] init];
transformer.transform = block;

return transformer;
}

+ (Class)transformedValueClass
{
return [NSObject class];
}

- (id)transformedValue:(id)value
{
return self.transform(value);
}

@end

J


___

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: Codesigning pain, god it hurts!

2016-05-18 Thread Jonathan Mitchell

> On 18 May 2016, at 04:29, Quincey Morris 
>  wrote:
> 
> Yes, it’s awful.
> 
I agree. Screwing it up is easy.
I use the following project archive scheme post action script to run a 
Gatekeeper security check on archive builds.
This provides decent confirmation that all is well.

 if [ "${CONFIGURATION}" == "Release" ]; then

# xcode post build build/archive cannot directly return or log error 
conditions but we can:
# 1. put up a dialog
# 2. post a notification
# 3. say someting
# 4. write to the syslog
# 5. write to a file and open the file

# Execute a project folder script.
# Note that Git checkout may mutate the execute permissions
#${PROJECT_DIR}/${PROJECT_NAME}/script.sh

# audible feedback
say "Processing post action script for ${PROJECT_NAME}"

# show avaiable vars - helps a lot when debugging
SHOW_EXPORTS=0
if [ $SHOW_EXPORTS -eq 1 ]; then
OUT_FILE="${HOME}/Desktop/${PROJECT_NAME}-xcode-post-action-exports.txt"
rm "${OUT_FILE}"
export -p > "${OUT_FILE}"
open "${OUT_FILE}"
fi

# make archived app path
APP_PATH="${ARCHIVE_PRODUCTS_PATH}/Applications/${EXECUTABLE_PATH}"

# update syslog
syslog -s -l Error "xcode-post-action APP_PATH = ${APP_PATH}"

# do Gatekeeper security check
spctl -v --assess --type execute "${APP_PATH}"
SPCTL_OUT=$?

# output result
syslog -s -l Error "xcode-post-action spctl result code = $SPCTL_OUT"
if [ $SPCTL_OUT -eq 0 ]; then
say "Gatekeeper security check passed for ${PROJECT_NAME}"
osascript -e 'display notification "Gatekeeper security check passed" 
with title "Archive Security Check"'
else
say "Gatekeeper security check faile for ${PROJECT_NAME}"
osascript -e 'tell app "Xcode" to display dialog "Security failure: 
spctl rejected app and Gatekeeper will too." buttons {"Okay"} default button 
"Okay"'
fi
fi
___

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: ARC [was Protecting against "app nap"]

2016-05-12 Thread Jonathan Taylor
Hi Jens,

Thanks again for your reply. I'm sure this has been done to death over the 
years on the list, but... you would definitely recommend ARC then, would you? 
I've been a bit put off by what seems like regular questions on the list(s) 
about debugging and fixing edge cases where ARC doesn't work. I guess that only 
shows the times when it doesn't work, but it's rather left me thinking that 
it's just the same, but with less explicit indication of what is going on. Is 
that an unfair assessment, in your view?

Best regards,
Jonny.

On 11 May 2016, at 16:10, Jens Alfke <j...@mooseyard.com> wrote:

> 
>> On May 11, 2016, at 2:31 AM, Jonathan Taylor <jonathan.tay...@glasgow.ac.uk> 
>> wrote:
>> 
>> I guess I just found method naming a bit odd (not really referring to an 
>> object at all), and might have expected it to have an ‘alloc/new’ naming 
>> since I’d have thought the API would be almost exclusively used for 
>> activities that continue beyond the calling scope.
> 
> The only methods named +alloc or +new are the core methods on NSObject that 
> instantiate objects. (There’s also -copy and -mutableCopy.) Regular methods 
> don’t use that naming scheme nor return owned references, they just 
> consistently return unowned references. That keeps the rules simpler.
> 
> (And I really recommend using ARC! It saves trouble and eliminates a lot of 
> bugs, like this one.)
> 
> —Jens

___

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

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

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

Re: Protecting against "app nap"

2016-05-11 Thread Jonathan Taylor
Thankyou both for your replies - a couple of replies below:

On 10 May 2016, at 23:33, Jens Alfke  wrote:
>> However, I was a bit surprised to find that I seem to need to explicitly 
>> retain the object I get back [this is non-ARC code…] if I want my request to 
>> remain in effect or even for the object to remain allocated to allow me to 
>> call endActivity at a later point.
> 
> It’s standard Cocoa memory management: when an object is returned to you from 
> a method, you don’t own a reference to it, so it’s not guaranteed to remain 
> valid. Since you’re holding onto the object, in order to call -endActivity 
> later, you must be storing it in a non-local variable, so you need to retain 
> it.

Fair enough. I agree that according to standard memory and naming conventions I 
should be expecting to have to retain the object. I guess I just found method 
naming a bit odd (not really referring to an object at all), and might have 
expected it to have an ‘alloc/new’ naming since I’d have thought the API would 
be almost exclusively used for activities that continue beyond the calling 
scope. Oh well.

>> My question here is what is the most appropriate way of identifying in code 
>> whether this feature is available, to ensure I only set it when it will be 
>> accepted.
> 
> Hm, it’s hard to say, because the declaration of DISPATCH_TIMER_STRICT 
> doesn’t specify what OS versions it’s usable with (via 
> __OSX_AVAILABLE_STARTING or something similar.) You may have to do some 
> research to narrow down when it was added.

OK, will do. Just wasn’t sure if there was a better way to nail it down.

On 10 May 2016, at 18:40, Paul Scott  wrote:
> Did you try clicking “Prevent app nap” in the “Info” inspector for the app?

I’ll be honest, I hadn’t spotted that. Useful to know about (and it looks like 
setting NSAppSleepDisabled in Info.plist should achieve the same thing without 
manual user intervention). However, it looks like beginActivityWithOptions has 
a broader remit than just app nap, so I’ll go with the belt and braces approach 
and do both…

Cheers
Jonny
___

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

Protecting against "app nap"

2016-05-10 Thread Jonathan Taylor
Hi all,

I’m hoping somebody can help me work out how to protect my code against the 
effects of “app nap”. This code is driving a scientific experiment, unattended, 
and it is catastrophic when the OS decides that my timers running at 10Hz 
should only be fired every 10 seconds or so… which it turns out has been 
happening!

I have been calling [[NSProcessInfo processInfo] beginActivityWithOptions:…] 
from -applicationDidFinishLaunching. I know that a blanket declaration like 
this would typically be considered poor practice, but honestly if the program 
is running then the experiment is running and I need the OS not to mess with my 
timings to that extent. Anyway, that seems to help stop the timer weirdness. 
However, I was a bit surprised to find that I seem to need to explicitly retain 
the object I get back [this is non-ARC code…] if I want my request to remain in 
effect or even for the object to remain allocated to allow me to call 
endActivity at a later point. I wasn’t expecting to have to retain it, and 
there’s no explicit mention of that in the headers, so I just wanted to check 
that is to be expected, or whether I may be doing something weirdly wrong.

The other thing I wanted to ask relates to creating a timer using 
dispatch_source_create. I have tried to be flexible where I can in terms of 
providing a leeway for non-critical timers, but others I really want to have 
control over. For these I am specifying DISPATCH_TIMER_STRICT, also in the hope 
of dissuading the OS from trying to be too clever for its own good. I notice 
that using this flag leads to dispatch_source_create failing on 10.8.5, which I 
presume is because the flag is not recognised (or needed) on that OS version. 
My question here is what is the most appropriate way of identifying in code 
whether this feature is available, to ensure I only set it when it will be 
accepted.

Any help much appreciated!
Cheers
Jonny.
___

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: discontiguous bounds ?

2016-05-09 Thread Jonathan Mitchell

> On 9 May 2016, at 08:59, Graham Cox  wrote:
> 
> I’ve done this, based on that code. Yes, it was a bit buggy, but I got it to 
> work. The app it’s a part of still works when compiled with the latest tools 
> and SDK. But yes, you need two separate table views to do this.
> 
I have done something similar - using a separate table view to create a non 
scrolling total row at the bottom of a table view.
NSStackView makes a suitable container for sticking this sort of thing together.
In this case I can bind the table column widths together.

I load the table view form a nib but put the view hierarchy together in code.
In particular I clone the initial NSTableView using 
NSKeyedArchiver/NSKeyedUnarchiver so that I don’t have to try and maintain two 
duplicate NSTableViews in the nib.

J
___

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   4   5   6   7   8   >