Discussion:
Dealing with an @available warning
(too old to reply)
James Walker
2018-10-23 22:01:41 UTC
Permalink
I had some code like this

pInfo.orientation = NSPaperOrientationPortrait;

where pInfo is of type NSPrintInfo*. When compiling with
-Wunguarded-availability, I got a warning saying that
NSPaperOrientationPortrait is only available on macOS 10.9 and later.
So I wanted to change it to:

if (@available( macOS 10.9, * ))
{
pInfo.orientation = NSPaperOrientationPortrait;
}
else
{
pInfo.orientation = NSPortraitOrientation
}

But then I get an error, "assigning to NSPaperOrientation from
incompatible type NSPrintingOrientation". If I fix the error by adding
a typecast to NSPaperOrientation, then I get a warning that
NSPaperOrientation is only available on 10.9 and later. Is there any
way out of this roundabout, other than using a later deployment target?
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.net
Saagar Jha
2018-10-23 22:12:46 UTC
Permalink
What build command are you using? I’m not seeing any warnings with this code, compiled with clang -x objective-c -framework AppKit -Wunguarded-availability -mmacosx-version-min=10.9 - :

#import <AppKit/AppKit.h>

int main() {
NSPrintInfo *info;
if (@available(macOS 10.9, *)) {
info.orientation = NSPaperOrientationPortrait;
} else {
info.orientation = NSPortraitOrientation;
}
}

Regardless, if you really need a fix, you should be able to cast through NSInteger, instead of NSPrintingOperation, as a fallback.

Saagar Jha
Post by James Walker
I had some code like this
pInfo.orientation = NSPaperOrientationPortrait;
{
pInfo.orientation = NSPaperOrientationPortrait;
}
else
{
pInfo.orientation = NSPortraitOrientation
}
But then I get an error, "assigning to NSPaperOrientation from incompatible type NSPrintingOrientation". If I fix the error by adding a typecast to NSPaperOrientation, then I get a warning that NSPaperOrientation is only available on 10.9 and later. Is there any way out of this roundabout, other than using a later deployment target?
_______________________________________________
Please 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/options/cocoa-dev/saagar%40saagarjha.com
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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/gegs%40ml-in.nark
James Walker
2018-10-23 23:02:08 UTC
Permalink
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.net
James Walker
2018-10-24 00:15:35 UTC
Permalink
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.net
Saagar Jha
2018-10-24 00:36:00 UTC
Permalink
Saagar Jha
If you compile with a deployment version of 10.9, I don't know if it even bothers to look at the else clause. Try -mmacosx-version-min=10.8.
Post by Saagar Jha
#import <AppKit/AppKit.h>
int main() {
NSPrintInfo *info;
info.orientation = NSPaperOrientationPortrait;
} else {
info.orientation = NSPortraitOrientation;
}
}
Regardless, if you really need a fix, you should be able to cast through NSInteger, instead of NSPrintingOperation, as a fallback.
I'm not sure what you mean by "cast through NSInteger", but if I say
info.orientation = (NSInteger) NSPortraitOrientation;
then there's an error, "assigning to NSPaperOrientation from incompatible type NSInteger (aka long)”.
I’m not seeing that error at all, even with -Wall -Wextra. What flags are you using?
Post by Saagar Jha
Saagar Jha
Post by James Walker
I had some code like this
pInfo.orientation = NSPaperOrientationPortrait;
{
pInfo.orientation = NSPaperOrientationPortrait;
}
else
{
pInfo.orientation = NSPortraitOrientation
}
But then I get an error, "assigning to NSPaperOrientation from incompatible type NSPrintingOrientation". If I fix the error by adding a typecast to NSPaperOrientation, then I get a warning that NSPaperOrientation is only available on 10.9 and later. Is there any way out of this roundabout, other than using a later deployment target?
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.nark
James Walker
2018-10-24 00:54:43 UTC
Permalink
Post by Saagar Jha
Saagar Jha
Post by Saagar Jha
What build command are you using? I’m not seeing any warnings with
this code, compiled with clang -x objective-c -framework AppKit
If you compile with a deployment version of 10.9, I don't know if it
even bothers to look at the else clause.  Try -mmacosx-version-min=10.8.
Oops, that was a typo. I meant -mmacosx-version-min=10.8. Either way,
@available is checked at runtime, so both cases must be compiled anyways.
Post by Saagar Jha
#import <AppKit/AppKit.h>
int main() {
NSPrintInfo *info;
info.orientation = NSPaperOrientationPortrait;
} else {
info.orientation = NSPortraitOrientation;
}
}
Regardless, if you really need a fix, you should be able to cast
through NSInteger, instead of NSPrintingOperation, as a fallback.
I'm not sure what you mean by "cast through NSInteger", but if I say
info.orientation = (NSInteger) NSPortraitOrientation;
then there's an error, "assigning to NSPaperOrientation from
incompatible type NSInteger (aka long)”.
I’m not seeing that error at all, even with -Wall -Wextra. What flags are you using?
Hmm, it appears to be because I'm using Objective-C++. When I put that
line in a .m file, there was no error.
Post by Saagar Jha
Post by Saagar Jha
Saagar Jha
Post by James Walker
I had some code like this
pInfo.orientation = NSPaperOrientationPortrait;
where pInfo is of type NSPrintInfo*.  When compiling with
-Wunguarded-availability, I got a warning saying that
NSPaperOrientationPortrait is only available on macOS 10.9 and
{
pInfo.orientation = NSPaperOrientationPortrait;
}
else
{
pInfo.orientation = NSPortraitOrientation
}
But then I get an error, "assigning to NSPaperOrientation from
incompatible type NSPrintingOrientation".  If I fix the error by
adding a typecast to NSPaperOrientation, then I get a warning that
NSPaperOrientation is only available on 10.9 and later.  Is there
any way out of this roundabout, other than using a later deployment
target?
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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/gegs%40ml-in.narkive.net
Saagar Jha
2018-10-25 23:05:17 UTC
Permalink
FWIW, I don’t see this in Objective-C++ either.

