Re: Dealing with an @available warning
Re: Dealing with an @available warning
- Subject: Re: Dealing with an @available warning
- From: Saagar Jha <email@hidden>
- Date: Tue, 23 Oct 2018 15:12:46 -0700
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
> On Oct 23, 2018, at 15:01, James Walker <email@hidden> wrote:
>
> 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 (email@hidden)
>
> 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:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden