Skip to content

swift4中有一个地方报错, 在存储属性那里用全局变量是有问题的. #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
GG526 opened this issue Dec 5, 2017 · 1 comment

Comments

@GG526
Copy link

GG526 commented Dec 5, 2017

  1. swift4中只需改这个地方就可以兼容.
func nsRange(from range: Range<String.Index>) -> NSRange {
//        let from = range.lowerBound.samePosition(in: utf16)
//        let to = range.upperBound.samePosition(in: utf16)
        // utf16.distance(from: utf16.startIndex, to: from)  //utf16.distance(from: from, to: to)
        return NSRange.init(range, in: self)
//        return NSRange(location:self.startIndex ,length: )
    }

注释的地方是您的代码。

2、在extension中添加储存属性可以使用runtime

private func setIsTapAction(isTapAction: Bool) {
        objc_setAssociatedObject(self, &AssociatedKeys.tapAction, isTapAction as Bool, objc_AssociationPolicy.OBJC_ASSOCIATION_RETAIN_NONATOMIC)
    }
    
    private func getIsTapAction() -> Bool {
        let isTap = objc_getAssociatedObject(self, &AssociatedKeys.tapAction) as? Bool
        return isTap != nil ? isTap! : true
    }

如果用原来的实现方式会出现第二地方添加的action会清空上一次的添加的.

@lyb5834
Copy link
Owner

lyb5834 commented Feb 24, 2018

多谢指出

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants