Re: Handling of paths through sandbox

2020-02-11 Thread Quincey Morris via Cocoa-dev
On Feb 11, 2020, at 09:00 , Gabriel Zachmann via Cocoa-dev 
 wrote:
> 
> I have a question regarding the proper handling of paths under Catalina,
> some of which go through the Container, some don't.
> 
> More specifically, I get the Pictures folder using this line of code:
> 
>  dir_to_scan = [NSHomeDirectory() stringByAppendingPathComponent: 
> @"Pictures/"]

Well, don’t do that. :)

Instead, use one of the two NSFileManager methods that find the Pictures 
directory for you:

URLsForDirectory:inDomains:
URLForDirectory:inDomain:appropriateForURL:create:error:

(You can specify nil for the “appropriateForURL” parameter.) Specify 
NSPicturesDirectory for the directory parameter, and NSUserDomainMask for the 
domain.

Note that the documentation says you can use URLs in the query’s search scopes, 
so you don’t need to convert to paths at all.

> This gives me a path like
> /Users/zach/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Pictures

> EXCEPT, apparently, Spotlight gives me paths starting with 
> /Users/zach/Pictures !
> (which does make some sense.)

Yes, some of the items in the container, which are named as if they are 
standard directories, are actually symbolic links to the real directories 
outside the container.

> Problem is that I can't just do
> 
>   [ array_with_all_images addObject: [path substringFromIndex: ([dir_to_scan 
> length] + 1)] ];

What is this supposed to be an array of? File names? Partial paths underneath 
~/Pictures? If the latter, why get partial paths at all, why not just make an 
array of URLs?


___

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


Catching keystrokes in my screensaver under Catalina

2020-02-11 Thread Gabriel Zachmann via Cocoa-dev
I used to be able to catch keystrokes in my screensaver under Mojave
by defining my own methods  -keyDown:  and/or  -processKey:

This does not work any more under Catalina, it seems.
My screensaver gets killed (stopped) right away.
Not even 
   -(void)stopAnimation
is called any more!

Does anyone have an idea, how I might be able to capture keystrokes while my 
screensaver is running?
(This used to be one of the unique features of my screensaver.)

I will appreciate very much any kinds of insights , hints, pointers, or 
examples!


Best regards, Gabriel

___

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: Sorting an array

2020-02-11 Thread Gabriel Zachmann via Cocoa-dev
Great!  Thanks a lot.

(Just for the record: it's called sortUsingSelector: )

Best regards, Gabriel

___

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: Sorting an array

2020-02-11 Thread Jens Alfke via Cocoa-dev


> On Feb 11, 2020, at 4:59 AM, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> First of all, what are the advantages/disadvantages of either method?

Sort descriptors are data; selectors are [references to] code. So a sort 
descriptor lets you configure the sorting without having to write any custom 
code, and there's a standard API for it. For this reason they're used by 
NSTableView to represent the column sorting, and by NSArrayController.

If you're hardcoding the sort order, which it looks like you are, then it's 
probably simpler just to go the code route and sort using a selector. (Note 
that there are also sort methods that take an NSComparator, which is just a 
typedef for a block. This is very convenient for custom sorts.

> Second, I was wondering if I could write the second method like this:
> 
>imagefiles_ = [imagefiles_ sortedArrayUsingSelector: 
> @selector(localizedStandardCompare:) ];

That won't work since imageFiles_ is a mutable array, and 
-sortedArrayUsingSelector: returns an immutable array. Use the mutable version, 
-sortArrayUsingSelector:, instead.

—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


Handling of paths through sandbox

2020-02-11 Thread Gabriel Zachmann via Cocoa-dev
I have a question regarding the proper handling of paths under Catalina,
some of which go through the Container, some don't.

More specifically, I get the Pictures folder using this line of code:

  dir_to_scan = [NSHomeDirectory() stringByAppendingPathComponent: @"Pictures/"]

This gives me a path like
/Users/zach/Library/Containers/com.apple.ScreenSaver.Engine.legacyScreenSaver/Data/Pictures

Then, I start a Spotlight query to collect all images in that folder, like so:

query_ = [[NSMetadataQuery alloc] init];
NSPredicate * predicate = [NSPredicate predicateWithFormat: 
@"(kMDItemContentTypeTree = 'public.image') && (kMDItemFSSize > %u) && 
(kMDItemPixelHeight > %u) && (kMDItemPixelWidth > %u)",
excludekB_ * 1024, excludeSize_, 
excludeSize_ ];
[query_ setSearchScopes: [NSArray arrayWithObject: dir_to_scan]];
[query_ setPredicate: predicate];   
[query_ startQuery]; 

(Yes, I have a few images in ~/Pictures)

Then, I collect them, which also works fine.

EXCEPT, apparently, Spotlight gives me paths starting with /Users/zach/Pictures 
!
(which does make some sense.)
Problem is that I can't just do

   [ array_with_all_images addObject: [path substringFromIndex: ([dir_to_scan 
length] + 1)] ];
!
I could, of course, handle the case where dir_to_scan = ~/Pictures specially.

But I am wondering whether or not I need to adopt a more general approach,
i.e., could there be other cases where the dir_to_scan goes through the 
Container,
whereas Spotlight gives me the direct paths?
If so, what would be the correct approach?


Thanks a lot in advance for all insights.
 
Best regards, Gabriel


___

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: Sorting an array

2020-02-11 Thread Sandor Szatmari via Cocoa-dev
Gabriel,


> On Feb 11, 2020, at 10:36, Gabriel Zachmann via Cocoa-dev 
>  wrote:
> 
> I have some trivial questions regarding sorting a simple array of strings.
> 
> I used to use this code:
> 
>NSSortDescriptor *sd = [[NSSortDescriptor alloc] initWithKey: nil 
> ascending: YES];//TODO: raus
>[imagefiles_ sortUsingDescriptors: @[sd] ];

Personally I find it awkward to use a sort descriptor with an explicitly nil 
key.  The API allows it, but it just feels off to me.  Are you restricted to 
using an SDK that doesn’t have the 
-sortedArrayUsingComparator:^NSComparissonResult block parameter?  If so, the 
selector based API is still pretty clean.  Before the block version of the API 
we often wrote our own sort methods and used them as the selectors sorting.  
Way back, we implemented Cocoa NaturalLanguage sorting for a long time like 
this, by wrapping C API in Cocoa.  I mention this just to illustrate that you 
can do a lot this way.

But ultimately the sorting API you choose should depend on the content of the 
array.

Sandor

> 
> where imagefiles_ is an NSMutableArray* .
> 
> Now, in the developer doc
> ( 
> https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Collections/Articles/Arrays.html#//apple_ref/doc/uid/2132-SW5)
>  
> I saw a different method. Following that, I was thinking of sorting my array 
> like this:
> 
>NSArray * sorted_images = [imagefiles_ sortedArrayUsingSelector: 
> @selector(localizedStandardCompare:) ];
>imagefiles_ = [NSMutableArray arrayWithArray: sorted_images];
> 
> First of all, what are the advantages/disadvantages of either method?
> 
> Second, I was wondering if I could write the second method like this:
> 
>imagefiles_ = [imagefiles_ sortedArrayUsingSelector: 
> @selector(localizedStandardCompare:) ];
> 
> 
> Thanks a lot in advance.
> 
> 
> 
> ___
> 
> 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/admin.szatmari.net%40gmail.com
> 
> This email sent to admin.szatmari@gmail.com
___

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

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

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

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


MFI Device Picker not displaying

2020-02-11 Thread Eric E. Dolecki via Cocoa-dev
I have a device with an MFI chip in it, I have my project set up with the
supported external accessory protocol strings, and I want to pull up the
MFI device picker just to prove to myself that my app can see my device.

This code runs, prints to the console, but I get a strange error.

if btManager!.state == .poweredOn {
print("Show MFI device picker.")

  EAAccessoryManager.shared().showBluetoothAccessoryPicker(withNameFilter:
nil) { (error) in
if error != nil {
print(error!.localizedDescription)
switch error! {
case EABluetoothAccessoryPickerError.alreadyConnected:
print("already connected.")
break
default:
break
}
}
}
}

Console:

*Show MFI device picker.*

*A constraint factory method was passed a nil layout anchor.  This is not
allowed, and may cause confusing exceptions. Break on BOOL
_NSLayoutConstraintToNilAnchor(void) to debug.  This will be logged only
once.  This may break in the future.*

I am assuming this is why I see no picker displayed. I am curious why I
might be seeing this. Not exactly sure how to fix it - I do a symbolic
breakpoint the break on _NSLayoutConstraintToNilAnchor (Module: UIKit).
Doesn't break on anything. Change the module to Foundation, it does break.
Seemingly on this line:


*class AppDelegate: UIResponder, UIApplicationDelegate {*

Any insight would be appreciated.
___

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


Sorting an array

2020-02-11 Thread Gabriel Zachmann via Cocoa-dev
I have some trivial questions regarding sorting a simple array of strings.

I used to use this code:

NSSortDescriptor *sd = [[NSSortDescriptor alloc] initWithKey: nil 
ascending: YES];//TODO: raus
[imagefiles_ sortUsingDescriptors: @[sd] ];

where imagefiles_ is an NSMutableArray* .

Now, in the developer doc
( 
https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Collections/Articles/Arrays.html#//apple_ref/doc/uid/2132-SW5)
 
I saw a different method. Following that, I was thinking of sorting my array 
like this:

NSArray * sorted_images = [imagefiles_ sortedArrayUsingSelector: 
@selector(localizedStandardCompare:) ];
imagefiles_ = [NSMutableArray arrayWithArray: sorted_images];

First of all, what are the advantages/disadvantages of either method?

Second, I was wondering if I could write the second method like this:

imagefiles_ = [imagefiles_ sortedArrayUsingSelector: 
@selector(localizedStandardCompare:) ];


Thanks a lot in advance.



___

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


Xcode can't launch System Preferences any more

2020-02-11 Thread Gabriel Zachmann via Cocoa-dev
XCode used to be able to launch SystemPreferences under Mojave. 

In the active scheme used for building, under Run / Info / Executable, I have 
SystemPreferences.app selected. "Launch" is set to "automatically". 
Now, after Xcode has (successfully) built my screensaver, I get this error 
message: 

- - - 
Details Launch error Domain: IDELaunchErrorDomain 
Code: 9 
Recovery Suggestion: There is a problem launching using posix_spawn (error 
code: 2). 
‒
- - - 

Does anyone know what I could do?
Thanks a lot in advance.


Best regards, Gabriel.
___

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