Re: using constants from Obj-c in swift
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