Downloaded the project from github, also loaded pods.
Errors appear when starting the simulator “Cannot find type ‘MarkerImage, ChartDataEntry, Legend’ in scope”.
Files are in pods -> Charts -> Core.
Lost classes exist in the project, open via navigator.
Deleted beadles, cleaned the project, re-recorded.
I tried adding via Complite Sources.
Tell me which direction to look in order to solve this problem.
I tried that too… Response from user: Azure Yu
sudo gem install cocoapods-deintegrate cocoapods-clean
pod deintegrate
pod cache clean --all
rm Podfile
rm Podfile.lock
pod init
<code>
import Foundation
import Charts
#if canImport(UIKit)
import UIKit
#endif
</code>
<code>
@objc(TooltipDataItem)
open class TooltipDataItem: NSObject {
@objc open var color: UIColor?
@objc open var text: String
@objc open var hasValue: Bool
@objc public init(color: UIColor, text: String, hasValue: Bool)
{
self.color = color
self.text = text
self.hasValue = hasValue
super.init()
}
@objc public init(text: String, hasValue: Bool)
{
self.text = text
self.hasValue = hasValue
super.init()
}
@objc public init(color: UIColor, text: String)
{
self.color = color
self.text = text
self.hasValue = false
super.init()
}
@objc public init(text: String)
{
self.text = text
self.hasValue = false
super.init()
}
}
</code>
<code>
@objc(TooltipData)
open class TooltipData: NSObject {
@objc open var items: [TooltipDataItem]
@objc open var title: String?
@objc open var hideEmpty: Bool
@objc public init(title: String, items: [TooltipDataItem], hideEmpty: Bool)
{
self.items = [TooltipDataItem]()
self.items.append(contentsOf: items)
self.title = title
self.hideEmpty = hideEmpty
super.init()
}
@objc public init(title: String)
{
self.items = [TooltipDataItem]()
self.title = title
self.hideEmpty = false
super.init()
}
@objc public init(title: String, items: [TooltipDataItem])
{
self.items = [TooltipDataItem]()
self.items.append(contentsOf: items)
self.title = title
self.hideEmpty = false
super.init()
}
@objc public init(items: [TooltipDataItem])
{
self.items = [TooltipDataItem]()
self.items.append(contentsOf: items)
self.hideEmpty = false
super.init()
}
@objc public init(items: [TooltipDataItem], hideEmpty: Bool)
{
self.items = [TooltipDataItem]()
self.items.append(contentsOf: items)
self.hideEmpty = hideEmpty
super.init()
}
}
open class BalloonMarker: MarkerImage //Cannot find type 'MarkerImage' in scope
{
@objc open var color: UIColor
@objc open var arrowSize = CGSize(width: 0, height: 0)
@objc open var font: UIFont
@objc open var textColor: UIColor
@objc open var insets: UIEdgeInsets
@objc open var minimumSize = CGSize()
fileprivate var drawData: TooltipData?
fileprivate var _labelSize: CGSize = CGSize()
fileprivate var _paragraphStyle: NSMutableParagraphStyle?
fileprivate var _drawAttributes = [NSAttributedString.Key : Any]()
@objc public init(color: UIColor, font: UIFont, textColor: UIColor, insets: UIEdgeInsets)
{
self.color = color
self.font = font
self.textColor = textColor
self.insets = insets
_paragraphStyle = NSParagraphStyle.default.mutableCopy() as? NSMutableParagraphStyle
_paragraphStyle?.alignment = .left
_paragraphStyle?.lineBreakMode = .byWordWrapping
super.init()
}
open override func offsetForDrawing(atPoint point: CGPoint) -> CGPoint
{
var offset = self.offset
var size = self.size
if size.width == 0.0 && image != nil
{
size.width = image!.size.width
}
if size.height == 0.0 && image != nil
{
size.height = image!.size.height
}
let width = size.width
let height = size.height
let padding: CGFloat = 8.0
var origin = point
origin.x -= width / 2
origin.y -= height
if origin.x + offset.x < 0.0
{
offset.x = -origin.x + padding
}
else if let chart = chartView,
origin.x + width + offset.x > chart.bounds.size.width
{
offset.x = chart.bounds.size.width - origin.x - width - padding
}
if origin.y + offset.y < 0
{
offset.y = height + padding;
}
else if let chart = chartView,
origin.y + height + offset.y > chart.bounds.size.height
{
offset.y = chart.bounds.size.height - origin.y - height - padding
}
return offset
}
open override func draw(context: CGContext, point: CGPoint)
{
guard let drawData = drawData else { return }
var hasAnyValue = false
for item in drawData.items {
if item.hasValue {
hasAnyValue = true
break
}
}
if(drawData.hideEmpty && !hasAnyValue) {
return
}
let offset = self.offsetForDrawing(atPoint: point)
let size = self.size
var rect = CGRect(
origin: CGPoint(
x: point.x + offset.x,
y: 0 ),// point.y),// + offset.y),
size: size)
rect.origin.x -= size.width / 2.0
// rect.origin.y -= size.height
context.saveGState()
context.setFillColor(color.cgColor)
var roundRect = UIBezierPath(roundedRect: rect, byRoundingCorners:.allCorners, cornerRadii: CGSize(width: 6.0, height: 6.0)).cgPath
context.addPath(roundRect)
context.fillPath()
rect.origin.y += self.insets.top
rect.size.height -= self.insets.top + self.insets.bottom
UIGraphicsPushContext(context)
var y = rect.origin.y
if let title = drawData.title {
if title.count > 0 {
var isize = CGSize()
isize = title.size(withAttributes: _drawAttributes)
title.draw(in: CGRect(x: rect.origin.x + self.insets.left, y: y, width: isize.width, height: isize.height), withAttributes: _drawAttributes)
y += isize.height + 2
}
}
let bndSize = CGSize(width: 240, height: 999)
for item in drawData.items {
if drawData.hideEmpty && !item.hasValue {
continue
}
var isize = CGSize()
// isize = item.text.size(withAttributes: _drawAttributes)
let iRect = item.text.boundingRect(with: bndSize, options: .usesLineFragmentOrigin, attributes: _drawAttributes, context: nil)
isize = iRect.size
var textShift = 0.0
if let color = item.color {
color.set()
textShift = 12.0
context.addRect(CGRect(x: rect.origin.x + self.insets.left, y: y + isize.height / 2 - 5, width: 10, height: 10))
// context.strokePath()
context.fillPath()
}
item.text.draw(in: CGRect(x: rect.origin.x + textShift + self.insets.left, y: y, width: isize.width, height: isize.height), withAttributes: _drawAttributes)
y += max( isize.height + 2, 12)
}
UIGraphicsPopContext()
context.restoreGState()
}
open override func refreshContent(entry: ChartDataEntry, highlight: Highlight)
{
if let extraData = entry.data as? TooltipData {
setLabel(extraData)
} else {
let tipData: TooltipData = TooltipData(title: "")
tipData.items.append(TooltipDataItem(color: color, text: String(entry.y)))
}
}
@objc open func setLabel(_ tipData: TooltipData)
{
drawData = tipData
_drawAttributes.removeAll()
_drawAttributes[.font] = self.font
_drawAttributes[.paragraphStyle] = _paragraphStyle
_drawAttributes[.foregroundColor] = self.textColor
_labelSize = drawData?.title?.size(withAttributes: _drawAttributes) ?? CGSize.zero
if let title = drawData?.title {
if title.count == 0 {
_labelSize = CGSize.zero
}
}
let bndSize = CGSize(width: 240, height: 999)
for item in drawData!.items {
if drawData!.hideEmpty && !item.hasValue {
continue
}
var isize = CGSize()
let iRect = item.text.boundingRect(with: bndSize, options: .usesLineFragmentOrigin, attributes: _drawAttributes, context: nil)
isize = iRect.size
// isize = item.text.size(withAttributes: _drawAttributes)
_labelSize.height += max(isize.height + 2, 12)
_labelSize.width = max(_labelSize.width, isize.width + 12)
}
var size = CGSize()
size.width = _labelSize.width + self.insets.left + self.insets.right
size.height = _labelSize.height + self.insets.top + self.insets.bottom
size.width = max(minimumSize.width, size.width)
size.height = max(minimumSize.height, size.height)
self.size = size
}
}
</code>
did you import the pods into the files you use them?
Pods imported and updated
Please put formatted code in your question, not screen-shots of code.
Did you add the appropriate
import
statement at the top of your swift file? Maybeimport Charts
(or whatever is needed for this pod). Did you dopod install
? Are you opening the workspace file instead of the project file?The pods were installed correctly, there were no warnings or errors in the terminal. I open through .xcworkspace.
Show 3 more comments