我正在使用框架GlyuckDataGrid在 Objective-C 中实现数据网格。有一个名为 IndexPath+DataGrid.swift
的扩展,它对于数据网格的实现至关重要,但它是用 Swift 编写的。
我正在使用 CocoaPods,并且我有以下导入,但仍然无法访问它。
@import GlyuckDataGrid;
#import <GlyuckDataGrid/GlyuckDataGrid-Swift.h>
E:既然我有了解决方案的答案,我想指出我忽略了 IndexPath
和 NSIndexPath
。别是我,混淆了 2...
最佳答案
该框架使用纯 Swift 类型 (IndexPath
),而不是其 Objective-C 等效类型 (NSIndexPath
)。对于您的情况,解决方案是扩展 NSIndexPath
以及 IndexPath
以向 Objective-C 公开功能:
public extension NSIndexPath { /** Returns an index-path object initialized with the indexes of a specific row and column in a data grid view. - parameter column: An index number identifying a column in a DataGridView object in a row identified by the row parameter. - parameter row: An index number identifying a row in a DataGridView object. - returns: An NSIndexPath object. */ convenience init(forColumn column: Int, row: Int) { self.init(item: column, section: row) } /// An index number identifying a column in a row of a data grid view. (read-only) var dataGridColumn: Int { return self.index(atPosition: 1) } /// An index number identifying a row in a data grid view. (read-only) var dataGridRow: Int { return self.index(atPosition: 0) } /// An index number for single-item indexPath var index: Int { return self.index(atPosition: 0) } }
来自c281729
.
关于ios - 如何访问 Objective-C 中的 Swift 扩展?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40772789/