简体   繁体   中英

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.

This is the link of Ghitub https://github.com/philackm/ScrollableGraphView

To use this library in my ObjectiveC project, I imported this into my view controller file:

#import "TargetName-Swift.h"

Then to work with the library we need to include <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

#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

No visible @interface for 'ScrollableGraphView' declares the selector '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

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 ..

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

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 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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