【发布时间】:2023-03-23 08:34:01
【问题描述】:
大家好,我的应用程序中的图表我正在使用完全用 Swift 语言编写的 MIT ScrollableGraphView 库。
这是Ghitub的链接https://github.com/philackm/ScrollableGraphView
为了在我的 ObjectiveC 项目中使用这个库,我将它导入到我的视图控制器文件中:
#import "TargetName-Swift.h"
然后要使用库,我们需要包含 <ScrollableGraphViewDataSource>
此时文档说以这种方式分配类
ScrollableGraphView * graphView = [[ScrollableGraphView alloc] initWithFrame: self.view.frame dataSource: self];
这是我完整的 ViewController.m
#import "TargetName-Swift.h"
@interface Dashboard () <ScrollableGraphViewDataSource>
@end
@implementation Dashboard
- (void)viewDidLoad {
[super viewDidLoad];
ScrollableGraphView *graphView = [[ScrollableGraphView alloc] initWithFrame: self.view.frame dataSource: self];
[self.view addSubview: graphView];
}
我的问题是 xCode 将这个错误返回给我
“ScrollableGraphView”没有可见的@interface 声明选择器“initWithFrame: dataSource:”
我想我已经遵循了使用这个库的所有必要说明,但我不明白为什么我找不到数据源的类分配
在 ScrollableGraphView.swift 文件中,类分配还包括数据源
public init (frame: CGRect, dataSource: ScrollableGraphViewDataSource) {
self.dataSource = dataSource
super.init (frame: frame)
}
所以我不明白为什么我不能在目标 C 中分配课程..
我哪里做错了?有人用过这个库吗?你知道如何解决这个问题吗?
【问题讨论】:
-
@Larme Objective-C Generated Interface Header Name...我知道在objective c项目中集成swift库我需要插入#import"projectName-Swift.h"
-
您是否尝试过将
@objc添加到 Swift 源代码中? -
@OOPer 添加您的答案...这对我来说是正确的
-
请自己写一个答案。当我无法确认它确实有效时,我通常不会写一些东西作为答案。而且我现在没有时间用实际的 ScrollableGraphView 确认。
标签: ios swift datasource