Re: C callbacks with NSNotificationCenter?

2016-09-10 Thread Andreas Falkenhahn
On 08.09.2016 at 00:47 Graham Cox wrote:


>> On 8 Sep 2016, at 3:44 AM, Andreas Falkenhahn  wrote:

>> How can I access "IMPORTANT_DATA_PTR" from within the block above?


> You already did it. Variables are captured from the scope where the
> block is declared and “magically” get referenced within the block.
> So what you’ve written should work.

> Have you tried it?

I didn't try it because I thought that the block wouldn't have access to
variables from the outer scope but apparently that isn't the case. It's
indeed working fine. So just using a block that calls the C function is the
perfect solution to my problem. No need for creating a class and using
selectors, I can just use a block that calls a C function. Nice.

> (You might want to more strongly type your parameters though, void* is a 
> nasty idea).

Well, this was just an example of course and the void* just a placeholder. 

-- 
Best regards,
 Andreas Falkenhahnmailto:andr...@falkenhahn.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

Why doesn't this crash?

2016-09-10 Thread Andreas Falkenhahn
I want my app to run on 10.6 but use 10.7 features where available. Thus I'm
compiling on 10.11 using -mmacosx-version-min=10.6. In particular, I want to
use AVFoundation to play videos on 10.7 and better.

To open a video, I do the following:

AVPlayer *p = [[AVPlayer alloc] initWithURL:url];

I'd expect this code to crash on 10.6 because 10.6 doesn't have AVPlayer.
To my surprise, however, the code doesn't crash and it just returns NULL.
This is fine because then my app will just show a message box informing
the user that the file couldn't be opened and no other AVFoundation APIs
will be accessed.

However, I'm wondering whether it is ok to execute this code on 10.6 without
any safeguard. I thought I'd have to do something like this instead:

if(floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7) {

AVPlayer *p = [[AVPlayer alloc] initWithURL:url];
...

} else {

return NULL;
}
 
Do I have to do this or can I just rely on alloc/init returning NULL for
classes unknown on 10.6?

-- 
Best regards,
 Andreas Falkenhahn  mailto:andr...@falkenhahn.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

Linking against AVKit breaks app on 10.6

2016-09-10 Thread Andreas Falkenhahn
When I link my app against AVKit using

-framework AVKit

it fails to load on 10.6 claiming

dyld: Library not loaded: 
/System/Library/Frameworks/AVKit.framework/Versions/A/AVKit
Referenced from: ...
Reason: image not found
Trace/BPT trap

I thought it was possible to dynamically use newer OS X features if the user is
running a newer version. I want my app to run on 10.6 but use newer features 
where
possible. Thus, I'm compiling and linking using -mmacosx-version-min=10.6.

This seems to work fine for 10.7 frameworks like AV Foundation and Core Media
but it doesn't work for AVKit. Linking against 

-framework AVFoundation -framework CoreMedia

doesn't break compatibility with 10.6 but linking against AVKit does. Is there a
way around this? AFAIR people said that it was possible to use newer OS X 
features
in apps compiled for older systems so I'm wondering why it doesn't work with 
AVKit
here...

-- 
Best regards,
 Andreas Falkenhahn  mailto:andr...@falkenhahn.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: Why doesn't this crash?

2016-09-10 Thread Pascal Bourguignon
It returns nil by feature of Objective-C. 
Referencing the class will translate into a runtime class lookup which will 
return nil. Sending a message to nil  will return nil.

The only caveat is that a class with that name could be provided by a library 
and invalidate your code. But I would say improbable, and I would count on it. 
Just be careful to never dereference those nils!

-- 
__Pascal Bourguignon__

