我将如何在 Swift 中实现此 Objective-C 行?
How would I implement this Objective-C Line in Swift?
在名为 UIScrollView-InfiniteScroll
的库(链接 here)中,您可以在 Classes/UIScrollView+InfiniteScroll.m
中找到 this 行代码:
static const void *kPBInfiniteScrollStateKey = &kPBInfiniteScrollStateKey;
如何在 Swift 中重写这一行?有可能吗?
它会帮助很多 你应该包括原始评论
// Keys for values in associated dictionary
static const void *kPBInfiniteScrollStateKey = &kPBInfiniteScrollStateKey;
您可以在 Swift 中使用这样的关联对象,由 erhatsezer https://gist.github.com/serhatsezer/4abe382229b001b37b1ee2f46e62b90f#file-productdetail-extension-swift
提供
private var associateKey: Void?
extension ProductDetail {
var totalSumOfBasket: String? {
get {
return objc_getAssociatedObject(self, &associateKey) as? String
}
set {
objc_setAssociatedObject(self, &associateKey, newValue, .OBJC_ASSOCIATION_RETAIN)
}
}
}
最基本的方法是使用 https://swiftify.com 工具。将 objc 转换为 swift.
的最简单方法
对于无限滚动视图,我发现的最佳解决方案是 https://github.com/rebeloper/DScrollview 它完全用 swift 编写。
在名为 UIScrollView-InfiniteScroll
的库(链接 here)中,您可以在 Classes/UIScrollView+InfiniteScroll.m
中找到 this 行代码:
static const void *kPBInfiniteScrollStateKey = &kPBInfiniteScrollStateKey;
如何在 Swift 中重写这一行?有可能吗?
它会帮助很多 你应该包括原始评论
// Keys for values in associated dictionary
static const void *kPBInfiniteScrollStateKey = &kPBInfiniteScrollStateKey;
您可以在 Swift 中使用这样的关联对象,由 erhatsezer https://gist.github.com/serhatsezer/4abe382229b001b37b1ee2f46e62b90f#file-productdetail-extension-swift
提供private var associateKey: Void?
extension ProductDetail {
var totalSumOfBasket: String? {
get {
return objc_getAssociatedObject(self, &associateKey) as? String
}
set {
objc_setAssociatedObject(self, &associateKey, newValue, .OBJC_ASSOCIATION_RETAIN)
}
}
}
最基本的方法是使用 https://swiftify.com 工具。将 objc 转换为 swift.
的最简单方法对于无限滚动视图,我发现的最佳解决方案是 https://github.com/rebeloper/DScrollview 它完全用 swift 编写。