简体   繁体   English

ScrollableGraphicView Swift库在Objective C项目中的问题

[英]Issue with ScrollableGraphicView Swift Library in Objective C project

Hello everyone for my chart in my app I'm using the MIT ScrollableGraphView library written entirely in Swift Language. 大家好,我的应用程序中的图表我使用的是完全用Swift语言编写的MIT ScrollableGraphView库。

This is the link of Ghitub https://github.com/philackm/ScrollableGraphView 这是Ghitub的链接https://github.com/philackm/ScrollableGraphView

To use this library in my ObjectiveC project, I imported this into my view controller file: 为了在我的ObjectiveC项目中使用这个库,我将其导入到我的视图控制器文件中:

#import "TargetName-Swift.h"

Then to work with the library we need to include <ScrollableGraphViewDataSource> 然后,要使用该库,我们需要包含<ScrollableGraphViewDataSource>

At this point the documentation says to allocate the class in this way 此时,文档说以这种方式分配类

ScrollableGraphView * graphView = [[ScrollableGraphView alloc] initWithFrame: self.view.frame dataSource: self];

This is my complete ViewController.m 这是我完整的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];
}

My problem is that xCode returns this error to me 我的问题是xCode将此错误返回给我

No visible @interface for 'ScrollableGraphView' declares the selector 'initWithFrame: dataSource:' 'ScrollableGraphView'的可见@interface没有声明选择器'initWithFrame:dataSource:'

I think I have followed all the necessary instructions to use this library but I do not understand why I can not find the class allocation with datasource 我想我已经遵循了使用该库的所有必要说明,但是我不明白为什么我找不到带有数据源的类分配

In the ScrollableGraphView.swift file, the class allocation also includes the datasource 在ScrollableGraphView.swift文件中,类分配还包括数据源

public init (frame: CGRect, dataSource: ScrollableGraphViewDataSource) {
        self.dataSource = dataSource
        super.init (frame: frame)
    }

so I do not understand why I can not allocate the class in objective C .. 所以我不明白为什么我不能在目标C中分配类。

Where am I doing wrong? 我在哪里做错了? has anyone ever used this library? 有没有人使用过这个库? do you know how to solve the problem? 你知道如何解决这个问题吗?

It seems that in my case the class allocation in the swift source file did not have the extension @objc 在我看来,swift源文件中的类分配没有扩展名@objc

As soon as I added this before initialization, everything worked perfectly for me ... 我在初始化之前添加了此内容,一切对我来说都非常完美...

This was the change: 这是更改:

Old source 旧资料

public init(frame: CGRect, dataSource: ScrollableGraphViewDataSource) {
        self.dataSource = dataSource
        super.init(frame: frame)
    }

Source with the addition of @ objc 带有@ objc的源

@objc public init(frame: CGRect, dataSource: ScrollableGraphViewDataSource) {
        self.dataSource = dataSource
        super.init(frame: frame)
    }

Now everything works ... I also thank OOPer for his suggestion that in this case it was correct! 现在一切正常...我也感谢OOPer的建议,在这种情况下,它是正确的!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM