• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Dealing with an @available warning
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Dealing with an @available warning


  • Subject: Re: Dealing with an @available warning
  • From: Greg Parker <email@hidden>
  • Date: Tue, 23 Oct 2018 15:16:57 -0700

> On Oct 23, 2018, at 3:01 PM, 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?

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     email@hidden <mailto:email@hidden>     Runtime
Wrangler


_______________________________________________

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

References: 
 >Dealing with an @available warning (From: James Walker <email@hidden>)

  • Prev by Date: Re: Dealing with an @available warning
  • Next by Date: Re: Dealing with an @available warning
  • Previous by thread: Re: Dealing with an @available warning
  • Next by thread: Notarization porcess
  • Index(es):
    • Date
    • Thread