Date   

Re: dispatch_get_current_queue

bartramf@...
 

Take a look at  `dispatchPrecondition` to test whether code is executing on a specific queue in a pattern like:
 
func foo() {
dispatchPrecondition(condition:  .onQueue(mySpecialQueue))
...
}

Hope it helps.
--
Frederick "Rick" Bartram
bartramf@...
PGP key id: 0x4193BED2  key server: http://pgp.mit.edu


Re: dispatch_get_current_queue

Gerriet M. Denkmann
 

On 6 Sep 2018, at 22:24, James Walker <list2@...> wrote:

On Sep 6, 2018, at 3:30 AM, Gerriet M. Denkmann <g@...> wrote:

macOS 13.6

For debugging purposes I want to test that certain methods do run in the correct queue.

So:
dispatch_queue_t queue = dispatch_get_current_queue();
const char *label = dispatch_queue_get_label(queue);
NSString *qLabel = [NSString stringWithUTF8String: label];

if ( ![ qLabel isEqualToString: supposedLabel ] ) … // error

But Xcode tells me that dispatch_get_current_queue is deprecated.

What to do instead?
Comments in the header dispatch/queue.h suggest using dispatch_assert_queue instead.
Thanks a lot. Exactly what I was looking for.

(Also: The variant dispatch_assert_queue_debug() is compiled out when the preprocessor macro NDEBUG is defined.)

Kind regards,

Gerriet.


Re: dispatch_get_current_queue

James Walker
 

On Sep 6, 2018, at 3:30 AM, Gerriet M. Denkmann <g@...> wrote:

macOS 13.6

For debugging purposes I want to test that certain methods do run in the correct queue.

So:
dispatch_queue_t queue = dispatch_get_current_queue();
const char *label = dispatch_queue_get_label(queue);
NSString *qLabel = [NSString stringWithUTF8String: label];

if ( ![ qLabel isEqualToString: supposedLabel ] ) … // error

But Xcode tells me that dispatch_get_current_queue is deprecated.

What to do instead?
Comments in the header dispatch/queue.h suggest using dispatch_assert_queue instead.


dispatch_get_current_queue

Gerriet M. Denkmann
 

macOS 13.6

For debugging purposes I want to test that certain methods do run in the correct queue.

So:
dispatch_queue_t queue = dispatch_get_current_queue();
const char *label = dispatch_queue_get_label(queue);
NSString *qLabel = [NSString stringWithUTF8String: label];

if ( ![ qLabel isEqualToString: supposedLabel ] ) … // error

But Xcode tells me that dispatch_get_current_queue is deprecated.

What to do instead?

Gerriet.


Re: How to get App Icon

Graham Cox
 

On 30 Aug 2018, at 3:27 pm, Gerriet M. Denkmann <g@...> wrote:

Yes it should. Also: the documentation says, it does. But sadly it does not.

Well, it does.

So if yours does not, rather than go round the houses trying to figure out how to “correct” for that, why not find out why yours isn’t doing what the rest of our apps does do? Something you’re doing is preventing standard behaviour. Don’t do more, do less.

—Graham


Re: How to get App Icon

Quincey Morris
 

On Aug 29, 2018, at 23:07 , Gerriet M. Denkmann <g@...> wrote:

But I stumbled upon:

NSRunningApplication *currentApplication = NSRunningApplication.currentApplication;
NSImage *myAppImage = currentApplication.icon;

Which is exactly what I needed.

Sounds good to me. :)


Re: How to get App Icon

Alex Zavatone
 

Are you using an assets file (xcassets) for your app icon? If you make an icon asset in an xcassets file it should contain a slot for that icon at all sizes.

On Aug 30, 2018, at 1:07 AM, Gerriet M. Denkmann <g@...> wrote:



On 30 Aug 2018, at 12:13, Quincey Morris <quinceymorris@...> wrote:

On Aug 29, 2018, at 20:47 , Gerriet M. Denkmann <g@...> wrote:

There must be a simple answer (which becomes immediately obvious once known) to this.
If you want to get the actual app icon, I think the simplest way is to get the URL for your app bundle,
I failed to find this. Probably missed something obvious.

But I stumbled upon:

NSRunningApplication *currentApplication = NSRunningApplication.currentApplication;
NSImage *myAppImage = currentApplication.icon;

Which is exactly what I needed.

then get the URL resource key for the icon (https://developer.apple.com/documentation/foundation/urlresourcekey/1414697-effectiveiconkey).

There’s also a NSWorkspace method to get the icon for a file.

And — I’ve never tried — you may be able to use NSDataAsset to peek into the asset catalog directly.
Also tried this (and failed miserably):

All these just return nil:
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"AppIcon" ]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"Assets" ]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"Assets.xcassets" ]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"Assets" bundle: NSBundle.mainBundle]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"Assets.xcassets" ]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @“AppIcon" bundle: NSBundle.mainBundle]; // nil

