Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgraded to Swift 4, Fixed Example, Fixed strings (working with Xcode Version 9.4 (9F1027a)) #16

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -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"
44 changes: 41 additions & 3 deletions Graphs.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
};
};
Expand Down Expand Up @@ -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";
Expand Down Expand Up @@ -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";
Expand All @@ -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";
Expand All @@ -369,42 +392,51 @@
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;
};
E92069981CFC20840025DBC8 /* Release */ = {
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",
Expand All @@ -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",
Expand All @@ -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;
};
Expand Down
4 changes: 3 additions & 1 deletion Graphs.xcodeproj/xcshareddata/xcschemes/Graphs.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0730"
LastUpgradeVersion = "0900"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -26,6 +26,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand Down Expand Up @@ -55,6 +56,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
44 changes: 24 additions & 20 deletions Graphs/BarGraphView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import UIKit

public enum GraphColorType {
case
Mat(UIColor),
Gradation(UIColor, UIColor)
mat(UIColor),
gradation(UIColor, UIColor)
}

extension UIColor {

func matColor() -> GraphColorType {
return .Mat(self)
return .mat(self)
}
}

Expand All @@ -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
}
}

Expand All @@ -56,24 +56,28 @@ internal class BarGraphView<T: Hashable, U: NumericType>: UIView {

internal var graph: BarGraph<T, U>?

private var config = BarGraphViewConfig()
fileprivate var config = BarGraphViewConfig()

init(frame: CGRect, graph: BarGraph<T, U>?) {

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,
Expand All @@ -82,8 +86,8 @@ internal class BarGraphView<T: Hashable, U: NumericType>: UIView {
)
}

override func drawRect(rect: CGRect) {
super.drawRect(rect)
override func draw(_ rect: CGRect) {
super.draw(rect)

guard let graph = self.graph else { return }

Expand All @@ -97,11 +101,11 @@ internal class BarGraphView<T: Hashable, U: NumericType>: 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
Expand Down Expand Up @@ -129,14 +133,14 @@ internal class BarGraphView<T: Hashable, U: NumericType>: 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)
Expand All @@ -152,4 +156,4 @@ internal class BarGraphView<T: Hashable, U: NumericType>: UIView {
}
})
}
}
}
Loading