之前的看到的都是錯誤的!!!!!!!!!!!!
正確的步驟如下:
1.安裝cocoaPods
2.新建一個OC工程
3.pod init 到 vi Podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '11.2'
target 'Chartsssss' do
# Uncomment the next line if you're using Swift or would like to use dynamic frameworks
use_frameworks!
pod 'Charts'
target 'ChartsssssTests' do
inherit! :search_paths
# Pods for testing
end
target 'ChartsssssUITests' do
inherit! :search_paths
# Pods for testing
end
end
4.將工程中Pods的編譯語言設置爲SWIFT最新版本
build Settings ->Swift Language Version
5.將Chart.framework添加到新建的項目中
點擊新建的項目->Build Phases->Link Binary With Libraries-> "+" -> 找到Charts.frame添加
6.添加OC與Switf橋接
在工程中新建一個Swift文件,名字隨便取,如"Chart-Bridging-Header.h",這時候會提示是否建立橋接文件,直接選Create Bridging Header選項,名字無 所謂,會自動建立一個橋接文件。
在橋接文件裏寫入
@import Charts;
6.測試
#import "ViewController.h"
#import "Chart-Bridging-Header.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
BarChartView *chatView=[[BarChartView alloc]initWithFrame:CGRectMake(0, 40, 300, 300)];
chatView.backgroundColor=[UIColor blueColor];
[self.view addSubview:chatView];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end