The last one writes the message:
[framework] CoreUI: attempting to lookup a named data 'AppIcon' with a type that is not a data type in the AssertCatalog

Then I gave up.

Kind regards,

Gerriet.




Re: How to get App Icon

Alex Zavatone
 

There also should be a special size for the small alert icon within your app’s icon xcassets file.  


On Aug 30, 2018, at 12:13 AM, Quincey Morris <quinceymorris@...> wrote:

On Aug 29, 2018, at 20:47 , Gerriet M. Denkmann <g@...> wrote:

There must be a simple answer (which becomes immediately obvious once known) to this.

If you want to get the actual app icon, I think the simplest way is to get the URL for your app bundle, then get the URL resource key for the icon (https://developer.apple.com/documentation/foundation/urlresourcekey/1414697-effectiveiconkey).

There’s also a NSWorkspace method to get the icon for a file.

And — I’ve never tried — you may be able to use NSDataAsset to peek into the asset catalog directly.

But I wouldn’t bother. It’s easier to add a separate copy of the actual image to an asset catalog *as an image*, and to use [NSImage imageNamed:] to get it. That puts the resolution/size under your control, and you can customize the image (e.g. sub-badging it with a caution or error icon) if you decide you need to, and it’s one line of code to get.


Re: How to get App Icon

Gerriet M. Denkmann
 

On 30 Aug 2018, at 12:13, Quincey Morris <quinceymorris@...> wrote:

On Aug 29, 2018, at 20:47 , Gerriet M. Denkmann <g@...> wrote:

There must be a simple answer (which becomes immediately obvious once known) to this.
If you want to get the actual app icon, I think the simplest way is to get the URL for your app bundle,
I failed to find this. Probably missed something obvious.

But I stumbled upon:

NSRunningApplication *currentApplication = NSRunningApplication.currentApplication;
NSImage *myAppImage = currentApplication.icon;

Which is exactly what I needed.

then get the URL resource key for the icon (https://developer.apple.com/documentation/foundation/urlresourcekey/1414697-effectiveiconkey).

There’s also a NSWorkspace method to get the icon for a file.

And — I’ve never tried — you may be able to use NSDataAsset to peek into the asset catalog directly.
Also tried this (and failed miserably):

All these just return nil:
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"AppIcon" ]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"Assets" ]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"Assets.xcassets" ]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"Assets" bundle: NSBundle.mainBundle]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @"Assets.xcassets" ]; // nil
//NSDataAsset *ass = [[ NSDataAsset alloc] initWithName: @“AppIcon" bundle: NSBundle.mainBundle]; // nil

The last one writes the message:
[framework] CoreUI: attempting to lookup a named data 'AppIcon' with a type that is not a data type in the AssertCatalog

Then I gave up.

Kind regards,

Gerriet.


Re: How to get App Icon

Gerriet M. Denkmann
 

On 30 Aug 2018, at 12:21, Jon Gotow <gotow@...> wrote:

I think you may be trying too hard. NSAlert should show a badged copy of your application icon if you just leave it set to its defaults (don’t set an icon at all).
Yes it should. Also: the documentation says, it does. But sadly it does not.


- Jon


On Aug 29, 2018, at 9:47 PM, Gerriet M. Denkmann <g@...> wrote:

macOS 13.6

The app has Assets.xccassets/AppIcon and shows a nice icon in the dock.

But an NSAlert just shows a boring alert-triangle.
I want it to display the icon of my app instead.

So I did:
NSImage *myAppImage = [ [NSApplication sharedApplication] applicationIconImage ];
NSLog(@"%s myAppImage: %@", __FUNCTION__, myAppImage);

myAppImage: <NSImage 0x60000007cb40 Size={128, 128} Reps=(
"<NSCGImageSnapshotRep:0x608000461b40 cgImage=<CGImage 0x6080001c3de0>\n\t<<CGColorSpace 0x6000000a04e0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Color LCD)>\n\t\twidth = 256, height = 256, bpc = 8, bpp = 32, row bytes = 1024 \n\t\tkCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little \n\t\tis mask? No, has mask? No, has matte? No, should interpolate? Yes>"
)>

[alert setIcon: myAppImage];

And now I get an even more boring default app image (paper with 2 pencils).
I really want the nice app image as shown in the dock.

There must be a simple answer (which becomes immediately obvious once known) to this.


Gerriet.






Re: How to get App Icon

Jon Gotow
 

