Re: setting tab stops in swift
Re: setting tab stops in swift
- Subject: Re: setting tab stops in swift
- From: Marc Khadpe <email@hidden>
- Date: Thu, 27 Aug 2015 20:49:18 -0400
It looks like your code should be:
let theTabStop: NSTextTab = NSTextTab(type: .LeftTabStopType, location: tabInterval * cnt)
Check the documentation on NSTextTab here
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextTab_Class/#//apple_ref/occ/instm/NSTextTab/initWithType:location: <https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextTab_Class/#//apple_ref/occ/instm/NSTextTab/initWithType:location:>
and NSTextTabType here
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextTab_Class/#//apple_ref/c/tdef/NSTextTabType <https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSTextTab_Class/#//apple_ref/c/tdef/NSTextTabType>
They have the Swift forms of the initializer and the enum that you want.
> On Aug 27, 2015, at 8:32 PM, Boyd Collier <email@hidden> wrote:
>
> I’m in the process of re-writing some obj-c code in swift for OS X and am stumped on how to set tab stops. The relevant obj-c code looks like this:
>
> [paraStyle setTabStops:[NSArray array]];
> for (cnt = 1; cnt <= numStops; cnt++) {
> tabStop = [[NSTextTab alloc] initWithType:NSLeftTabStopType location: tabInterval * (cnt)];
> [paraStyle addTabStop:tabStop];
> [tabStop release];
> }
> [attrs setObject:paraStyle forKey:NSParagraphStyleAttributeName];
> [paraStyle release];
>
> [[textView textStorage] addAttributes:attrs range:NSMakeRange(0, [[[textView textStorage] string] length])];
> [attrs release];
>
> Most of my swift code compiles, but not the line corresponding to tabStop = [[NSTextTab alloc] initWithType:NSLeftTabStopType location: tabInterval * (cnt)];
>
> I’ve tried
> let theTabStop: NSTextTab = NSTextTab(NSLeftTabStopType, loc, (tabInterval * cnt))
>
> but am told that NSLeftTabStopType is an “unresolved identifier”, which I understand has to do with enums being quite different in swift.
> Surely, the correct way to deal with this is relatively simple, but I’ve not yet come up with it. Any help would be greatly appreciated.
>
> Boyd
> _______________________________________________
>
> 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