Skip to content

Commit

Permalink
Part I modify All NSAttributedStringKey related methods for Swift 4
Browse files Browse the repository at this point in the history
extension NSString for func size(attributes attrs: [String : Any]? = nil) -> NSSize is deleted due to iOS uses size(withAttributes: attrs) now
  • Loading branch information
liuxuan30 authored and pmairoldi committed Sep 7, 2017
1 parent f9eea57 commit 0307406
Show file tree
Hide file tree
Showing 26 changed files with 144 additions and 110 deletions.
47 changes: 39 additions & 8 deletions Charts.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -718,8 +718,17 @@
193FC8DF32D250560C5F5D77 /* Project object */ = {
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0830;
LastUpgradeCheck = 0700;
LastSwiftUpdateCheck = 0730;
LastUpgradeCheck = 0800;
TargetAttributes = {
06165F231D8110E600722320 = {
CreatedOnToolsVersion = 7.3.1;
LastSwiftMigration = 0900;
};
06165F2D1D8110E600722320 = {
CreatedOnToolsVersion = 7.3.1;
};
};
};
buildConfigurationList = 493FF4FB1D40FC7C51DDDA6B /* Build configuration list for PBXProject "Charts" */;
compatibilityVersion = "Xcode 3.2";
Expand Down Expand Up @@ -1117,6 +1126,32 @@
SDKROOT = macosx;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
WATCHOS_DEPLOYMENT_TARGET = 2.0;
};
name = Release;
};
06165F391D8110E700722320 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
APPLICATION_EXTENSION_API_ONLY = YES;
COMBINE_HIDPI_IMAGES = YES;
DEFINES_MODULE = YES;
DYLIB_COMPATIBILITY_VERSION = 1;
DYLIB_CURRENT_VERSION = 1;
DYLIB_INSTALL_NAME_BASE = "@rpath";
FRAMEWORK_VERSION = A;
INFOPLIST_FILE = "$(SRCROOT)/Source/Supporting Files/Info.plist";
INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks";
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.dcg.Charts;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand Down Expand Up @@ -1144,12 +1179,8 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = macosx;
SKIP_INSTALL = YES;
SUPPORTED_PLATFORMS = "macosx iphoneos iphonesimulator appletvos appletvsimulator";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
2 changes: 1 addition & 1 deletion Charts.xcodeproj/xcshareddata/xcschemes/Charts.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
22 changes: 18 additions & 4 deletions ChartsDemo/ChartsDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -484,12 +484,12 @@
attributes = {
LastSwiftMigration = 0700;
LastSwiftUpdateCheck = 0700;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = dcg;
TargetAttributes = {
5B57BBAE1A9B26AA0036A6CC = {
CreatedOnToolsVersion = 6.1.1;
LastSwiftMigration = 0800;
LastSwiftMigration = 0900;
};
};
};
Expand Down Expand Up @@ -647,14 +647,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -693,14 +699,20 @@
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -740,7 +752,8 @@
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_OBJC_BRIDGING_HEADER = "Supporting Files/ChartsDemo-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -759,7 +772,8 @@
PRODUCT_NAME = ChartsDemo;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SWIFT_OBJC_BRIDGING_HEADER = "Supporting Files/ChartsDemo-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_SWIFT3_OBJC_INFERENCE = On;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
10 changes: 5 additions & 5 deletions ChartsDemo/Classes/Components/BalloonMarker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class BalloonMarker: MarkerImage
fileprivate var label: String?
fileprivate var _labelSize: CGSize = CGSize()
fileprivate var _paragraphStyle: NSMutableParagraphStyle?
fileprivate var _drawAttributes = [String : AnyObject]()
fileprivate var _drawAttributes = [NSAttributedStringKey : AnyObject]()

public init(color: UIColor, font: UIFont, textColor: UIColor, insets: UIEdgeInsets)
{
Expand Down Expand Up @@ -119,11 +119,11 @@ open class BalloonMarker: MarkerImage
label = newLabel

_drawAttributes.removeAll()
_drawAttributes[NSFontAttributeName] = self.font
_drawAttributes[NSParagraphStyleAttributeName] = _paragraphStyle
_drawAttributes[NSForegroundColorAttributeName] = self.textColor
_drawAttributes[NSAttributedStringKey.font] = self.font
_drawAttributes[NSAttributedStringKey.paragraphStyle] = _paragraphStyle
_drawAttributes[NSAttributedStringKey.foregroundColor] = self.textColor

_labelSize = label?.size(attributes: _drawAttributes) ?? CGSize.zero
_labelSize = label?.size(withAttributes: _drawAttributes) ?? CGSize.zero

var size = CGSize()
size.width = _labelSize.width + self.insets.left + self.insets.right
Expand Down
20 changes: 10 additions & 10 deletions Source/Charts/Charts/ChartViewBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate

/// flag that indicates if offsets calculation has already been done or not
fileprivate var _offsetsCalculated = false
/// array of Highlight objects that reference the highlighted slices in the chart
internal var _indicesToHighlight = [Highlight]()

Expand Down Expand Up @@ -276,8 +276,8 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
_data = nil
_offsetsCalculated = false
_indicesToHighlight.removeAll()
lastHighlighted = nil
lastHighlighted = nil
setNeedsDisplay()
}

Expand Down Expand Up @@ -367,8 +367,8 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
text: noDataText,
point: CGPoint(x: frame.width / 2.0, y: frame.height / 2.0),
attributes:
[NSFontAttributeName: noDataFont,
NSForegroundColorAttributeName: noDataTextColor],
[NSAttributedStringKey.font: noDataFont,
NSAttributedStringKey.foregroundColor: noDataTextColor],
constrainedToSize: self.bounds.size,
anchor: CGPoint(x: 0.5, y: 0.5),
angleRadians: 0.0)
Expand Down Expand Up @@ -405,10 +405,10 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
y: frame.height - _viewPortHandler.offsetBottom - description.yOffset - description.font.lineHeight)
}

var attrs = [String : AnyObject]()
var attrs = [NSAttributedStringKey : AnyObject]()

attrs[NSFontAttributeName] = description.font
attrs[NSForegroundColorAttributeName] = description.textColor
attrs[NSAttributedStringKey.font] = description.font
attrs[NSAttributedStringKey.foregroundColor] = description.textColor

ChartUtils.drawText(
context: context,
Expand Down Expand Up @@ -871,7 +871,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
/// - returns: `true` if the image was saved successfully
open func save(to path: String, format: ImageFormat, compressionQuality: Double) -> Bool
{
guard let image = getChartImage(transparent: format != .jpeg)
guard let image = getChartImage(transparent: format != .jpeg)
else { return false }

var imageData: Data!
Expand All @@ -895,7 +895,7 @@ open class ChartViewBase: NSUIView, ChartDataProvider, AnimatorDelegate
return false
}

return true
return true
}

internal var _viewportJobs = [ViewPortJob]()
Expand Down
6 changes: 3 additions & 3 deletions Source/Charts/Charts/PieChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ open class PieChartView: PieRadarChartViewBase

attrString = NSMutableAttributedString(string: newValue!)
attrString?.setAttributes([
NSForegroundColorAttributeName: NSUIColor.black,
NSFontAttributeName: NSUIFont.systemFont(ofSize: 12.0),
NSParagraphStyleAttributeName: paragraphStyle
NSAttributedStringKey.foregroundColor: NSUIColor.black,
NSAttributedStringKey.font: NSUIFont.systemFont(ofSize: 12.0),
NSAttributedStringKey.paragraphStyle: paragraphStyle
], range: NSMakeRange(0, attrString!.length))
}
self.centerAttributedText = attrString
Expand Down
8 changes: 4 additions & 4 deletions Source/Charts/Components/Legend.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ open class Legend: ComponentBase
guard let label = entry.label
else { continue }

let size = (label as NSString!).size(attributes: [NSFontAttributeName: font])
let size = (label as NSString!).size(withAttributes: [NSAttributedStringKey.font: font])

if size.width > maxW
{
Expand Down Expand Up @@ -351,7 +351,7 @@ open class Legend: ComponentBase

if label != nil
{
let size = (label as NSString!).size(attributes: [NSFontAttributeName: labelFont])
let size = (label as NSString!).size(withAttributes: [NSAttributedStringKey.font: labelFont])

if drawingForm && !wasStacked
{
Expand Down Expand Up @@ -410,7 +410,7 @@ open class Legend: ComponentBase

// Start calculating layout

let labelAttrs = [NSFontAttributeName: labelFont]
let labelAttrs = [NSAttributedStringKey.font: labelFont]
var maxLineWidth: CGFloat = 0.0
var currentLineWidth: CGFloat = 0.0
var requiredWidth: CGFloat = 0.0
Expand Down Expand Up @@ -438,7 +438,7 @@ open class Legend: ComponentBase
// grouped forms have null labels
if label != nil
{
calculatedLabelSizes[i] = (label as NSString!).size(attributes: labelAttrs)
calculatedLabelSizes[i] = (label as NSString!).size(withAttributes: labelAttrs)
requiredWidth += drawingForm ? formToTextSpace + formSize : 0.0
requiredWidth += calculatedLabelSizes[i].width
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Components/YAxis.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ open class YAxis: AxisBase
open func requiredSize() -> CGSize
{
let label = getLongestLabel() as NSString
var size = label.size(attributes: [NSFontAttributeName: labelFont])
var size = label.size(withAttributes: [NSAttributedStringKey.font: labelFont])
size.width += xOffset * 2.0
size.height += yOffset * 2.0
size.width = max(minWidth, min(size.width, maxWidth > 0.0 ? maxWidth : size.width))
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/BarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ open class BarChartRenderer: BarLineScatterCandleBubbleRenderer
/// Draws a value at the specified x and y position.
open func drawValue(context: CGContext, value: String, xPos: CGFloat, yPos: CGFloat, font: NSUIFont, align: NSTextAlignment, color: NSUIColor)
{
ChartUtils.drawText(context: context, text: value, point: CGPoint(x: xPos, y: yPos), align: align, attributes: [NSFontAttributeName: font, NSForegroundColorAttributeName: color])
ChartUtils.drawText(context: context, text: value, point: CGPoint(x: xPos, y: yPos), align: align, attributes: [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: color])
}

open override func drawExtras(context: CGContext)
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/BubbleChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ open class BubbleChartRenderer: BarLineScatterCandleBubbleRenderer
x: pt.x,
y: pt.y - (0.5 * lineHeight)),
align: .center,
attributes: [NSFontAttributeName: valueFont, NSForegroundColorAttributeName: valueTextColor])
attributes: [NSAttributedStringKey.font: valueFont, NSAttributedStringKey.foregroundColor: valueTextColor])
}

if let icon = e.icon, dataSet.isDrawIconsEnabled
Expand Down
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/CandleStickChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ open class CandleStickChartRenderer: LineScatterCandleRadarRenderer
x: pt.x,
y: pt.y - yOffset),
align: .center,
attributes: [NSFontAttributeName: valueFont, NSForegroundColorAttributeName: dataSet.valueTextColorAt(j)])
attributes: [NSAttributedStringKey.font: valueFont, NSAttributedStringKey.foregroundColor: dataSet.valueTextColorAt(j)])
}

if let icon = e.icon, dataSet.isDrawIconsEnabled
Expand Down
6 changes: 3 additions & 3 deletions Source/Charts/Renderers/HorizontalBarChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer
viewPortHandler: viewPortHandler)

// calculate the correct offset depending on the draw position of the value
let valueTextWidth = valueText.size(attributes: [NSFontAttributeName: valueFont]).width
let valueTextWidth = valueText.size(withAttributes: [NSAttributedStringKey.font: valueFont]).width
posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus))
negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus)

Expand Down Expand Up @@ -462,7 +462,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer
viewPortHandler: viewPortHandler)

// calculate the correct offset depending on the draw position of the value
let valueTextWidth = valueText.size(attributes: [NSFontAttributeName: valueFont]).width
let valueTextWidth = valueText.size(withAttributes: [NSAttributedStringKey.font: valueFont]).width
posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus))
negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus)

Expand Down Expand Up @@ -546,7 +546,7 @@ open class HorizontalBarChartRenderer: BarChartRenderer
viewPortHandler: viewPortHandler)

// calculate the correct offset depending on the draw position of the value
let valueTextWidth = valueText.size(attributes: [NSFontAttributeName: valueFont]).width
let valueTextWidth = valueText.size(withAttributes: [NSAttributedStringKey.font: valueFont]).width
posOffset = (drawValueAboveBar ? valueOffsetPlus : -(valueTextWidth + valueOffsetPlus))
negOffset = (drawValueAboveBar ? -(valueTextWidth + valueOffsetPlus) : valueOffsetPlus)

Expand Down
4 changes: 2 additions & 2 deletions Source/Charts/Renderers/LegendRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ open class LegendRenderer: Renderer

if direction == .rightToLeft
{
posX -= (e.label as NSString!).size(attributes: [NSFontAttributeName: labelFont]).width
posX -= (e.label as NSString!).size(withAttributes: [NSAttributedStringKey.font: labelFont]).width
}

if !wasStacked
Expand Down Expand Up @@ -571,6 +571,6 @@ open class LegendRenderer: Renderer
/// Draws the provided label at the given position.
open func drawLabel(context: CGContext, x: CGFloat, y: CGFloat, label: String, font: NSUIFont, textColor: NSUIColor)
{
ChartUtils.drawText(context: context, text: label, point: CGPoint(x: x, y: y), align: .left, attributes: [NSFontAttributeName: font, NSForegroundColorAttributeName: textColor])
ChartUtils.drawText(context: context, text: label, point: CGPoint(x: x, y: y), align: .left, attributes: [NSAttributedStringKey.font: font, NSAttributedStringKey.foregroundColor: textColor])
}
}
2 changes: 1 addition & 1 deletion Source/Charts/Renderers/LineChartRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ open class LineChartRenderer: LineRadarRenderer
x: pt.x,
y: pt.y - CGFloat(valOffset) - valueFont.lineHeight),
align: .center,
attributes: [NSFontAttributeName: valueFont, NSForegroundColorAttributeName: dataSet.valueTextColorAt(j)])
attributes: [NSAttributedStringKey.font: valueFont, NSAttributedStringKey.foregroundColor: dataSet.valueTextColorAt(j)])
}

if let icon = e.icon, dataSet.isDrawIconsEnabled
Expand Down
Loading

0 comments on commit 0307406

Please sign in to comment.