I think you may be trying too hard. NSAlert should show a badged copy of your application icon if you just leave it set to its defaults (don't set an icon at all).

- Jon

On Aug 29, 2018, at 9:47 PM, Gerriet M. Denkmann <g@...> wrote:

macOS 13.6

The app has Assets.xccassets/AppIcon and shows a nice icon in the dock.

But an NSAlert just shows a boring alert-triangle.
I want it to display the icon of my app instead.

So I did:
NSImage *myAppImage = [ [NSApplication sharedApplication] applicationIconImage ];
NSLog(@"%s myAppImage: %@", __FUNCTION__, myAppImage);

myAppImage: <NSImage 0x60000007cb40 Size={128, 128} Reps=(
"<NSCGImageSnapshotRep:0x608000461b40 cgImage=<CGImage 0x6080001c3de0>\n\t<<CGColorSpace 0x6000000a04e0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Color LCD)>\n\t\twidth = 256, height = 256, bpc = 8, bpp = 32, row bytes = 1024 \n\t\tkCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little \n\t\tis mask? No, has mask? No, has matte? No, should interpolate? Yes>"
)>

[alert setIcon: myAppImage];

And now I get an even more boring default app image (paper with 2 pencils).
I really want the nice app image as shown in the dock.

There must be a simple answer (which becomes immediately obvious once known) to this.


Gerriet.




Re: How to get App Icon

Quincey Morris
 

On Aug 29, 2018, at 20:47 , Gerriet M. Denkmann <g@...> wrote:

There must be a simple answer (which becomes immediately obvious once known) to this.

If you want to get the actual app icon, I think the simplest way is to get the URL for your app bundle, then get the URL resource key for the icon (https://developer.apple.com/documentation/foundation/urlresourcekey/1414697-effectiveiconkey).

There’s also a NSWorkspace method to get the icon for a file.

And — I’ve never tried — you may be able to use NSDataAsset to peek into the asset catalog directly.

But I wouldn’t bother. It’s easier to add a separate copy of the actual image to an asset catalog *as an image*, and to use [NSImage imageNamed:] to get it. That puts the resolution/size under your control, and you can customize the image (e.g. sub-badging it with a caution or error icon) if you decide you need to, and it’s one line of code to get.


How to get App Icon

Gerriet M. Denkmann
 

macOS 13.6

The app has Assets.xccassets/AppIcon and shows a nice icon in the dock.

But an NSAlert just shows a boring alert-triangle.
I want it to display the icon of my app instead.

So I did:
NSImage *myAppImage = [ [NSApplication sharedApplication] applicationIconImage ];
NSLog(@"%s myAppImage: %@", __FUNCTION__, myAppImage);

myAppImage: <NSImage 0x60000007cb40 Size={128, 128} Reps=(
"<NSCGImageSnapshotRep:0x608000461b40 cgImage=<CGImage 0x6080001c3de0>\n\t<<CGColorSpace 0x6000000a04e0> (kCGColorSpaceICCBased; kCGColorSpaceModelRGB; Color LCD)>\n\t\twidth = 256, height = 256, bpc = 8, bpp = 32, row bytes = 1024 \n\t\tkCGImageAlphaPremultipliedFirst | kCGImageByteOrder32Little \n\t\tis mask? No, has mask? No, has matte? No, should interpolate? Yes>"
)>

[alert setIcon: myAppImage];

And now I get an even more boring default app image (paper with 2 pencils).
I really want the nice app image as shown in the dock.

There must be a simple answer (which becomes immediately obvious once known) to this.


Gerriet.


Custom keyboard with search bar not behaving

Steve Mills
 

I’m implementing a custom keyboard for iOS. It consists a UISearchBar the user can use to filter the “keys” they can use to type. When the search button is used, I call [searchBar resignFirstResponder] give have the search bar give up its capture of input. The insertion point has been and still will be blinking in the document view, yet calling [self.textDocumentProxy insertText:s] no longer inserts text into the document.

I thought this was working earlier in the project development. Any ideas? I see a similar feature working in Google's Gboard. Maybe I need to use a fake search bar so the text input chain never gets disturbed?

Steve via iPhone


Re: Handling a menu item in a modal dialog

James Walker
 

On 8/13/18 6:55 PM, Andy Lee via Groups.Io wrote:
On Aug 13, 2018, at 9:05 PM, James Walker <list2@...> wrote:
By the way, there are other menu items, implemented in the app delegate, that are enabled while the dialog is running.  Seems like there's something special about the Quit item.  Maybe that's related to the fact that Quit isn't in the menu nib, but gets added magically.
I got curious and created a scratch app to fiddle with.  I called [NSApp runModalForWindow:] and was surprised to see that even though the dialog was demonstrably modal (clicking on the window behind it caused a beep), the Quit menu item was enabled.  I'll send you my mini-project off-list in case it helps.

Thanks, that did help.  I think the root of the problem is that my app is not totally a normal Cocoa app.  I am in the process of converting a complex app from Carbon to Cocoa, and though I no longer have any Carbon windows, the overall structure and event handling is still somewhat Carbonated.


Re: Handling a menu item in a modal dialog

Andy Lee
 

On Aug 13, 2018, at 9:05 PM, James Walker <list2@...> wrote:
By the way, there are other menu items, implemented in the app delegate, that are enabled while the dialog is running. Seems like there's something special about the Quit item. Maybe that's related to the fact that Quit isn't in the menu nib, but gets added magically.
I got curious and created a scratch app to fiddle with. I called [NSApp runModalForWindow:] and was surprised to see that even though the dialog was demonstrably modal (clicking on the window behind it caused a beep), the Quit menu item was enabled. I'll send you my mini-project off-list in case it helps.

--Andy


Re: Handling a menu item in a modal dialog

Bill Pitcher
 

"While the app is in that loop, it does not respond to any other events (including mouse, keyboard, or window-close events) unless they are associated with the window. It also does not perform any tasks (such as firing timers) that are not associated with the modal run loop. In other words, this method consumes only enough CPU time to process events and dispatch them to the action methods associated with the modal window.”
Discussion: runModalForWindow

"App-Modal Dialogs
An app-modal dialog prevents the user from doing anything else in the app until the dialog is dismissed.”
https://developer.apple.com/design/human-interface-guidelines/macos/windows-and-views/dialogs/

Consider the
Modeless Dialogs
A modeless dialog is usually referred to as a panel. The user can continue interacting with documents and apps uninterrupted.

cheers
Bill Pitcher
Tutor
Literacy Aotearoa - Dunedin

On 14/08/2018, at 12:06 PM, James Walker <list2@...> wrote:

On 8/13/18 5:04 PM, Bill Pitcher wrote:
Not sure it is possible, modal means just the controls on sheet are actioned. Normally if you’re in a sheet and you want the App to Quit you add a Button that Quits. I think you can give the button the Command-Q short cut.

If the sheet isn’t fully modal then maybe you’re better coming from the other direction and displaying it non-modally and ensuring the menu options that don’t apply are disabled. YMMV.
It's not a sheet, just a window being operated with -[NSApplication runModalForWindow:].

On 14/08/2018, at 11:51 AM, James Walker <list2@...>
wrote:

I'm trying to enable the Quit menu item while a modal dialog is running, is that possible? My window controller implements the terminate: action, and has a validateMenuItem: method, but validateMenuItem: never gets called. The window is main and key, and the only thing preceding the window controller in the responder chain is the window itself, which does not respond to a "terminate:" message. I've checked that [NSApp targetForAction: @selector(terminate:)] returns my window controller. What might I be missing?


Re: Handling a menu item in a modal dialog

James Walker
 

On 8/13/18 6:00 PM, Andy Lee via Groups.Io wrote:
On Aug 13, 2018, at 8:06 PM, James Walker <list2@...> wrote:
It's not a sheet, just a window being operated with -[NSApplication runModalForWindow:].
I forget the tweak to do this -- I think it has something to do with using your own run loop.

I'm pretty sure I've done what you describe.  If I can find how I'll post it here, but maybe the run loop hint will help you find it.

Interesting.  The window does have a little red close button, and once the dialog is closed one can quit normally, so maybe I should just live without it rather than using a custom run loop.

By the way, there are other menu items, implemented in the app delegate, that are enabled while the dialog is running.  Seems like there's something special about the Quit item.  Maybe that's related to the fact that Quit isn't in the menu nib, but gets added magically.


Re: Handling a menu item in a modal dialog

Andy Lee
 

On Aug 13, 2018, at 8:06 PM, James Walker <list2@...> wrote:
It's not a sheet, just a window being operated with -[NSApplication runModalForWindow:].
I forget the tweak to do this -- I think it has something to do with using your own run loop.

I'm pretty sure I've done what you describe. If I can find how I'll post it here, but maybe the run loop hint will help you find it.

--Andy


Re: Handling a menu item in a modal dialog

James Walker
 

On 8/13/18 5:04 PM, Bill Pitcher wrote:
Not sure it is possible, modal means just the controls on sheet are actioned. Normally if you’re in a sheet and you want the App to Quit you add a Button that Quits. I think you can give the button the Command-Q short cut.

If the sheet isn’t fully modal then maybe you’re better coming from the other direction and displaying it non-modally and ensuring the menu options that don’t apply are disabled. YMMV.

It's not a sheet, just a window being operated with -[NSApplication runModalForWindow:].

On 14/08/2018, at 11:51 AM, James Walker <list2@...> wrote:

I'm trying to enable the Quit menu item while a modal dialog is running, is that possible?  My window controller implements the terminate: action, and has a validateMenuItem: method, but validateMenuItem: never gets called.  The window is main and key, and the only thing preceding the window controller in the responder chain is the window itself, which does not respond to a "terminate:" message.  I've checked that [NSApp targetForAction: @selector(terminate:)] returns my window controller.  What might I be missing?


781 - 800 of 1457