您可以使用URL的absoluteString属性来获取URL的字符串表示形式,并使用Int()函数将其转换为整数。下面是您可以尝试的代码示例:

func textView(_ textView: UITextView, shouldInteractWith URL: URL, in characterRange: NSRange, interaction: UITextItemInteraction) -> Bool {
    if let urlString = URL.absoluteString, let intValue = Int(urlString) {
        // intValue is the converted integer value
        // You can use intValue here as needed
        return true
    }
    return false
}

请注意,如果URL的字符串表示形式无法转换为整数,将返回nil。因此,您可以使用可选绑定(optional binding)来确保转换成功

func textView_ textView UITextView shouldInteractWith URL URL in characterRange NSRange interaction UITextItemInteraction - Bool 获取URL的String 然后转Int

原文地址: https://www.cveoy.top/t/topic/hNWP 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录