diff --git a/Cartfile.resolved b/Cartfile.resolved index e629cf5..4a33a6b 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1,2 +1,2 @@ -github "Quick/Nimble" "v4.0.1" -github "Quick/Quick" "v0.9.2" +github "Quick/Nimble" "v7.0.1" +github "Quick/Quick" "v1.1.0" diff --git a/Graphs.xcodeproj/project.pbxproj b/Graphs.xcodeproj/project.pbxproj index 38c7245..004173f 100644 --- a/Graphs.xcodeproj/project.pbxproj +++ b/Graphs.xcodeproj/project.pbxproj @@ -194,14 +194,20 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0900; ORGANIZATIONNAME = "Recruit Holdings Co., Ltd."; TargetAttributes = { E92069811CFC20840025DBC8 = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = RT4NRJPHW3; + LastSwiftMigration = 0900; + ProvisioningStyle = Manual; }; E920698B1CFC20840025DBC8 = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = RT4NRJPHW3; + LastSwiftMigration = 0900; + ProvisioningStyle = Manual; }; }; }; @@ -283,13 +289,21 @@ 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; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -332,13 +346,21 @@ 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; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -358,6 +380,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.3; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -369,18 +392,22 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = RT4NRJPHW3; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Graphs/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.mtl.Graphs; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; @@ -388,23 +415,28 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = RT4NRJPHW3; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = Graphs/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; - IPHONEOS_DEPLOYMENT_TARGET = 8.0; + IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.mtl.Graphs; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; E920699A1CFC20840025DBC8 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + DEVELOPMENT_TEAM = RT4NRJPHW3; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", @@ -413,12 +445,16 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.mtl.GraphsTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Debug; }; E920699B1CFC20840025DBC8 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; + DEVELOPMENT_TEAM = RT4NRJPHW3; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", @@ -427,6 +463,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.mtl.GraphsTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.0; }; name = Release; }; diff --git a/Graphs.xcodeproj/xcshareddata/xcschemes/Graphs.xcscheme b/Graphs.xcodeproj/xcshareddata/xcschemes/Graphs.xcscheme index b4d2bb9..d368b4e 100644 --- a/Graphs.xcodeproj/xcshareddata/xcschemes/Graphs.xcscheme +++ b/Graphs.xcodeproj/xcshareddata/xcschemes/Graphs.xcscheme @@ -1,6 +1,6 @@ GraphColorType { - return .Mat(self) + return .mat(self) } } @@ -40,13 +40,13 @@ public struct BarGraphViewConfig { textVisible: Bool? = nil, contentInsets: UIEdgeInsets? = nil ) { - self.barColor = (barColor ?? DefaultColorType.Bar.color()).matColor() - self.textColor = textColor ?? DefaultColorType.BarText.color() - self.textFont = textFont ?? UIFont.systemFontOfSize(10.0) + self.barColor = (barColor ?? DefaultColorType.bar.color()).matColor() + self.textColor = textColor ?? DefaultColorType.barText.color() + self.textFont = textFont ?? UIFont.systemFont(ofSize: 10.0) self.barWidthScale = barWidthScale ?? 0.8 self.zeroLineVisible = zeroLineVisible ?? true self.textVisible = textVisible ?? true - self.contentInsets = contentInsets ?? UIEdgeInsetsZero + self.contentInsets = contentInsets ?? UIEdgeInsets.zero } } @@ -56,24 +56,28 @@ internal class BarGraphView: UIView { internal var graph: BarGraph? - private var config = BarGraphViewConfig() + fileprivate var config = BarGraphViewConfig() init(frame: CGRect, graph: BarGraph?) { self.graph = graph super.init(frame: frame) - self.backgroundColor = UIColor.clearColor() + self.backgroundColor = UIColor.clear self.setNeedsDisplay() } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } - func setBarGraphViewConfig(config: BarGraphViewConfig?) { + func setBarGraphViewConfig(_ config: BarGraphViewConfig?) { self.config = config ?? BarGraphViewConfig() self.setNeedsDisplay() } - private func graphFrame() -> CGRect { + fileprivate func graphFrame() -> CGRect { return CGRect( x: self.config.contentInsets.left, y: self.config.contentInsets.top, @@ -82,8 +86,8 @@ internal class BarGraphView: UIView { ) } - override func drawRect(rect: CGRect) { - super.drawRect(rect) + override func draw(_ rect: CGRect) { + super.draw(rect) guard let graph = self.graph else { return } @@ -97,11 +101,11 @@ internal class BarGraphView: UIView { let zero = rect.size.height / CGFloat((max - min).floatValue()) * CGFloat(min.floatValue()) - graph.units.enumerate().forEach({ (index, u) in + graph.units.enumerated().forEach({ (index, u) in switch self.config.barColor { - case let .Mat(color): color.setFill() - case .Gradation(_, _): break + case let .mat(color): color.setFill() + case .gradation(_, _): break } let height = { () -> CGFloat in @@ -129,14 +133,14 @@ internal class BarGraphView: UIView { ) path.fill() - if let str = self.graph?.graphTextDisplay()(unit: u, totalValue: total) { + if let str = self.graph?.graphTextDisplay()(u, total) { let attrStr = NSAttributedString.graphAttributedString(str, color: self.config.textColor, font: self.config.textFont) let size = attrStr.size() - attrStr.drawInRect( - CGRect( + attrStr.draw( + in: CGRect( origin: CGPoint( x: sectionWidth * CGFloat(index) + rect.origin.x, y: u.value >= U(0) @@ -152,4 +156,4 @@ internal class BarGraphView: UIView { } }) } -} \ No newline at end of file +} diff --git a/Graphs/Graph.swift b/Graphs/Graph.swift index a43cee0..08e6c8d 100644 --- a/Graphs/Graph.swift +++ b/Graphs/Graph.swift @@ -10,34 +10,34 @@ import UIKit public enum GraphType { case - Bar, - Line, - Pie + bar, + line, + pie } -public class Graph { +open class Graph { - public typealias GraphTextDisplayHandler = (unit: GraphUnit, totalValue: U) -> String? + public typealias GraphTextDisplayHandler = (_ unit: GraphUnit, _ totalValue: U) -> String? let kind: GraphKind init(barGraph: BarGraph) { - self.kind = GraphKind.Bar(barGraph) + self.kind = GraphKind.bar(barGraph) } init(lineGraph: LineGraph) { - self.kind = GraphKind.Line(lineGraph) + self.kind = GraphKind.line(lineGraph) } init(pieGraph: PieGraph) { - self.kind = GraphKind.Pie(pieGraph) + self.kind = GraphKind.pie(pieGraph) } } public extension Graph { - public convenience init(type: GraphType, data: [S], min minOrNil: U? = nil, max maxOrNil: U? = nil, textDisplayHandler: GraphTextDisplayHandler? = nil) { + public convenience init(type: GraphType, data: [S], min minOrNil: U? = nil, max maxOrNil: U? = nil, textDisplayHandler: GraphTextDisplayHandler? = nil) where S.GraphDataKey == T, S.GraphDataValue == U { let range = {() -> GraphRange? in if let min = minOrNil, let max = maxOrNil { @@ -49,11 +49,11 @@ public extension Graph { self.init(type: type, data: data, range: range(), textDisplayHandler: textDisplayHandler) } - public convenience init(type: GraphType, data: [S], range rangeOrNil: GraphRange? = nil, textDisplayHandler: GraphTextDisplayHandler? = nil) { + public convenience init(type: GraphType, data: [S], range rangeOrNil: GraphRange? = nil, textDisplayHandler: GraphTextDisplayHandler? = nil) where S.GraphDataKey == T, S.GraphDataValue == U { let r = {() -> GraphRange in if let r = rangeOrNil { return r } - let sorted = data.sort{ $0.value < $1.value } + let sorted = data.sorted{ $0.value < $1.value } return GraphRange( min: sorted.first?.value ?? U(0), max: sorted.last?.value ?? U(0) @@ -61,7 +61,7 @@ public extension Graph { } switch type { - case .Bar: + case .bar: self.init(barGraph:BarGraph( units: data.map{ GraphUnit(key: $0.key, value: $0.value) }, @@ -69,7 +69,7 @@ public extension Graph { textDisplayHandler: textDisplayHandler )) - case .Line: + case .line: self.init(lineGraph: LineGraph( units: data.map{ GraphUnit(key: $0.key, value: $0.value) }, @@ -77,7 +77,7 @@ public extension Graph { textDisplayHandler: textDisplayHandler )) - case .Pie: + case .pie: self.init(pieGraph: PieGraph( units: data.map{ GraphUnit(key: $0.key, value: $0.value) }, @@ -103,7 +103,7 @@ public extension Graph { let r = {() -> GraphRange in if let r = rangeOrNil { return r } - let sorted = array.sort{ $0 < $1 } + let sorted = array.sorted{ $0 < $1 } return GraphRange( min: sorted.first ?? U(0), max: sorted.last ?? U(0) @@ -111,7 +111,7 @@ public extension Graph { } switch type { - case .Bar: + case .bar: self.init(barGraph:BarGraph( units: array.map{ GraphUnit(key: nil, value: $0) }, @@ -119,7 +119,7 @@ public extension Graph { textDisplayHandler: textDisplayHandler )) - case .Line: + case .line: self.init(lineGraph: LineGraph( units: array.map{ GraphUnit(key: nil, value: $0) }, @@ -127,7 +127,7 @@ public extension Graph { textDisplayHandler: textDisplayHandler )) - case .Pie: + case .pie: self.init(pieGraph: PieGraph( units: array.map{ GraphUnit(key: nil, value: $0) }, @@ -153,7 +153,7 @@ public extension Graph { public convenience init(type: GraphType, dictionary: [T: U], range rangeOrNil: GraphRange? = nil, textDisplayHandler: GraphTextDisplayHandler? = nil) { - let sorted = dictionary.sort{ $0.1 < $1.1 } + let sorted = dictionary.sorted{ $0.1 < $1.1 } let r = {() -> GraphRange in if let r = rangeOrNil { return r } @@ -165,7 +165,7 @@ public extension Graph { } switch type { - case .Bar: + case .bar: self.init(barGraph:BarGraph( units: sorted.map{ GraphUnit(key: $0.0, value: $0.1) }, @@ -173,7 +173,7 @@ public extension Graph { textDisplayHandler: textDisplayHandler )) - case .Line: + case .line: self.init(lineGraph: LineGraph( units: sorted.map{ GraphUnit(key: $0.0, value: $0.1) }, @@ -181,7 +181,7 @@ public extension Graph { textDisplayHandler: textDisplayHandler )) - case .Pie: + case .pie: self.init(pieGraph: PieGraph( units: sorted.map{ GraphUnit(key: $0.0, value: $0.1) }, @@ -193,27 +193,27 @@ public extension Graph { public extension Graph { - public func view(frame: CGRect) -> GraphView { + public func view(_ frame: CGRect) -> GraphView { return GraphView(frame: frame, graph: self) } } enum GraphKind { case - Bar(BarGraph), - Line(LineGraph), - Pie(PieGraph) + bar(BarGraph), + line(LineGraph), + pie(PieGraph) - internal static func barGraph(units: [GraphUnit], range: GraphRange) -> GraphKind { - return GraphKind.Bar(BarGraph(units: units, range: range)) + internal static func barGraph(_ units: [GraphUnit], range: GraphRange) -> GraphKind { + return GraphKind.bar(BarGraph(units: units, range: range)) } - internal static func lineGraph(units: [GraphUnit], range: GraphRange) -> GraphKind { - return GraphKind.Line(LineGraph(units: units, range: range)) + internal static func lineGraph(_ units: [GraphUnit], range: GraphRange) -> GraphKind { + return GraphKind.line(LineGraph(units: units, range: range)) } - internal static func pieGraph(units: [GraphUnit]) -> GraphKind { - return GraphKind.Pie(PieGraph(units: units)) + internal static func pieGraph(_ units: [GraphUnit]) -> GraphKind { + return GraphKind.pie(PieGraph(units: units)) } } @@ -250,7 +250,7 @@ internal struct BarGraph: GraphBase { self.textDisplayHandler = textDisplayHandler } - func view(frame: CGRect) -> GraphView? { + func view(_ frame: CGRect) -> GraphView? { return BarGraphView( frame: frame, graph: self @@ -261,7 +261,7 @@ internal struct BarGraph: GraphBase { if let f = textDisplayHandler { return f } - return { (unit, total) -> String? in String(unit.value) } + return { (unit, total) -> String? in String(describing: unit.value) } } } @@ -279,7 +279,7 @@ internal struct MultiBarGraph: GraphBase { if let f = textDisplayHandler { return f } - return { (unit, total) -> String? in String(unit.value) } + return { (unit, total) -> String? in String(describing: unit.value) } } } @@ -304,7 +304,7 @@ internal struct LineGraph: GraphBase { self.textDisplayHandler = textDisplayHandler } - func view(frame: CGRect) -> GraphView? { + func view(_ frame: CGRect) -> GraphView? { return LineGraphView(frame: frame, graph: self) } @@ -312,7 +312,7 @@ internal struct LineGraph: GraphBase { if let f = textDisplayHandler { return f } - return { (unit, total) -> String? in String(unit.value) } + return { (unit, total) -> String? in String(describing: unit.value) } } } @@ -334,7 +334,7 @@ internal struct PieGraph: GraphBase { self.textDisplayHandler = textDisplayHandler } - func view(frame: CGRect) -> GraphView? { + func view(_ frame: CGRect) -> GraphView? { return PieGraphView(frame: frame, graph: self) } @@ -344,7 +344,7 @@ internal struct PieGraph: GraphBase { } return { (unit, total) -> String? in let f = unit.value.floatValue() / total.floatValue() - return String(unit.value) + " : " + String(format: "%.0f%%", f * 100.0) + return String(describing: unit.value) + " : " + String(format: "%.0f%%", f * 100.0) } } } @@ -384,7 +384,7 @@ public struct BarGraphApperance { barWidthScale: CGFloat?, valueTextAttributes: GraphTextAttributes? ) { - self.barColor = barColor ?? DefaultColorType.Bar.color() + self.barColor = barColor ?? DefaultColorType.bar.color() self.barWidthScale = barWidthScale ?? 0.8 self.valueTextAttributes = valueTextAttributes } @@ -400,9 +400,9 @@ public struct GraphTextAttributes { textColor: UIColor?, textAlign: NSTextAlignment? ) { - self.font = font ?? UIFont.systemFontOfSize(10.0) - self.textColor = textColor ?? UIColor.grayColor() - self.textAlign = textAlign ?? .Center + self.font = font ?? UIFont.systemFont(ofSize: 10.0) + self.textColor = textColor ?? UIColor.gray + self.textAlign = textAlign ?? .center } } @@ -410,12 +410,11 @@ public struct GraphTextAttributes { -public protocol NumericType: Equatable, Comparable { - func +(lhs: Self, rhs: Self) -> Self - func -(lhs: Self, rhs: Self) -> Self - func *(lhs: Self, rhs: Self) -> Self - func /(lhs: Self, rhs: Self) -> Self - func %(lhs: Self, rhs: Self) -> Self +public protocol NumericType: Comparable { + static func +(lhs: Self, rhs: Self) -> Self + static func -(lhs: Self, rhs: Self) -> Self + static func *(lhs: Self, rhs: Self) -> Self + static func /(lhs: Self, rhs: Self) -> Self init() init(_ v: Int) } diff --git a/Graphs/GraphView.swift b/Graphs/GraphView.swift index 3a8cacf..a4de0d2 100644 --- a/Graphs/GraphView.swift +++ b/Graphs/GraphView.swift @@ -8,29 +8,29 @@ import UIKit -public class GraphView: UIView { +open class GraphView: UIView { - public var graph: Graph? { + open var graph: Graph? { didSet { self.reloadData() } } - private var barGraphConfig: BarGraphViewConfig? - private var lineGraphConfig: LineGraphViewConfig? - private var pieGraphConfig: PieGraphViewConfig? + fileprivate var barGraphConfig: BarGraphViewConfig? + fileprivate var lineGraphConfig: LineGraphViewConfig? + fileprivate var pieGraphConfig: PieGraphViewConfig? public init(frame: CGRect, graph: Graph? = nil) { self.graph = graph super.init(frame: frame) - self.backgroundColor = UIColor.clearColor() + self.backgroundColor = UIColor.clear self.reloadData() } required public init?(coder aDecoder: NSCoder) { super.init(coder: aDecoder) - self.backgroundColor = UIColor.clearColor() + self.backgroundColor = UIColor.clear self.reloadData() } @@ -41,7 +41,7 @@ public class GraphView: UIView { guard let graph = self.graph else { return } switch graph.kind { - case .Bar(let g): + case .bar(let g): if let view = g.view(self.bounds) { if let c = barGraphConfig { @@ -50,7 +50,7 @@ public class GraphView: UIView { self.addSubview(view) } - case .Line(let g): + case .line(let g): if let view = g.view(self.bounds) { if let c = lineGraphConfig { @@ -59,7 +59,7 @@ public class GraphView: UIView { self.addSubview(view) } - case .Pie(let g): + case .pie(let g): if let view = g.view(self.bounds) { if let c = pieGraphConfig { @@ -70,7 +70,7 @@ public class GraphView: UIView { } } - public override func layoutSubviews() { + open override func layoutSubviews() { super.layoutSubviews() self.subviews.forEach{ $0.frame = self.bounds @@ -80,7 +80,7 @@ public class GraphView: UIView { extension GraphView { - public func barGraphConfiguration(configuration: () -> BarGraphViewConfig) -> Self { + public func barGraphConfiguration(_ configuration: () -> BarGraphViewConfig) -> Self { self.barGraphConfig = configuration() self.subviews.forEach { (v) in if let barGraphView = v as? BarGraphView { @@ -90,7 +90,7 @@ extension GraphView { return self } - public func lineGraphConfiguration(configuration: () -> LineGraphViewConfig) -> Self { + public func lineGraphConfiguration(_ configuration: () -> LineGraphViewConfig) -> Self { self.lineGraphConfig = configuration() self.subviews.forEach { (v) in if let lineGraphView = v as? LineGraphView { @@ -100,7 +100,7 @@ extension GraphView { return self } - public func pieGraphConfiguration(configuration: () -> PieGraphViewConfig) -> Self { + public func pieGraphConfiguration(_ configuration: () -> PieGraphViewConfig) -> Self { self.pieGraphConfig = configuration() self.subviews.forEach { (v) in if let pieGraphView = v as? PieGraphView { diff --git a/Graphs/GraphsExtensions.swift b/Graphs/GraphsExtensions.swift index 58ab391..7b50212 100644 --- a/Graphs/GraphsExtensions.swift +++ b/Graphs/GraphsExtensions.swift @@ -26,32 +26,32 @@ public protocol GraphData { SequenceType -> 'Graph' object */ -extension SequenceType where Generator.Element: GraphData { +extension Sequence where Iterator.Element: GraphData { - typealias GraphDataKey = Generator.Element.GraphDataKey - typealias GraphDataValue = Generator.Element.GraphDataValue + public typealias GraphDataKey = Iterator.Element.GraphDataKey + public typealias GraphDataValue = Iterator.Element.GraphDataValue public func barGraph( - range: GraphRange? = nil, + _ range: GraphRange? = nil, textDisplayHandler: Graph.GraphTextDisplayHandler? = nil - ) -> Graph { + ) -> Graph { - return Graph(type: .Bar, data: self.map{ $0 }, range: range, textDisplayHandler: textDisplayHandler) + return Graph(type: .bar, data: self.map{ $0 }, range: range, textDisplayHandler: textDisplayHandler) } public func lineGraph( - range: GraphRange? = nil, + _ range: GraphRange? = nil, textDisplayHandler: Graph.GraphTextDisplayHandler? = nil - ) -> Graph { + ) -> Graph { - return Graph(type: .Line, data: self.map{ $0 }, range: range, textDisplayHandler: textDisplayHandler) + return Graph(type: .line, data: self.map{ $0 }, range: range, textDisplayHandler: textDisplayHandler) } public func pieGraph( - textDisplayHandler: Graph.GraphTextDisplayHandler? = nil - ) -> Graph { + _ textDisplayHandler: Graph.GraphTextDisplayHandler? = nil + ) -> Graph { - return Graph(type: .Pie, data: self.map{ $0 }, range: nil, textDisplayHandler: textDisplayHandler) + return Graph(type: .pie, data: self.map{ $0 }, range: nil, textDisplayHandler: textDisplayHandler) } } @@ -60,31 +60,31 @@ extension SequenceType where Generator.Element: GraphData { SequenceType -> 'Graph' object */ -extension SequenceType where Generator.Element: NumericType { +extension Sequence where Iterator.Element: NumericType { public func barGraph( - range: GraphRange? = nil, - textDisplayHandler: Graph.GraphTextDisplayHandler? = nil - ) -> Graph { + _ range: GraphRange? = nil, + textDisplayHandler: Graph.GraphTextDisplayHandler? = nil + ) -> Graph { - return Graph(type: .Bar, array: self.map{ $0 }, range: range, textDisplayHandler: textDisplayHandler) + return Graph(type: .bar, array: self.map{ $0 }, range: range, textDisplayHandler: textDisplayHandler) } public func lineGraph( - range: GraphRange? = nil, - textDisplayHandler: Graph.GraphTextDisplayHandler? = nil - ) -> Graph { + _ range: GraphRange? = nil, + textDisplayHandler: Graph.GraphTextDisplayHandler? = nil + ) -> Graph { - return Graph(type: .Line, array: self.map{ $0 }, range: range, textDisplayHandler: textDisplayHandler) + return Graph(type: .line, array: self.map{ $0 }, range: range, textDisplayHandler: textDisplayHandler) } public func pieGraph( - textDisplayHandler: Graph.GraphTextDisplayHandler? = nil - ) -> Graph { + _ textDisplayHandler: Graph.GraphTextDisplayHandler? = nil + ) -> Graph { - return Graph(type: .Pie, array: self.map{ $0 }, range: nil, textDisplayHandler: textDisplayHandler) + return Graph(type: .pie, array: self.map{ $0 }, range: nil, textDisplayHandler: textDisplayHandler) } } @@ -94,37 +94,37 @@ extension SequenceType where Generator.Element: NumericType { Dictionary -> 'Graph' object */ -extension CollectionType where Self: DictionaryLiteralConvertible, Self.Key: Hashable, Self.Value: NumericType, Generator.Element == (Self.Key, Self.Value) { +extension Collection where Self: ExpressibleByDictionaryLiteral, Self.Key: Hashable, Self.Value: NumericType, Iterator.Element == (Self.Key, Self.Value) { - typealias aKey = Self.Key - typealias aValue = Self.Value + public typealias aKey = Self.Key + public typealias aValue = Self.Value public func barGraph( - range: GraphRange? = nil, + _ range: GraphRange? = nil, sort: (((Self.Key, Self.Value), (Self.Key, Self.Value)) -> Bool)? = nil, textDisplayHandler: Graph.GraphTextDisplayHandler? = nil ) -> Graph { - return Graph(type: .Bar, dictionary: dict(), range: range, textDisplayHandler: textDisplayHandler) + return Graph(type: .bar, dictionary: dict(), range: range, textDisplayHandler: textDisplayHandler) } public func lineGraph( - range: GraphRange? = nil, + _ range: GraphRange? = nil, sort: (((Self.Key, Self.Value), (Self.Key, Self.Value)) -> Bool)? = nil, textDisplayHandler: Graph.GraphTextDisplayHandler? = nil ) -> Graph { - return Graph(type: .Line, dictionary: dict(), range: range, textDisplayHandler: textDisplayHandler) + return Graph(type: .line, dictionary: dict(), range: range, textDisplayHandler: textDisplayHandler) } public func pieGraph( - range: GraphRange? = nil, + _ range: GraphRange? = nil, sort: (((Self.Key, Self.Value), (Self.Key, Self.Value)) -> Bool)? = nil, textDisplayHandler: Graph.GraphTextDisplayHandler? = nil ) -> Graph { - return Graph(type: .Pie, dictionary: dict(), range: nil, textDisplayHandler: textDisplayHandler) + return Graph(type: .pie, dictionary: dict(), range: nil, textDisplayHandler: textDisplayHandler) } func dict() -> [aKey: aValue] { @@ -153,21 +153,21 @@ extension Array { } enum DefaultColorType { - case Bar, Line, BarText, LineText, PieText + case bar, line, barText, lineText, pieText func color() -> UIColor { switch self { - case .Bar: return UIColor(hex: "#4DC2AB") - case .Line: return UIColor(hex: "#FF0066") - case .BarText: return UIColor(hex: "#333333") - case .LineText: return UIColor(hex: "#333333") - case .PieText: return UIColor(hex: "#FFFFFF") + case .bar: return UIColor(hex: "#4DC2AB") + case .line: return UIColor(hex: "#FF0066") + case .barText: return UIColor(hex: "#333333") + case .lineText: return UIColor(hex: "#333333") + case .pieText: return UIColor(hex: "#FFFFFF") } } - static func pieColors(count: Int) -> [UIColor] { + static func pieColors(_ count: Int) -> [UIColor] { - func randomArray(arr: [Int]) -> [Int] { + func randomArray(_ arr: [Int]) -> [Int] { if arr.count <= 0 { return [] } @@ -201,26 +201,26 @@ public extension UIColor { let prefixHex = {(str) -> String in for prefix in ["0x", "0X", "#"] { if str.hasPrefix(prefix) { - return str.substringFromIndex(str.startIndex.advancedBy(prefix.characters.count)) + return String(str[str.index(str.startIndex, offsetBy: prefix.count)...]) } } return str }(hex) - if prefixHex.characters.count != 6 && prefixHex.characters.count != 8 { + if prefixHex.count != 6 && prefixHex.count != 8 { self.init(white: 0.0, alpha: 1.0) return } - let scanner = NSScanner(string: prefixHex) + let scanner = Scanner(string: prefixHex) var hexInt: UInt64 = 0 - if !scanner.scanHexLongLong(&hexInt) { + if !scanner.scanHexInt64(&hexInt) { self.init(white: 0.0, alpha: 1.0) return } - switch prefixHex.characters.count { + switch prefixHex.count { case 6: self.init(RGBInt: hexInt) case 8: @@ -251,15 +251,13 @@ public extension UIEdgeInsets { extension NSAttributedString { - class func graphAttributedString(string: String, color: UIColor, font: UIFont) -> NSAttributedString { + class func graphAttributedString(_ string: String, color: UIColor, font: UIFont) -> NSAttributedString { let paragraph = NSMutableParagraphStyle() - paragraph.alignment = .Center + paragraph.alignment = .center - return NSAttributedString(string: string, attributes: [ - NSForegroundColorAttributeName:color, - NSFontAttributeName: font, - NSParagraphStyleAttributeName: paragraph - ]) + return NSMutableAttributedString( + string: string, + attributes: [NSFontAttributeName: font, NSForegroundColorAttributeName: color, NSParagraphStyleAttributeName: paragraph]) } } diff --git a/Graphs/LineGraphView.swift b/Graphs/LineGraphView.swift index 0bfc6b6..8c6745c 100644 --- a/Graphs/LineGraphView.swift +++ b/Graphs/LineGraphView.swift @@ -27,24 +27,24 @@ public struct LineGraphViewConfig { dotDiameter: CGFloat? = nil, contentInsets: UIEdgeInsets? = nil ) { - self.lineColor = lineColor ?? DefaultColorType.Line.color() + self.lineColor = lineColor ?? DefaultColorType.line.color() self.lineWidth = lineWidth ?? 3.0 - self.textColor = textColor ?? DefaultColorType.LineText.color() - self.textFont = textFont ?? UIFont.systemFontOfSize(10.0) + self.textColor = textColor ?? DefaultColorType.lineText.color() + self.textFont = textFont ?? UIFont.systemFont(ofSize: 10.0) self.dotEnable = true self.dotDiameter = dotDiameter ?? 10.0 - self.contentInsets = contentInsets ?? UIEdgeInsetsZero + self.contentInsets = contentInsets ?? UIEdgeInsets.zero } } internal class LineGraphView: UIView { - private var graph: LineGraph? - private var config: LineGraphViewConfig + fileprivate var graph: LineGraph? + fileprivate var config: LineGraphViewConfig var lineColor: UIColor? = nil { didSet { - self.config.lineColor = lineColor ?? DefaultColorType.Line.color() + self.config.lineColor = lineColor ?? DefaultColorType.line.color() self.setNeedsDisplay() } } @@ -53,17 +53,21 @@ internal class LineGraphView: UIView { self.config = LineGraphViewConfig() super.init(frame: frame) - self.backgroundColor = UIColor.clearColor() + self.backgroundColor = UIColor.clear self.graph = graph } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } - func setLineGraphViewConfig(config: LineGraphViewConfig?) { + func setLineGraphViewConfig(_ config: LineGraphViewConfig?) { self.config = config ?? LineGraphViewConfig() self.setNeedsDisplay() } - override func drawRect(rect: CGRect) { - super.drawRect(rect) + override func draw(_ rect: CGRect) { + super.draw(rect) guard let lineGraph = self.graph else { return } let rect = self.graphFrame() @@ -72,34 +76,34 @@ internal class LineGraphView: UIView { let ps = self.points(lineGraph, rect: rect) let context = UIGraphicsGetCurrentContext() - CGContextSetStrokeColorWithColor(context, config.lineColor.CGColor ?? UIColor.blackColor().CGColor) - CGContextSetLineWidth(context, self.config.lineWidth) + context?.setStrokeColor(config.lineColor.cgColor) + context?.setLineWidth(self.config.lineWidth) ps.forEach({point in if point == ps.first { - CGContextMoveToPoint(context, point.x, point.y) + context?.move(to: CGPoint(x: point.x, y: point.y)) } else { - CGContextAddLineToPoint(context, point.x, point.y) - CGContextStrokePath(context) - CGContextMoveToPoint(context, point.x, point.y) + context?.addLine(to: CGPoint(x: point.x, y: point.y)) + context?.strokePath() + context?.move(to: CGPoint(x: point.x, y: point.y)) } }) - CGContextSetLineWidth(context, 0.0) - CGContextSetFillColorWithColor(context, config.lineColor.CGColor ?? UIColor.blackColor().CGColor) + context?.setLineWidth(0.0) + context?.setFillColor(config.lineColor.cgColor) if self.config.dotEnable { ps.forEach({point in let r = CGRect(x: point.x - CGFloat(self.config.dotDiameter / 2.0), y: point.y - CGFloat(self.config.dotDiameter / 2.0), width: CGFloat(self.config.dotDiameter), height: CGFloat(self.config.dotDiameter)) - CGContextStrokeEllipseInRect(context, r) - CGContextFillEllipseInRect(context, r) + context?.strokeEllipse(in: r) + context?.fillEllipse(in: r) }) } zip(lineGraph.units, ps).forEach { (u, p) in - guard let str = self.graph?.graphTextDisplay()(unit: u, totalValue: total) else { + guard let str = self.graph?.graphTextDisplay()(u, total) else { return } @@ -107,8 +111,8 @@ internal class LineGraphView: UIView { let size = attrStr.size() - attrStr.drawInRect( - CGRect( + attrStr.draw( + in: CGRect( origin: CGPoint( x: p.x - sectionWidth / 2.0, y: u.value >= U(0) @@ -124,7 +128,7 @@ internal class LineGraphView: UIView { } } - private func graphFrame() -> CGRect { + fileprivate func graphFrame() -> CGRect { return CGRect( x: self.config.contentInsets.left, y: self.config.contentInsets.top, @@ -133,11 +137,11 @@ internal class LineGraphView: UIView { ) } - private func points(graph: LineGraph, rect: CGRect) -> [CGPoint] { + fileprivate func points(_ graph: LineGraph, rect: CGRect) -> [CGPoint] { let sectionWidth = rect.width / CGFloat(graph.units.count) - return graph.units.enumerate().map { + return graph.units.enumerated().map { CGPoint( x: CGFloat($0) * sectionWidth + (sectionWidth / 2.0) + rect.origin.x, y: rect.size.height - rect.size.height * CGFloat(($1.value - graph.range.min).floatValue() / (graph.range.max - graph.range.min).floatValue()) + rect.origin.y diff --git a/Graphs/MultiBarGraphView.swift b/Graphs/MultiBarGraphView.swift index 975c9a3..c189dc7 100644 --- a/Graphs/MultiBarGraphView.swift +++ b/Graphs/MultiBarGraphView.swift @@ -10,10 +10,10 @@ import UIKit class MultiBarGraphView: UIView { - private var scrollView: UIScrollView! + fileprivate var scrollView: UIScrollView! - private var graph: MultiBarGraph? - private var config: MultiBarGraphViewConfig + fileprivate var graph: MultiBarGraph? + fileprivate var config: MultiBarGraphViewConfig init(frame: CGRect, graph: MultiBarGraph?, viewConfig: MultiBarGraphViewConfig? = nil) { @@ -25,6 +25,10 @@ class MultiBarGraphView: UIView { ) self.addSubview(self.scrollView) } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } } struct MultiBarGraphViewConfig { @@ -38,7 +42,7 @@ struct MultiBarGraphViewConfig { barWidthScale: CGFloat? = nil, sectionWidth: CGFloat? = nil ) { - self.barColors = barColors ?? [DefaultColorType.Bar.color()] + self.barColors = barColors ?? [DefaultColorType.bar.color()] self.barWidthScale = barWidthScale ?? 0.8 self.sectionWidth = sectionWidth } diff --git a/Graphs/PieGraphView.swift b/Graphs/PieGraphView.swift index 5f6b1e1..b9bb067 100644 --- a/Graphs/PieGraphView.swift +++ b/Graphs/PieGraphView.swift @@ -24,53 +24,58 @@ public struct PieGraphViewConfig { contentInsets: UIEdgeInsets? = nil ) { self.pieColors = pieColors - self.textColor = textColor ?? DefaultColorType.PieText.color() - self.textFont = textFont ?? UIFont.systemFontOfSize(10.0) + self.textColor = textColor ?? DefaultColorType.pieText.color() + self.textFont = textFont ?? UIFont.systemFont(ofSize: 10.0) self.isDounut = isDounut - self.contentInsets = contentInsets ?? UIEdgeInsetsZero + self.contentInsets = contentInsets ?? UIEdgeInsets.zero } } internal class PieGraphView: UIView { - private var graph: PieGraph? { + fileprivate var graph: PieGraph? { didSet { self.config.pieColors = DefaultColorType.pieColors(graph?.units.count ?? 0) self.setNeedsDisplay() } } - private var config: PieGraphViewConfig + fileprivate var config: PieGraphViewConfig init(frame: CGRect, graph: PieGraph?) { self.config = PieGraphViewConfig(pieColors: DefaultColorType.pieColors(graph?.units.count ?? 0)) super.init(frame: frame) - self.backgroundColor = UIColor.clearColor() + self.backgroundColor = UIColor.clear self.graph = graph } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } - func setPieGraphViewConfig(config: PieGraphViewConfig?) { + func setPieGraphViewConfig(_ config: PieGraphViewConfig?) { self.config = config ?? PieGraphViewConfig() self.setNeedsDisplay() } - - override func drawRect(rect: CGRect) { - super.drawRect(rect) - - guard let graph = self.graph else { return } - - func convert(s: S, arr: [S], f: (S) -> S) -> [S] { - switch arr.match { - case let .Some(h, t): return [f(h) + s] + convert(h + s, arr:t, f: f) - case .None: return [] - } + + // This generic function has to be put outside of "draw(_ rect: CGRect)", to avoid Swift compiler segmentation fault 11 + func convert(_ s: S, arr: [S], f: (S) -> S) -> [S] { + switch arr.match { + case let .some(h, t): return [(f(h) + s) as S] + convert(h + s, arr:t, f: f) + case .none: return [] } + } + + override func draw(_ rect: CGRect) { + super.draw(rect) + guard let graph = self.graph else { return } + let colors = self.config.pieColors ?? DefaultColorType.pieColors(graph.units.count) - + let values = graph.units.map({ max($0.value, U(0)) }) - let total = values.reduce(U(0), combine: { $0 + $1 }) + let total = values.reduce(U(0), { $0 + $1 }) let percentages = values.map({ Double($0.floatValue() / total.floatValue()) }) let rect = self.graphFrame() @@ -81,49 +86,49 @@ internal class PieGraphView: UIView { let radius = min(rect.width, rect.height) / 2.0 let centers = convert(0.0, arr: percentages) { $0 / 2.0 }.map { (c) -> CGPoint in - let angle = M_PI * 2.0 * c - M_PI / 2.0 + let angle = .pi * 2.0 * c - .pi / 2.0 return CGPoint( x: Double(x) + cos(angle) * Double(radius * 3.0 / 4.0), y: Double(y) + sin(angle) * Double(radius * 3.0 / 4.0) ) } - var startAngle = -M_PI / 2.0 + var startAngle = -.pi / 2.0 - percentages.enumerate().forEach { (index, f) in - let endAngle = startAngle + M_PI * 2.0 * f - CGContextMoveToPoint(context, x, y); - CGContextAddArc(context, x, y, radius, CGFloat(startAngle), CGFloat(endAngle), 0); + percentages.enumerated().forEach { (index, f) in + let endAngle = startAngle + .pi * 2.0 * f + context?.move(to: CGPoint(x: x, y: y)); + context?.addArc(center: CGPoint(x: x, y: y), radius: radius, startAngle: CGFloat(startAngle), endAngle: CGFloat(endAngle), clockwise: false) if self.config.isDounut { - CGContextAddArc(context, x, y, radius/2, CGFloat(endAngle), CGFloat(startAngle), 1) + context?.addArc(center: CGPoint(x: x, y: y), radius: radius/2, startAngle: CGFloat(endAngle), endAngle: CGFloat(startAngle), clockwise: true) } - CGContextSetFillColor(context, CGColorGetComponents( colors[index].CGColor )) - CGContextClosePath(context); - CGContextFillPath(context); + if let comps = colors[index].cgColor.components { + context?.setFillColor(comps) + } + context?.closePath(); + context?.fillPath(); startAngle = endAngle } zip(graph.units, centers).forEach { (u, center) in - guard let str = self.graph?.graphTextDisplay()(unit: u, totalValue: total) else { + guard let str = self.graph?.graphTextDisplay()(u, total) else { return } let paragraph = NSMutableParagraphStyle() - paragraph.alignment = .Center + paragraph.alignment = .center - let attrStr = NSAttributedString(string: str, attributes: [ - NSForegroundColorAttributeName:self.config.textColor, - NSFontAttributeName: UIFont.systemFontOfSize(10.0), - NSParagraphStyleAttributeName: paragraph - ]) + let attrStr = NSMutableAttributedString( + string: str, + attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 10.0), NSForegroundColorAttributeName: self.config.textColor, NSParagraphStyleAttributeName: paragraph]) let size = attrStr.size() - attrStr.drawInRect( - CGRect( + attrStr.draw( + in: CGRect( origin: CGPoint( x: center.x - size.width / 2.0, y: center.y - size.height / 2.0 @@ -134,7 +139,7 @@ internal class PieGraphView: UIView { } } - private func graphFrame() -> CGRect { + fileprivate func graphFrame() -> CGRect { return CGRect( x: self.config.contentInsets.left, y: self.config.contentInsets.top, diff --git a/GraphsExample/GraphsExample.xcodeproj/project.pbxproj b/GraphsExample/GraphsExample.xcodeproj/project.pbxproj index 66c05fc..955216c 100644 --- a/GraphsExample/GraphsExample.xcodeproj/project.pbxproj +++ b/GraphsExample/GraphsExample.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 974E409B1F3C36BC5D841350 /* Pods_GraphsExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8F49A1ECEBF7A92816B652F8 /* Pods_GraphsExample.framework */; }; + 997732406C40FD3614D32C96 /* Pods_GraphsExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 151EB9703E3E799C3FE91973 /* Pods_GraphsExample.framework */; }; E92069AC1CFC3D200025DBC8 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = E92069AB1CFC3D200025DBC8 /* AppDelegate.swift */; }; E92069B11CFC3D200025DBC8 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E92069AF1CFC3D200025DBC8 /* Main.storyboard */; }; E92069B31CFC3D200025DBC8 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E92069B21CFC3D200025DBC8 /* Assets.xcassets */; }; @@ -28,9 +28,8 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 4227E7448AC62671208299D7 /* Pods-GraphsExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GraphsExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GraphsExample/Pods-GraphsExample.debug.xcconfig"; sourceTree = ""; }; - 648833EF53F9A4F7C44598BB /* Pods-GraphsExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GraphsExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-GraphsExample/Pods-GraphsExample.release.xcconfig"; sourceTree = ""; }; - 8F49A1ECEBF7A92816B652F8 /* Pods_GraphsExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GraphsExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 151EB9703E3E799C3FE91973 /* Pods_GraphsExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_GraphsExample.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 465F0ABDDEF4C02C753CE97A /* Pods-GraphsExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GraphsExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-GraphsExample/Pods-GraphsExample.debug.xcconfig"; sourceTree = ""; }; E92069A81CFC3D200025DBC8 /* GraphsExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GraphsExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; E92069AB1CFC3D200025DBC8 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; E92069B01CFC3D200025DBC8 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; @@ -42,6 +41,7 @@ E92069C21CFC3D200025DBC8 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; E961AAE51D1245C400B4D5A7 /* GraphCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GraphCollectionViewCell.swift; sourceTree = ""; }; E97D788E1D112F8F00F4F8CF /* MainViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MainViewController.swift; sourceTree = ""; }; + EE1A0FF102CF6F40687D38D2 /* Pods-GraphsExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-GraphsExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-GraphsExample/Pods-GraphsExample.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -49,7 +49,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 974E409B1F3C36BC5D841350 /* Pods_GraphsExample.framework in Frameworks */, + 997732406C40FD3614D32C96 /* Pods_GraphsExample.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -63,21 +63,21 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ - 29D120C267599379DAEF37A8 /* Frameworks */ = { + 22CB99AD1E7F847B621ADBE5 /* Pods */ = { isa = PBXGroup; children = ( - 8F49A1ECEBF7A92816B652F8 /* Pods_GraphsExample.framework */, + 465F0ABDDEF4C02C753CE97A /* Pods-GraphsExample.debug.xcconfig */, + EE1A0FF102CF6F40687D38D2 /* Pods-GraphsExample.release.xcconfig */, ); - name = Frameworks; + name = Pods; sourceTree = ""; }; - 8AFFCF1B50DBACE8319B88C4 /* Pods */ = { + A90BA0B16C5C466CEE0A0869 /* Frameworks */ = { isa = PBXGroup; children = ( - 4227E7448AC62671208299D7 /* Pods-GraphsExample.debug.xcconfig */, - 648833EF53F9A4F7C44598BB /* Pods-GraphsExample.release.xcconfig */, + 151EB9703E3E799C3FE91973 /* Pods_GraphsExample.framework */, ); - name = Pods; + name = Frameworks; sourceTree = ""; }; E920699F1CFC3D200025DBC8 = { @@ -86,8 +86,8 @@ E92069AA1CFC3D200025DBC8 /* GraphsExample */, E92069BF1CFC3D200025DBC8 /* GraphsExampleTests */, E92069A91CFC3D200025DBC8 /* Products */, - 8AFFCF1B50DBACE8319B88C4 /* Pods */, - 29D120C267599379DAEF37A8 /* Frameworks */, + 22CB99AD1E7F847B621ADBE5 /* Pods */, + A90BA0B16C5C466CEE0A0869 /* Frameworks */, ); sourceTree = ""; }; @@ -130,13 +130,11 @@ isa = PBXNativeTarget; buildConfigurationList = E92069C51CFC3D210025DBC8 /* Build configuration list for PBXNativeTarget "GraphsExample" */; buildPhases = ( - 238EE3CEB76B45FE11A50757 /* [CP] Check Pods Manifest.lock */, + 65C4C7FE5F71C5549E3AAC37 /* [CP] Check Pods Manifest.lock */, E92069A41CFC3D200025DBC8 /* Sources */, E92069A51CFC3D200025DBC8 /* Frameworks */, E92069A61CFC3D200025DBC8 /* Resources */, - 757FB9C9151E3B788984CFB0 /* [CP] Embed Pods Frameworks */, - 17985833460BB9F83DF0E125 /* [CP] Copy Pods Resources */, - 406E61D919A0A9E11D6F2F3E /* Embed Pods Frameworks */, + 94B11597A60E31C8C2A3F286 /* [CP] Embed Pods Frameworks */, ); buildRules = ( ); @@ -172,14 +170,17 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0730; - LastUpgradeCheck = 0730; + LastUpgradeCheck = 0940; ORGANIZATIONNAME = "Recruit Holdings Co., Ltd."; TargetAttributes = { E92069A71CFC3D200025DBC8 = { CreatedOnToolsVersion = 7.3.1; + LastSwiftMigration = 0800; }; E92069BB1CFC3D200025DBC8 = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = RT4NRJPHW3; + LastSwiftMigration = 0800; TestTargetID = E92069A71CFC3D200025DBC8; }; }; @@ -224,60 +225,36 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ - 17985833460BB9F83DF0E125 /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "[CP] Copy Pods Resources"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-GraphsExample/Pods-GraphsExample-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; - 238EE3CEB76B45FE11A50757 /* [CP] Check Pods Manifest.lock */ = { + 65C4C7FE5F71C5549E3AAC37 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-GraphsExample-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; - showEnvVarsInLog = 0; - }; - 406E61D919A0A9E11D6F2F3E /* Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputPaths = ( - ); - name = "Embed Pods Frameworks"; - outputPaths = ( - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-GraphsExample/Pods-GraphsExample-frameworks.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; - 757FB9C9151E3B788984CFB0 /* [CP] Embed Pods Frameworks */ = { + 94B11597A60E31C8C2A3F286 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${SRCROOT}/Pods/Target Support Files/Pods-GraphsExample/Pods-GraphsExample-frameworks.sh", + "${BUILT_PRODUCTS_DIR}/Graphs/Graphs.framework", ); name = "[CP] Embed Pods Frameworks"; outputPaths = ( + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/Graphs.framework", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; @@ -344,13 +321,23 @@ 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_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -390,13 +377,23 @@ 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_DEPRECATED_OBJC_IMPLEMENTATIONS = 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_IMPLICIT_RETAIN_SELF = 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; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; @@ -415,6 +412,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 9.3; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; + SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; }; @@ -422,27 +420,33 @@ }; E92069C61CFC3D210025DBC8 /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 4227E7448AC62671208299D7 /* Pods-GraphsExample.debug.xcconfig */; + baseConfigurationReference = 465F0ABDDEF4C02C753CE97A /* Pods-GraphsExample.debug.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GraphsExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.mtl.GraphsExample; + PRODUCT_BUNDLE_IDENTIFIER = come.example.GraphsExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Debug; }; E92069C71CFC3D210025DBC8 /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = 648833EF53F9A4F7C44598BB /* Pods-GraphsExample.release.xcconfig */; + baseConfigurationReference = EE1A0FF102CF6F40687D38D2 /* Pods-GraphsExample.release.xcconfig */; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = GraphsExample/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; - PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.mtl.GraphsExample; + PRODUCT_BUNDLE_IDENTIFIER = come.example.GraphsExample; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -450,10 +454,12 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + DEVELOPMENT_TEAM = RT4NRJPHW3; INFOPLIST_FILE = GraphsExampleTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.mtl.GraphsExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GraphsExample.app/GraphsExample"; }; name = Debug; @@ -462,10 +468,12 @@ isa = XCBuildConfiguration; buildSettings = { BUNDLE_LOADER = "$(TEST_HOST)"; + DEVELOPMENT_TEAM = RT4NRJPHW3; INFOPLIST_FILE = GraphsExampleTests/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = jp.co.recruit.mtl.GraphsExampleTests; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/GraphsExample.app/GraphsExample"; }; name = Release; diff --git a/GraphsExample/GraphsExample/AppDelegate.swift b/GraphsExample/GraphsExample/AppDelegate.swift index f6e1480..cd5f4c6 100644 --- a/GraphsExample/GraphsExample/AppDelegate.swift +++ b/GraphsExample/GraphsExample/AppDelegate.swift @@ -13,31 +13,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - - func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { - // Override point for customization after application launch. + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey : Any]? = nil) -> Bool { return true } - func applicationWillResignActive(application: UIApplication) { + func applicationWillResignActive(_ application: UIApplication) { // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. } - func applicationDidEnterBackground(application: UIApplication) { + func applicationDidEnterBackground(_ application: UIApplication) { // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. } - func applicationWillEnterForeground(application: UIApplication) { + func applicationWillEnterForeground(_ application: UIApplication) { // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. } - func applicationDidBecomeActive(application: UIApplication) { + func applicationDidBecomeActive(_ application: UIApplication) { // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. } - func applicationWillTerminate(application: UIApplication) { + func applicationWillTerminate(_ application: UIApplication) { // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. } diff --git a/GraphsExample/GraphsExample/MainViewController.swift b/GraphsExample/GraphsExample/MainViewController.swift index 659e2bf..59f1a7b 100644 --- a/GraphsExample/GraphsExample/MainViewController.swift +++ b/GraphsExample/GraphsExample/MainViewController.swift @@ -31,41 +31,39 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec @IBOutlet private var collectionView: UICollectionView! - override func viewWillAppear(animated: Bool) { + override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) self.navigationController?.setNavigationBarHidden(true, animated: animated) } - override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) { + override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) { self.collectionView.reloadData() } - override func willTransitionToTraitCollection(newCollection: UITraitCollection, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { - super.willTransitionToTraitCollection(newCollection, withTransitionCoordinator: coordinator) + override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) { + super.willTransition(to: newCollection, with: coordinator) self.collectionView.reloadData() } - - override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { - super.viewWillTransitionToSize(size, withTransitionCoordinator: coordinator) + + override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransition(to: size, with: coordinator) self.collectionView.reloadData() } - // MARK: - UICollectionViewDataSource - - func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { + func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } - - func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return GraphExampleType.count() } - - func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { + + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { - let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! GraphCollectionViewCell + let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! GraphCollectionViewCell cell.graphView.subviews.forEach({ $0.removeFromSuperview() }) @@ -73,7 +71,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec case .BarGraph1: let view = (1 ... 10).barGraph(GraphRange(min: 0, max: 11)).view(cell.graphView.bounds) - view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cell.graphView.addSubview(view) cell.label.text = "let view = (1 ... 10).barGraph(GraphRange(min: 0, max: 11)).view(cell.graphView.bounds)" @@ -81,7 +79,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec case .BarGraph2: let view = [8, 12, 20, -10, 6, 20, -11, 9, 12, 16, -10, 6, 20, -12].barGraph().view(cell.graphView.bounds).barGraphConfiguration({ BarGraphViewConfig(barColor: UIColor(hex: "#ff6699"), contentInsets: UIEdgeInsets(top: 16.0, left: 16.0, bottom: 16.0, right: 16.0)) }) - view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cell.graphView.addSubview(view) cell.label.text = "[8, 12, 20, -10, 6, 20, -11, 9, 12, 16, -10, 6, 20, -12].barGraph().view(cell.graphView.bounds).barGraphConfiguration({ BarGraphViewConfig(barColor: UIColor(hex: \"#ff6699\"), contentInsets: UIEdgeInsets(top: 16.0, left: 16.0, bottom: 16.0, right: 16.0)) })" @@ -89,7 +87,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec case .BarGraph3: let view = [8.0, 12.0, 20.0, 10.0, 6.0, 20.0, 11.0, 9.0, 12.0, 16.0, 10.0, 6.0, 20.0].barGraph(GraphRange(min: 0, max: 25)).view(cell.graphView.bounds).barGraphConfiguration({ BarGraphViewConfig(barColor: UIColor(hex: "#ccff66"), barWidthScale: 0.4) }) - view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cell.graphView.addSubview(view) cell.label.text = "let view = [8.0, 12.0, 20.0, 10.0, 6.0, 20.0, 11.0, 9.0, 12.0, 16.0, 10.0, 6.0, 20.0].barGraph(GraphRange(min: 0, max: 25)).view(cell.graphView.bounds).barGraphConfiguration({ BarGraphViewConfig(barColor: UIColor(hex: \"#ccff66\"), barWidthScale: 0.4) })" @@ -97,7 +95,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec case .LineGraph1: let view = (1 ... 10).lineGraph(GraphRange(min: 0, max: 11)).view(cell.graphView.bounds) - view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cell.graphView.addSubview(view) cell.label.text = "let view = (1 ... 10).lineGraph(GraphRange(min: 0, max: 11)).view(cell.graphView.bounds)" @@ -105,7 +103,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec case .LineGraph2: let view = [8, 12, 20, -10, 6, 20, -11, 9, 12, 16, -10, 6, 20, -12].lineGraph().view(cell.graphView.bounds).lineGraphConfiguration({ LineGraphViewConfig(lineColor: UIColor(hex: "#ff6699"), contentInsets: UIEdgeInsets(top: 32.0, left: 32.0, bottom: 32.0, right: 32.0)) }) - view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cell.graphView.addSubview(view) cell.label.text = "[8, 12, 20, -10, 6, 20, -11, 9, 12, 16, -10, 6, 20, -12].lineGraph().view(cell.graphView.bounds).lineGraphConfiguration({ LineGraphViewConfig(lineColor: UIColor(hex: \"#ff6699\"), contentInsets: UIEdgeInsets(top: 32.0, left: 32.0, bottom: 32.0, right: 32.0)) })" @@ -113,7 +111,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec case .LineGraph3: let view = [8.0, 12.0, 20.0, 10.0, 6.0, 20.0, 11.0, 9.0, 12.0, 16.0, 10.0, 6.0, 20.0].lineGraph(GraphRange(min: 0, max: 25)).view(cell.graphView.bounds).lineGraphConfiguration({ LineGraphViewConfig(lineColor: UIColor(hex: "#ccff33"), lineWidth: 2.0, dotDiameter: 20.0) }) - view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cell.graphView.addSubview(view) cell.label.text = "[8.0, 12.0, 20.0, 10.0, 6.0, 20.0, 11.0, 9.0, 12.0, 16.0, 10.0, 6.0, 20.0].lineGraph(GraphRange(min: 0, max: 25)).view(cell.graphView.bounds).lineGraphConfiguration({ LineGraphViewConfig(lineColor: UIColor(hex: \"#ccff66\"), lineWidth: 1.0, dotDiameter: 10.0) })" @@ -121,7 +119,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec case .PieGraph1: let view = (5 ... 10).pieGraph().view(cell.graphView.bounds) - view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cell.graphView.addSubview(view) cell.label.text = "(5 ... 10).pieGraph().view(cell.graphView.bounds)" @@ -129,7 +127,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec case .PieGraph2: let view = [8, 12, 20, 6, 20, 11, 9].pieGraph(){ (u, t) -> String? in String(format: "%.0f%%", (Float(u.value) / Float(t)))}.view(cell.graphView.bounds).pieGraphConfiguration({ PieGraphViewConfig(textFont: UIFont(name: "DINCondensed-Bold", size: 14.0), isDounut: true, contentInsets: UIEdgeInsets(top: 16.0, left: 16.0, bottom: 16.0, right: 16.0)) }) - view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cell.graphView.addSubview(view) cell.label.text = "[8, 12, 20, 6, 20, 11, 9].pieGraph(){ (u, t) -> String? in String(format: \"%.0f%%\", (Float(u.value) / Float(t)))}.view(cell.graphView.bounds).pieGraphConfiguration({ PieGraphViewConfig(textFont: UIFont(name: \"DINCondensed-Bold\", size: 14.0), isDounut: true, contentInsets: UIEdgeInsets(top: 16.0, left: 16.0, bottom: 16.0, right: 16.0)) })" @@ -137,7 +135,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec case .PieGraph3: let view = [8.5, 20.0].pieGraph(){ (u, t) -> String? in String(format: "%.0f%%", (Float(u.value) / Float(t)))}.view(cell.graphView.bounds).pieGraphConfiguration({ PieGraphViewConfig(textFont: UIFont(name: "DINCondensed-Bold", size: 14.0), isDounut: true, contentInsets: UIEdgeInsets(top: 16.0, left: 16.0, bottom: 16.0, right: 16.0)) }) - view.autoresizingMask = [.FlexibleWidth, .FlexibleHeight] + view.autoresizingMask = [.flexibleWidth, .flexibleHeight] cell.graphView.addSubview(view) cell.label.text = "[8.5, 20.0].pieGraph(){ (u, t) -> String? in String(format: \"%.0f%%\", (Float(u.value) / Float(t)))}.view(cell.graphView.bounds).pieGraphConfiguration({ PieGraphViewConfig(textFont: UIFont(name: \"DINCondensed-Bold\", size: 14.0), isDounut: true, contentInsets: UIEdgeInsets(top: 16.0, left: 16.0, bottom: 16.0, right: 16.0)) })" @@ -149,11 +147,11 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec // MARK: - UICollectionViewDelegate - func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView { + func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { switch kind { case UICollectionElementKindSectionHeader: - let view = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: "Header", forIndexPath: indexPath) + let view = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: "Header", for: indexPath) return view case _: return UICollectionReusableView() @@ -162,12 +160,12 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec private let cellMargin = CGFloat(8.0) - func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - let regularCollection = UITraitCollection(horizontalSizeClass: .Regular) + let regularCollection = UITraitCollection(horizontalSizeClass: .regular) - let horizontalCellCount = self.traitCollection.containsTraitsInCollection(regularCollection) ? 2 : 1 + let horizontalCellCount = self.traitCollection.containsTraits(in: regularCollection) ? 2 : 1 let width = (collectionView.frame.size.width - cellMargin * CGFloat(horizontalCellCount + 1)) / CGFloat(horizontalCellCount) return CGSize( @@ -176,7 +174,7 @@ class MainViewController: UIViewController, UICollectionViewDataSource, UICollec ) } - func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { + func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize { return CGSize(width: collectionView.frame.size.width, height: 120.0) } diff --git a/GraphsExample/Podfile.lock b/GraphsExample/Podfile.lock index 07f8850..fac2e6c 100644 --- a/GraphsExample/Podfile.lock +++ b/GraphsExample/Podfile.lock @@ -1,5 +1,5 @@ PODS: - - Graphs (0.1.0) + - Graphs (0.1.2) DEPENDENCIES: - Graphs (from `..`) @@ -9,6 +9,8 @@ EXTERNAL SOURCES: :path: ".." SPEC CHECKSUMS: - Graphs: 86c8882eff318c40ed092790116aaa8d23d52676 + Graphs: 20ab93a2d97bc48e885d98ca08ceee9b9323fc26 -COCOAPODS: 0.39.0 +PODFILE CHECKSUM: 44a93f406ae068a7c552ed78b7f4276e3e8546e0 + +COCOAPODS: 1.5.3