• 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: using constants from Obj-c in swift
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: using constants from Obj-c in swift


  • Subject: Re: using constants from Obj-c in swift
  • From: Charles Srstka <email@hidden>
  • Date: Fri, 25 Sep 2015 14:06:19 -0500

> On Sep 25, 2015, at 1:43 PM, Boyd Collier <email@hidden> wrote:
>
> In objective-c programs, there are places where one can write lines like the following:
>
> [scrollview setBorderType:NSNoBorder];
>
> with NSNoBoarder being specified in an enum in NSView.  But enums in swift are a different sort of beast, and I’ve not yet figured out what get the same job done.
> Is there a straightforward way to do this?  (I’m using swift 2 in Xcode 7)

Generally speaking, Objective-C enums get simplified in Swift so that the common prefixes are removed from the name of the constant. You access an enum by typing the enum type name, then a period, then the constant name (in your case, NSBorderType.NoBorder). However, if you have a property or parameter that is defined as that enum type, you can leave the enum type name out, and the compiler will infer it. So, all you have to do is this:

scrollView.borderType = .NoBorder

Charles


_______________________________________________

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: 
 >using constants from Obj-c in swift (From: Boyd Collier <email@hidden>)

  • Prev by Date: using constants from Obj-c in swift
  • Next by Date: Re: using constants from Obj-c in swift
  • Previous by thread: using constants from Obj-c in swift
  • Next by thread: Re: using constants from Obj-c in swift
  • Index(es):
    • Date
    • Thread