Saagar Jha
Post by Saagar Jha
Saagar Jha
If you compile with a deployment version of 10.9, I don't know if it even bothers to look at the else clause. Try -mmacosx-version-min=10.8.
Post by Saagar Jha
#import <AppKit/AppKit.h>
int main() {
NSPrintInfo *info;
info.orientation = NSPaperOrientationPortrait;
} else {
info.orientation = NSPortraitOrientation;
}
}
Regardless, if you really need a fix, you should be able to cast through NSInteger, instead of NSPrintingOperation, as a fallback.
I'm not sure what you mean by "cast through NSInteger", but if I say
info.orientation = (NSInteger) NSPortraitOrientation;
then there's an error, "assigning to NSPaperOrientation from incompatible type NSInteger (aka long)”.
I’m not seeing that error at all, even with -Wall -Wextra. What flags are you using?
Hmm, it appears to be because I'm using Objective-C++. When I put that line in a .m file, there was no error.
Post by Saagar Jha
Post by Saagar Jha
Saagar Jha
Post by James Walker
I had some code like this
pInfo.orientation = NSPaperOrientationPortrait;
{
pInfo.orientation = NSPaperOrientationPortrait;
}
else
{
pInfo.orientation = NSPortraitOrientation
}
But then I get an error, "assigning to NSPaperOrientation from incompatible type NSPrintingOrientation". If I fix the error by adding a typecast to NSPaperOrientation, then I get a warning that NSPaperOrientation is only available on 10.9 and later. Is there any way out of this roundabout, other than using a later deployment target?
_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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/gegs%40ml-in.narkive.net

T

Greg Parker
2018-10-23 22:16:57 UTC
Permalink
Post by James Walker
I had some code like this
pInfo.orientation = NSPaperOrientationPortrait;
{
pInfo.orientation = NSPaperOrientationPortrait;
}
else
{
pInfo.orientation = NSPortraitOrientation
}
But then I get an error, "assigning to NSPaperOrientation from incompatible type NSPrintingOrientation". If I fix the error by adding a typecast to NSPaperOrientation, then I get a warning that NSPaperOrientation is only available on 10.9 and later. Is there any way out of this roundabout, other than using a later deployment target?
Dumb answer: use #pragma clang diagnostic to disable the guarded availability check on that line. Something like this:

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunguarded-availability"
pInfo.orientation = (NSPaperOrientation)NSPortraitOrientation;
#pragma clang diagnostic pop

You should file a bug report against AppKit. I'm not sure there is any benefit to marking a plain C enum as unavailable. Use of a new enum would work fine when running on an old OS version.
--
Greg Parker ***@apple.com <mailto:***@apple.com> Runtime Wrangler


_______________________________________________

Cocoa-dev mailing list (Cocoa-***@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/gegs%40ml-in.narkive.net

This email sent to ***@ml-in.narkive.net
Continue reading on narkive:
Loading...