You can’t. 

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

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

After 1+ months are you sure Swift is worth all this effort? 


> On 16 Aug 2014, at 4:30 pm, Gerriet M. Denkmann <gerr...@mdenkmann.de> 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 (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/rols%40rols.org
> 
> This email sent to r...@rols.org

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to