> Le 10 sept. 2016 à 13:39, Andreas Falkenhahn  a écrit 
> :
> 
> I want my app to run on 10.6 but use 10.7 features where available. Thus I'm
> compiling on 10.11 using -mmacosx-version-min=10.6. In particular, I want to
> use AVFoundation to play videos on 10.7 and better.
> 
> To open a video, I do the following:
> 
>AVPlayer *p = [[AVPlayer alloc] initWithURL:url];
> 
> I'd expect this code to crash on 10.6 because 10.6 doesn't have AVPlayer.
> To my surprise, however, the code doesn't crash and it just returns NULL.
> This is fine because then my app will just show a message box informing
> the user that the file couldn't be opened and no other AVFoundation APIs
> will be accessed.
> 
> However, I'm wondering whether it is ok to execute this code on 10.6 without
> any safeguard. I thought I'd have to do something like this instead:
> 
>if(floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_7) {
> 
>AVPlayer *p = [[AVPlayer alloc] initWithURL:url];
>...
> 
>} else {
> 
>return NULL;
>}
> 
> Do I have to do this or can I just rely on alloc/init returning NULL for
> classes unknown on 10.6?
> 
> -- 
> Best regards,
> Andreas Falkenhahn  mailto:andr...@falkenhahn.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/pjb%40informatimago.com
> 
> This email sent to p...@informatimago.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

Progress Indicator

2016-09-10 Thread Peter Hudson
Hi All

I have a simple view with a progress indicator in it.
Simple circular type - indeterminate.

I start it with   [progInd  startAnimation:self];
I end it with[progInd  stopAnimation:self];

After a couple of years of running just fine, it now simply does not appear 
onscreen at all - or run.

I’ve tried removing the object from the view and dropping in a new one - and 
reconnecting.
Everything looks fine - it appears to be connected up correctly.

Any suggestions 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/archive%40mail-archive.com

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

Re: Why doesn't this crash?

2016-09-10 Thread Jens Alfke

> On Sep 10, 2016, at 5:16 AM, Pascal Bourguignon  
> wrote:
> 
> It returns nil by feature of Objective-C. 
> Referencing the class will translate into a runtime class lookup which will 
> return nil. Sending a message to nil  will return nil.

Well, not exactly. If you reference the class name as a literal, as in 
[AVPlayer alloc], that does result in a link-time reference to a symbol 
.objc_class_name_AVPlayer. If that class doesn’t exist when the app is being 
loaded, it will fail to launch with a fatal dyld error.

Things would work as you describe if the class were being looked up by name, 
like
[[NSClassFromString(@“AVPlayer”) alloc] init]
since NSClassFromString would return Nil.

Andreas, I think the reason your code doesn’t crash is that the linker is 
importing AVFoundation as a weak library (probably because of the minimum OS 
version you declared at build time.) That means that if the library doesn’t 
exist at load-time, all of its symbols will point to null. Then things are as 
Pascal describes.

—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: Progress Indicator

2016-09-10 Thread Peter Hudson
Hi Michael

Thanks for the suggestion - but I had already checked this.

Peter




> On 10 Sep 2016, at 16:43, Michael Mayer  wrote:
> 
> Peter -
> 
> My apologies for the obvious suggestion but, did you make sure it is plugged 
> in?
> progInd.hidden = false  (automatically converted to swift)
> 
> Regards, Michael
> 
> 
> 
> On Sep 10, 2016, at 10:38 AM, Peter Hudson  > wrote:
> 
> Hi All
> 
> I have a simple view with a progress indicator in it.
> Simple circular type - indeterminate.
> 
> I start it with   [progInd  startAnimation:self];
> I end it with[progInd  stopAnimation:self];
> 
> After a couple of years of running just fine, it now simply does not appear 
> onscreen at all - or run.
> 
> I’ve tried removing the object from the view and dropping in a new one - and 
> reconnecting.
> Everything looks fine - it appears to be connected up correctly.
> 
> Any suggestions 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/m.mayer6%40gmail.com 
> 
> 
> This email sent to m.may...@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

Re: Progress Indicator

