website/versioned_docs/version-3.8/ios.md
:::note You can find the source code of the Lightweight Charts™ iOS wrapper in this repository. :::
You can use Lightweight Charts™ inside an iOS application. To use Lightweight Charts™ in that context, you can use our iOS wrapper, which will allow you to interact with Lightweight Charts™ library, which will be rendered in a web view.
:::info Requires iOS 10.0+ :::
CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate LightweightCharts into your Xcode project using CocoaPods, specify it in your Podfile:
pod 'LightweightCharts', '~> 3.8.0'
The Swift Package Manager is a tool for automating the distribution of Swift code and is integrated into the swift compiler.
Once you have your Swift package set up, adding LightweightCharts as a dependency is as easy as adding it to the dependencies value of your Package.swift.
dependencies: [
.package(url: "https://github.com/tradingview/LightweightChartsIOS", .upToNextMajor(from: "3.8.0"))
]
Once the library has been installed in your repo, you're ready to create your first chart.
First of all, in a file where you would like to create a chart, you need to import the library:
import LightweightCharts
Create instance of LightweightCharts, which is a subclass of UIView, and add it to your view.
var chart: LightweightCharts!
// ...
chart = LightweightCharts()
view.addSubview(chart)
// ... setup layout
Add any series to the chart and store a reference to it.
var series: BarSeries!
// ...
series = chart.addBarSeries(options: nil)
Add data to the series.
let data = [
BarData(time: .string("2018-10-19"), open: 180.34, high: 180.99, low: 178.57, close: 179.85),
BarData(time: .string("2018-10-22"), open: 180.82, high: 181.40, low: 177.56, close: 178.75),
BarData(time: .string("2018-10-23"), open: 175.77, high: 179.49, low: 175.44, close: 178.53),
BarData(time: .string("2018-10-24"), open: 178.58, high: 182.37, low: 176.31, close: 176.97),
BarData(time: .string("2018-10-25"), open: 177.52, high: 180.50, low: 176.83, close: 179.07)
]
// ...
series.setData(data: data)
The GitHub repository for LightweightChartsIOS contains an example of the library in action. To run the example, start by cloning the repository, go to the Example directory, and then run
pod install