Re: formatted strings in Swift

2016-09-02 Thread Quincey Morris
On Sep 2, 2016, at 22:02 , Gerriet M. Denkmann wrote: > > Did in a playground: > > let s = String(format: "%2s → %2s", "a", "b") > print(“formatted = \"\(s)\"") > > But this prints random garbage (e.g.: formatted = “‡“S → ‡“S”) (no error > message or compi

formatted strings in Swift

2016-09-02 Thread Gerriet M. Denkmann
Did in a playground: let s = String(format: "%2s → %2s", "a", "b") print(“formatted = \"\(s)\"") But this prints random garbage (e.g.: formatted = “‡“S → ‡“S”) (no error message or compiler warning). Why? How to create a formatted string? Gerriet.

Re: Substring in Swift

2016-09-02 Thread Gerriet M. Denkmann
> On 3 Sep 2016, at 00:23, Quincey Morris > wrote: […] > My only quibble would be the double bridging: > >> let swiftString = uitv.text // bridging from >> NSString to String >> let nsString = swiftString as NSString // bridging from String >> to NSStr

Re: Substring in Swift

2016-09-02 Thread Quincey Morris
On Sep 2, 2016, at 06:32 , Gerriet M. Denkmann wrote: > > The solution in Swift I have found uses NSString to cope with NSRange: > > // uitv is UITextView > let swiftString = uitv.text > let nsString = swiftString as NSString > let selectedNSRange = uitv.selectedRange

Re: Substring in Swift

2016-09-02 Thread Gerriet M. Denkmann
> On 2 Sep 2016, at 20:00, Jim Adams wrote: > > >> On Sep 2, 2016, at 5:17 AM, Gerriet M. Denkmann wrote: >> >> How to translate this into Swift (current version, i.e. the one before 3.0): >> >> UITextView *uitv = … >> NSRange selectedRange = uitv.selectedRange; >> NSString *textString = uit

Re: Substring in Swift

2016-09-02 Thread Jim Adams
I found these examples on useyourloaf.com: let fqdn = "useyourloaf.com" let rangeOfTLD = Range(start: fqdn.endIndex.advancedBy(-3), end: fqdn.endIndex) let tld = fqdn[rangeOfTLD] // "com" let rangeOfDomain = fqdn.startIndex..>>

Re: Does setFormatter() retain?

2016-09-02 Thread Dave
> On 29 Aug 2016, at 03:26, Andy Lee wrote: > > On Aug 24, 2016, at 4:25 PM, Jens Alfke wrote: >> >>> On Aug 24, 2016, at 1:04 PM, Andreas Falkenhahn >>> wrote: >>> >>> Now, will "setFormatter" call retain on "formatter" or not? Looking >>> at "retainCount" seems to suggest so, although I k

Re: How to Open Dictionary

2016-09-02 Thread Cosmo Birch
You might find this site helpful: http://useyourloaf.com/blog/swift-string-cheat-sheet/ > On Sep 2, 2016, at 2:08 AM, Gerriet M. Denkmann wrote: > > How to translate this into Swift (current version, i.e. the one before 3.0): > > UITextView *uitv = … > NSRange selectedRange = uitv.selectedRan

Substring in Swift

2016-09-02 Thread Gerriet M. Denkmann
How to translate this into Swift (current version, i.e. the one before 3.0): UITextView *uitv = … NSRange selectedRange = uitv.selectedRange; NSString *textString = uitv.string; NSString *selectedString = [ textString substringWithRange: selectedRange ]; Looks simple, but I have now tried for mor

Re: How to Open Dictionary

2016-09-02 Thread Gerriet M. Denkmann
> On 2 Sep 2016, at 13:46, Igor Ranieri wrote: > > You might want to look into UIReferenceLibraryViewController. That’s the > class that presents the dictionary view for you, you can instantiate it with > a term and present it to the user. > Thanks a lot! Exactly what I was trying to find.