2016-09-10 Thread Steve Mills
> On Sep 10, 2016, at 09:38, Peter Hudson  wrote:
> 
> I have a simple view with a progress indicator in it.
> Simple circular type - indeterminate.
> 
> I start it with   [progInd  startAnimation:self];
> I end it with[progInd  stopAnimation:self];
> 
> After a couple of years of running just fine, it now simply does not appear 
> onscreen at all - or run.
> 
> I’ve tried removing the object from the view and dropping in a new one - and 
> reconnecting.
> Everything looks fine - it appears to be connected up correctly.

Is it set to animate via thread or the regular way? If regular, has something 
changed so the event loop is not getting enough time to animate? I'd try 
subclassing it, override a few methods, and see if things are being called, 
like drawRect.

Steve via iPad


___

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

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

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

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

Progress Indicator

2016-09-10 Thread Peter Hudson
Hi Steve

I think your suggestion is going the right way.

I have ( unwittingly ) moved the processing about and the calls to the progress 
indicator are now happening while the thread is blocked for processing ( and 
non of the interface is being updated until the processing is done )

Next question, I guess, is how do I get out of this corner ?

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/archive%40mail-archive.com

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

Re: Progress Indicator

2016-09-10 Thread Steve Mills
> On Sep 10, 2016, at 10:16, Peter Hudson  wrote:
> 
> Hi Steve
> 
> I think your suggestion is going the right way.
> 
> I have ( unwittingly ) moved the processing about and the calls to the 
> progress indicator are now happening while the thread is blocked for 
> processing ( and non of the interface is being updated until the processing 
> is done )
> 
> Next question, I guess, is how do I get out of this corner ?

Chance it to threaded in IB.

Steve via iPad


___

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

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

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

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

Re: Progress Indicator

2016-09-10 Thread Alex Zavatone
Is it that the animation thread is being blocked or the thread you have to 
dispatch the request to start?

On Sep 10, 2016, at 10:16 AM, Peter Hudson wrote:

> Hi Steve
> 
> I think your suggestion is going the right way.
> 
> I have ( unwittingly ) moved the processing about and the calls to the 
> progress indicator are now happening while the thread is blocked for 
> processing ( and non of the interface is being updated until the processing 
> is done )
> 
> Next question, I guess, is how do I get out of this corner ?
> 
> 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/zav%40mac.com
> 
> This email sent to z...@mac.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

XIP archive won't extract for my users

2016-09-10 Thread SevenBits
Apologies if this wasn't posted to the right list.

Following the recent trend by Apple, I have begun packaging my app
downloads as an "XIP" file. Several of my users are reporting that, upon
downloading the file, they can't extract it because "the archive doesn't
come from Apple". Some users, though, have reported alternative apps like
The Unarchiver from the MAS works for them.

Well, sure, it's not from Apple, but it's signed by my
developer certificate, and so I'd expect everything to work; it did during
my testing.

You can see a user's bug report along with a screenshot here:
https://github.com/SevenBits/Mac-Linux-USB-Loader/issues/135

Any thoughts on this issue?
___

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: XIP archive won't extract for my users

2016-09-10 Thread Quincey Morris
On Sep 10, 2016, at 16:42 , SevenBits  wrote:
> 
> Well, sure, it's not from Apple, but it's signed by my
> developer certificate, and so I'd expect everything to work; it did during
> my testing.

It’s not clear what certificate you used. You could have used:

1. A MAS certificate.

2. A Developer ID certificate.

3. A personal developer certificate.

Of those, #2 is the only one I’d expect to work.

___

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: XIP archive won't extract for my users

2016-09-10 Thread Shane Stanley
On 11 Sep 2016, at 9:42 AM, SevenBits  wrote:
> 
> Following the recent trend by Apple, I have begun packaging my app
> downloads as an "XIP" file. Several of my users are reporting that, upon
> downloading the file, they can't extract it because "the archive doesn't
> come from Apple". 

From the latest update to 'macOS Code Signing In Depth':

> Important: Starting with macOS Sierra, only XIP archives signed by Apple will 
> be expanded. Developers who have been using XIP archives will need to move to 
> using signed installer packages or disk images.


-- 
Shane Stanley 
, 



___

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

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

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

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

Re: Why doesn't this crash?

