• 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: How to convert String.Index to UInt?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to convert String.Index to UInt?


  • Subject: Re: How to convert String.Index to UInt?
  • From: "Stephen J. Butler" <email@hidden>
  • Date: Sat, 16 Aug 2014 04:25:03 -0500

Try:

import Cocoa

let s = "hallo\there"
let aas = NSMutableAttributedString(string: s, attributes: nil)

if let rangeOfTab = s.rangeOfString( "\t" ) {
    let colour = NSColor.grayColor()
    let length = distance(s.startIndex, rangeOfTab.startIndex)
    let aRange = NSRange(location: 0, length: length)
    aas.addAttribute(NSForegroundColorAttributeName, value: colour, range:
aRange)
}

Maybe read more:

http://oleb.net/blog/2014/07/swift-strings/



On Sat, Aug 16, 2014 at 3:30 AM, Gerriet M. Denkmann <email@hidden>
wrote:

> import Cocoa
>
> let s = "hallo\there"
> let aas = NSMutableAttributedString( string: s, attributes: nil )
>
> let rangeOfTab = s.rangeOfString( "\t" )
> if rangeOfTab != nil
> {
>         let colour = NSColor.grayColor()
>         let locationOfTab = rangeOfTab!.startIndex
>         let aRange = NSRange( location: 0, length: locationOfTab ) <--
> error: 'String.Index' is not convertible to 'Int'
>         aas.addAttribute( NSForegroundColorAttributeName, value: colour,
> range: aRange )
> }
>
> How can I convert a String.Index into an UInt (or Int or whatever)?
>
> Gerriet.
>
>
> _______________________________________________
>
> 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


  • Follow-Ups:
    • Re: How to convert String.Index to UInt?
      • From: "Gerriet M. Denkmann" <email@hidden>
    • Re: How to convert String.Index to UInt?
      • From: "Gerriet M. Denkmann" <email@hidden>
References: 
 >How to convert String.Index to UInt? (From: "Gerriet M. Denkmann" <email@hidden>)

  • Prev by Date: Re: How to convert String.Index to UInt?
  • Next by Date: Re: How to convert String.Index to UInt?
  • Previous by thread: Re: How to convert String.Index to UInt?
  • Next by thread: Re: How to convert String.Index to UInt?
  • Index(es):
    • Date
    • Thread