NSRange to Range

前端 未结 13 1231
失恋的感觉
失恋的感觉 2020-11-22 11:59

How can I convert NSRange to Range in Swift?

I want to use the following UITextFieldDelegate method:

13条回答
  •  逝去的感伤
    2020-11-22 12:41

    extension StringProtocol where Index == String.Index {
    
        func nsRange(of string: String) -> NSRange? {
            guard let range = self.range(of: string) else {  return nil }
            return NSRange(range, in: self)
        }
    }
    

提交回复
热议问题