2016-09-10 Thread Julian
Also worthy to note is that the +class method is implemented in a smart way
and does more or less what objc_getClass does, and will never crash. It's
the recommended general way to see if the class is available. (Jens correct
me if I'm wrong, no doubt you know more here than I do!)

On Sep 10, 2016 7:41 AM, "Jens Alfke"  wrote:

>
> > On Sep 10, 2016, at 5:16 AM, Pascal Bourguignon 
> wrote:
> >
> > It returns nil by feature of Objective-C.
> > Referencing the class will translate into a runtime class lookup which
> will return nil. Sending a message to nil  will return nil.
>
> Well, not exactly. If you reference the class name as a literal, as in
> [AVPlayer alloc], that does result in a link-time reference to a symbol
> .objc_class_name_AVPlayer. If that class doesn’t exist when the app is
> being loaded, it will fail to launch with a fatal dyld error.
>
> Things would work as you describe if the class were being looked up by
> name, like
> [[NSClassFromString(@“AVPlayer”) alloc] init]
> since NSClassFromString would return Nil.
>
> Andreas, I think the reason your code doesn’t crash is that the linker is
> importing AVFoundation as a weak library (probably because of the minimum
> OS version you declared at build time.) That means that if the library
> doesn’t exist at load-time, all of its symbols will point to null. Then
> things are as Pascal describes.
>
> —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/jpellico%40gmail.com
>
> This email sent to jpell...@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

referencing a Swift Dictionary from Objective-C

2016-09-10 Thread Gavin Eadie
I’m moving some code from Obj-C to Swift and, from time to time, I open a gap I 
cannot see across.  This is one, and I’d love some assistance.

I converted a pile of utility Obj-C code that included a class method of the 
form on the rhs of:

   xxx = [UIColor colorFromName:@"aliceblue"]

In the new Swift replacement of the utility code, I added a global constant 
Dictionary of the form:

   public let colorLookup = [
  "aliceblue" : UIColor.init(colorLiteralRed:0.0, green:0.5, blue:1.0, 
alpha:1.0),
  …
   ]

and changed the Obj-C call to

   xxx = colorLookup[@"aliceblue"]


The Obj-C compiler complains that the subscript is not numeric.  It also 
appears to not be able to resolve the global constant "colorLookup" (which 
probably explains the error in the previous sentence).  I notice that 
"colorLookup" doesn’t appear in "Utilities-Swift.h" ..

There are other (and better) ways I could code this, but I’m curious why 
"colorLookup" is invisible to Objective-C .. Thanks, Gavin
___

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: referencing a Swift Dictionary from Objective-C

2016-09-10 Thread Charles Srstka
> On Sep 11, 2016, at 12:16 AM, Gavin Eadie  wrote:
> 
> I’m moving some code from Obj-C to Swift and, from time to time, I open a gap 
> I cannot see across.  This is one, and I’d love some assistance.
> 
> I converted a pile of utility Obj-C code that included a class method of the 
> form on the rhs of:
> 
>   xxx = [UIColor colorFromName:@"aliceblue"]
> 
> In the new Swift replacement of the utility code, I added a global constant 
> Dictionary of the form:
> 
>   public let colorLookup = [
>  "aliceblue" : UIColor.init(colorLiteralRed:0.0, green:0.5, blue:1.0, 
> alpha:1.0),
>  …
>   ]
> 
> and changed the Obj-C call to
> 
>   xxx = colorLookup[@"aliceblue"]
> 
> 
> The Obj-C compiler complains that the subscript is not numeric.  It also 
> appears to not be able to resolve the global constant "colorLookup" (which 
> probably explains the error in the previous sentence).  I notice that 
> "colorLookup" doesn’t appear in "Utilities-Swift.h" ..
> 
> There are other (and better) ways I could code this, but I’m curious why 
> "colorLookup" is invisible to Objective-C .. Thanks, Gavin

Wrap the variable in an Objective-C class and it should be fine:

public class Constants: NSObject {
public let colorLookup: [String : UIColor] = ...
}

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