diff --git a/Cartfile.private b/Cartfile.private index da82317..897faf4 100644 --- a/Cartfile.private +++ b/Cartfile.private @@ -1 +1 @@ -github "Quick/Nimble" ~> 4.1 +github "Quick/Nimble" diff --git a/Cartfile.resolved b/Cartfile.resolved index 2353900..0260062 100644 --- a/Cartfile.resolved +++ b/Cartfile.resolved @@ -1 +1 @@ -github "Quick/Nimble" "v4.1.0" +github "Quick/Nimble" "220152be528dcc0537764c179c95b8174028c80c" diff --git a/Typesetter.xcodeproj/project.pbxproj b/Typesetter.xcodeproj/project.pbxproj index 441bad9..f73c0a7 100644 --- a/Typesetter.xcodeproj/project.pbxproj +++ b/Typesetter.xcodeproj/project.pbxproj @@ -229,7 +229,6 @@ }; 536F381B1C5D11E800948324 = { CreatedOnToolsVersion = 7.2; - DevelopmentTeam = 4MJAYLR55B; LastSwiftMigration = 0800; }; }; @@ -358,6 +357,7 @@ ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALID_ARCHS = "arm64 armv7 armv7s"; VERSIONING_SYSTEM = "apple-generic"; @@ -402,6 +402,7 @@ MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; + SWIFT_VERSION = 3.0; TARGETED_DEVICE_FAMILY = "1,2"; VALIDATE_PRODUCT = YES; VERSIONING_SYSTEM = "apple-generic"; @@ -412,6 +413,7 @@ 536F38271C5D11E800948324 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = NO; CLANG_ENABLE_MODULES = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; @@ -425,18 +427,20 @@ ); INFOPLIST_FILE = Typesetter/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = studio.Typesetter; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Debug; }; 536F38281C5D11E800948324 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + APPLICATION_EXTENSION_API_ONLY = NO; CLANG_ENABLE_MODULES = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; DEFINES_MODULE = YES; @@ -450,11 +454,12 @@ ); INFOPLIST_FILE = Typesetter/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = studio.Typesetter; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Release; }; @@ -462,6 +467,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", @@ -471,7 +477,7 @@ PRODUCT_BUNDLE_IDENTIFIER = studio.TypesetterTests; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Debug; }; @@ -479,6 +485,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; + DEVELOPMENT_TEAM = ""; FRAMEWORK_SEARCH_PATHS = ( "$(inherited)", "$(PROJECT_DIR)/Carthage/Build/iOS", @@ -487,7 +494,7 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = studio.TypesetterTests; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 2.3; + SWIFT_VERSION = 3.0; }; name = Release; }; diff --git a/Typesetter/CSV.swift b/Typesetter/CSV.swift index 2c3e059..ea57c10 100644 --- a/Typesetter/CSV.swift +++ b/Typesetter/CSV.swift @@ -11,13 +11,13 @@ import Foundation class CSV { let headers: [String] let columns: [String: [String]] - private static let delimiter = NSCharacterSet(charactersInString: ",") + fileprivate static let delimiter = CharacterSet(charactersIn: ",") - private static func getColumns(headers: [String], lines: [String]) -> [String: [String]] { + fileprivate static func getColumns(_ headers: [String], lines: [String]) -> [String: [String]] { return Array(lines)[1.. 1 else { @@ -50,8 +50,8 @@ class CSV { return nil } - let headers = lines[0].componentsSeparatedByCharactersInSet(CSV.delimiter) + let headers = lines[0].components(separatedBy: CSV.delimiter) self.headers = headers self.columns = CSV.getColumns(headers, lines: lines) } -} \ No newline at end of file +} diff --git a/Typesetter/Info.plist b/Typesetter/Info.plist index d3de8ee..dfb6492 100644 --- a/Typesetter/Info.plist +++ b/Typesetter/Info.plist @@ -15,7 +15,7 @@ CFBundlePackageType FMWK CFBundleShortVersionString - 1.0 + 2.0 CFBundleSignature ???? CFBundleVersion diff --git a/Typesetter/Typesetter.swift b/Typesetter/Typesetter.swift index 98286b5..23f9918 100644 --- a/Typesetter/Typesetter.swift +++ b/Typesetter/Typesetter.swift @@ -20,25 +20,25 @@ import UIKit Where the columns headers are `TypesetterTextStyle`s and the row headers are `TypesetterFontSize`s. */ -public class Typesetter { +open class Typesetter { internal typealias TextStyleFontSizeMatrix = [TypesetterTextStyle: [TypesetterFontSize: CGFloat]] - private let configuration: TypesetterConfiguration - private let matrix: TextStyleFontSizeMatrix - private let application = UIApplication.sharedApplication() + fileprivate let configuration: TypesetterConfiguration + fileprivate let matrix: TextStyleFontSizeMatrix + fileprivate let application = UIApplication.shared /** Check if this instance of typesetter has sizes loaded. Returns `true` if this instance has successfully loaded font sizes from a file, `false` if not. */ - public var hasSizes: Bool { + open var hasSizes: Bool { return matrix.count > 0 } - private static var resourcePaths: [NSBundle: String] = [:] - private static func defaultResourcePathForBundle(bundle: NSBundle) -> String? { + fileprivate static var resourcePaths: [Bundle: String] = [:] + fileprivate static func defaultResourcePathForBundle(_ bundle: Bundle) -> String? { if let path = resourcePaths[bundle] { return path - } else if let path = bundle.pathForResource("FontSizes", ofType: "csv") { + } else if let path = bundle.path(forResource: "FontSizes", ofType: "csv") { resourcePaths[bundle] = path return path } @@ -51,7 +51,7 @@ public class Typesetter { - Parameter bundle: The bundle in which to look for the file named `FontSizes.csv` */ - public convenience init(bundle: NSBundle) { + public convenience init(bundle: Bundle) { guard let path = Typesetter.defaultResourcePathForBundle(bundle) else { self.init(configuration: TypesetterConfiguration(sizeDefinitionsPath: "NoPath")) return @@ -79,8 +79,15 @@ public class Typesetter { - textStyle: The `TypesetterTextStyle` text style to return the `UIFont` instance for - font: The `TypesetterFont` to return the `UIFont` with. */ - public func sizedFontFor(textStyle: TypesetterTextStyle, font: TypesetterFont) -> UIFont { - let size = TypesetterFontSize(contentSize: application.preferredContentSizeCategory) + open func sizedFontFor(_ textStyle: TypesetterTextStyle, font: TypesetterFont) -> UIFont { + + var preferrredContentSize = UIContentSizeCategory.medium + + if UIApplication.shared.responds(to: #selector(getter: UIApplication.preferredContentSizeCategory)) { + preferrredContentSize = UIApplication.shared.preferredContentSizeCategory + } + + let size = TypesetterFontSize(contentSize: preferrredContentSize) let pointSize = sizeFor(size: size, textStyle: textStyle) return UIFont(descriptor: descriptorFor(textStyle, size: size, font: font), size: pointSize) @@ -93,18 +100,18 @@ public class Typesetter { - textStyle: The text style as a string to return the `UIFont` instance for - font: The `TypesetterFont` to return the `UIFont` with. */ - public func sizedFontFor(textStyle: String, font: TypesetterFont) -> UIFont { + open func sizedFontFor(_ textStyle: String, font: TypesetterFont) -> UIFont { let style = TypesetterTextStyle(rawValue: textStyle) ?? .Body return sizedFontFor(style, font: font) } - private func descriptorFor(textStyle: TypesetterTextStyle, size: TypesetterFontSize, font: TypesetterFont) -> UIFontDescriptor { + fileprivate func descriptorFor(_ textStyle: TypesetterTextStyle, size: TypesetterFontSize, font: TypesetterFont) -> UIFontDescriptor { return UIFontDescriptor(name: font.name, size: sizeFor(size: size, textStyle: textStyle)) } - private func sizeFor(size size: TypesetterFontSize, textStyle: TypesetterTextStyle) -> CGFloat { + fileprivate func sizeFor(size: TypesetterFontSize, textStyle: TypesetterTextStyle) -> CGFloat { return matrix[textStyle]?[size] ?? configuration.defaultFontSize } -} \ No newline at end of file +} diff --git a/Typesetter/TypesetterConfiguration.swift b/Typesetter/TypesetterConfiguration.swift index b0fe289..9723aa2 100644 --- a/Typesetter/TypesetterConfiguration.swift +++ b/Typesetter/TypesetterConfiguration.swift @@ -14,7 +14,7 @@ public struct TypesetterConfiguration { */ public let defaultFontSize: CGFloat - private let defaultDefaultFontSize: CGFloat = 12.0 + fileprivate let defaultDefaultFontSize: CGFloat = 12.0 /** Initialize a new `TypesetterConfiguration` with a custom path to a definition file. @@ -37,4 +37,4 @@ public struct TypesetterConfiguration { self.sizeDefinitionsPath = sizeDefinitionsPath self.defaultFontSize = defaultFontSize } -} \ No newline at end of file +} diff --git a/Typesetter/TypesetterFontSize.swift b/Typesetter/TypesetterFontSize.swift index 0f7ad8b..168e0b1 100644 --- a/Typesetter/TypesetterFontSize.swift +++ b/Typesetter/TypesetterFontSize.swift @@ -29,85 +29,46 @@ public enum TypesetterFontSize: String { /** The largest font size reflecting the current accessibility settings. */ case AccessibilityExtraExtraExtraLarge + static let allSizes = [ ExtraSmall, Small, Medium, Large, ExtraLarge, ExtraExtraLarge, ExtraExtraExtraLarge, AccessibilityMedium, AccessibilityLarge, AccessibilityExtraLarge, AccessibilityExtraExtraLarge, AccessibilityExtraExtraExtraLarge] + /** The number of typesetter font sizes available. Always returns 12. */ - static var count: Int { - var count = 0 - - switch self.Small { - case .Small: - count += 1 - fallthrough - case .Medium: - count += 1 - fallthrough - case .Large: - count += 1 - fallthrough - case .ExtraSmall: - count += 1 - fallthrough - case .ExtraLarge: - count += 1 - fallthrough - case .ExtraExtraLarge: - count += 1 - fallthrough - case .ExtraExtraExtraLarge: - count += 1 - fallthrough - case .AccessibilityMedium: - count += 1 - fallthrough - case .AccessibilityLarge: - count += 1 - fallthrough - case .AccessibilityExtraLarge: - count += 1 - fallthrough - case .AccessibilityExtraExtraLarge: - count += 1 - fallthrough - case .AccessibilityExtraExtraExtraLarge: - count += 1 - } - - return count - } + + static let count = allSizes.count /** Initialize the corresponding TypesetterFontSize for a UIContentSize. Parameter contentSize: The UIContentSize to wrap. */ - init(contentSize: String) { + init(contentSize: UIContentSizeCategory) { switch contentSize { - case UIContentSizeCategorySmall: + case UIContentSizeCategory.small: self = .Small - case UIContentSizeCategoryMedium: + case UIContentSizeCategory.medium: self = .Medium - case UIContentSizeCategoryLarge: + case UIContentSizeCategory.large: self = .Large - case UIContentSizeCategoryExtraSmall: + case UIContentSizeCategory.extraSmall: self = .ExtraSmall - case UIContentSizeCategoryExtraLarge: + case UIContentSizeCategory.extraLarge: self = .ExtraLarge - case UIContentSizeCategoryExtraExtraLarge: + case UIContentSizeCategory.extraExtraLarge: self = .ExtraExtraLarge - case UIContentSizeCategoryExtraExtraExtraLarge: + case UIContentSizeCategory.extraExtraExtraLarge: self = .ExtraExtraExtraLarge - case UIContentSizeCategoryAccessibilityMedium: + case UIContentSizeCategory.accessibilityMedium: self = .AccessibilityMedium - case UIContentSizeCategoryAccessibilityLarge: + case UIContentSizeCategory.accessibilityLarge: self = .AccessibilityLarge - case UIContentSizeCategoryAccessibilityExtraLarge: + case UIContentSizeCategory.accessibilityExtraLarge: self = .AccessibilityExtraLarge - case UIContentSizeCategoryAccessibilityExtraExtraLarge: + case UIContentSizeCategory.accessibilityExtraExtraLarge: self = .AccessibilityExtraExtraLarge - case UIContentSizeCategoryAccessibilityExtraExtraExtraLarge: + case UIContentSizeCategory.accessibilityExtraExtraExtraLarge: self = .AccessibilityExtraExtraExtraLarge default: self = .Medium } } -} \ No newline at end of file +} diff --git a/Typesetter/TypesetterTextStyle.swift b/Typesetter/TypesetterTextStyle.swift index 57567e9..415e0c7 100644 --- a/Typesetter/TypesetterTextStyle.swift +++ b/Typesetter/TypesetterTextStyle.swift @@ -25,94 +25,62 @@ public enum TypesetterTextStyle: String { /** The text style used for third level hierarchical headings. */ case Title3 + + static let allStyles = [ Body, Callout, Caption1, Caption2, Footnote, Headline, Subheadline, Title1, Title2, Title3 ] + /** The count of available text styles, which is 10. */ - static var count: Int { - var count = 0 - switch self.Body { - case .Body: - count += 1 - fallthrough - case .Callout: - count += 1 - fallthrough - case .Caption1: - count += 1 - fallthrough - case .Caption2: - count += 1 - fallthrough - case .Footnote: - count += 1 - fallthrough - case .Headline: - count += 1 - fallthrough - case .Subheadline: - count += 1 - fallthrough - case .Title1: - count += 1 - fallthrough - case .Title2: - count += 1 - fallthrough - case .Title3: - count += 1 - } - - return count - } + static let count = allStyles.count /** Initializes a new text style from an UITextStyle - Parameter textStyle: The UITextStyle to map. */ - init(textStyle: String) { + init(textStyle: UIFontTextStyle) { if #available(iOS 9.0, *) { switch textStyle { - case UIFontTextStyleBody: + case UIFontTextStyle.body: self = .Body - case UIFontTextStyleCaption1: + case UIFontTextStyle.caption1: self = .Caption1 - case UIFontTextStyleCaption2: + case UIFontTextStyle.caption2: self = .Caption2 - case UIFontTextStyleFootnote: + case UIFontTextStyle.footnote: self = .Footnote - case UIFontTextStyleHeadline: + case UIFontTextStyle.headline: self = .Headline - case UIFontTextStyleSubheadline: + case UIFontTextStyle.subheadline: self = .Subheadline - case UIFontTextStyleCallout: + case UIFontTextStyle.callout: self = .Callout - case UIFontTextStyleTitle1: + case UIFontTextStyle.title1: self = .Title1 - case UIFontTextStyleTitle2: + case UIFontTextStyle.title2: self = .Title2 - case UIFontTextStyleTitle3: + case UIFontTextStyle.title3: self = .Title3 default: self = .Body } } else { switch textStyle { - case UIFontTextStyleBody: + case UIFontTextStyle.body: self = .Body - case UIFontTextStyleCaption1: + case UIFontTextStyle.caption1: self = .Caption1 - case UIFontTextStyleCaption2: + case UIFontTextStyle.caption2: self = .Caption2 - case UIFontTextStyleFootnote: + case UIFontTextStyle.footnote: self = .Footnote - case UIFontTextStyleHeadline: + case UIFontTextStyle.headline: self = .Headline - case UIFontTextStyleSubheadline: + case UIFontTextStyle.subheadline: self = .Subheadline default: self = .Body } } } -} \ No newline at end of file +} diff --git a/Typesetter/TypesetterTextStyleFontSizeMatrixLoader.swift b/Typesetter/TypesetterTextStyleFontSizeMatrixLoader.swift index 2b68b50..44e3b5d 100644 --- a/Typesetter/TypesetterTextStyleFontSizeMatrixLoader.swift +++ b/Typesetter/TypesetterTextStyleFontSizeMatrixLoader.swift @@ -2,7 +2,7 @@ import UIKit internal class TypesetterTextStyleFontSizeMatrixLoader { - private static var cachedPaths: [String: Typesetter.TextStyleFontSizeMatrix] = [:] + fileprivate static var cachedPaths: [String: Typesetter.TextStyleFontSizeMatrix] = [:] let path: String @@ -11,13 +11,13 @@ internal class TypesetterTextStyleFontSizeMatrixLoader { } func clear() { - TypesetterTextStyleFontSizeMatrixLoader.cachedPaths.removeValueForKey(path) + TypesetterTextStyleFontSizeMatrixLoader.cachedPaths.removeValue(forKey: path) } func load() -> Typesetter.TextStyleFontSizeMatrix? { if let cached = TypesetterTextStyleFontSizeMatrixLoader.cachedPaths[path] { return cached } - guard let csv = loadCSV(path) where !csv.headers.isEmpty else { + guard let csv = loadCSV(path) , !csv.headers.isEmpty else { logReadFailure("Could not find or read font sizes csv") return nil } @@ -36,14 +36,14 @@ internal class TypesetterTextStyleFontSizeMatrixLoader { return nil } - private func loadMatrix(csv: CSV, styleNames: ArraySlice, sizeNames: [String]) -> Typesetter.TextStyleFontSizeMatrix? { + fileprivate func loadMatrix(_ csv: CSV, styleNames: ArraySlice, sizeNames: [String]) -> Typesetter.TextStyleFontSizeMatrix? { var matrix = Typesetter.TextStyleFontSizeMatrix() for styleName in styleNames { - for (index, sizeName) in sizeNames.enumerate() { + for (index, sizeName) in sizeNames.enumerated() { guard let style = TypesetterTextStyle(rawValue: styleName), - size = TypesetterFontSize(rawValue: sizeName), - values = csv.columns[styleName], - fontSize = Float(values[index]) + let size = TypesetterFontSize(rawValue: sizeName), + let values = csv.columns[styleName], + let fontSize = Float(values[index]) else { logReadFailure("Font sizes csv is corrupt at \(styleName) \(sizeName)") return nil @@ -62,11 +62,11 @@ internal class TypesetterTextStyleFontSizeMatrixLoader { return matrix } - private func loadCSV(path: String) -> CSV? { + fileprivate func loadCSV(_ path: String) -> CSV? { return CSV(contentsOfFile: path) } - private func logReadFailure(message: String) { + fileprivate func logReadFailure(_ message: String) { NSLog("Typesetter: \(message) - will default to same font size for all fonts") } -} \ No newline at end of file +} diff --git a/TypesetterTests/CSVTests.swift b/TypesetterTests/CSVTests.swift index 9b08561..d3a14a2 100644 --- a/TypesetterTests/CSVTests.swift +++ b/TypesetterTests/CSVTests.swift @@ -30,8 +30,8 @@ class CSVTests: XCTestCase { expect(parsed).to(beNil()) } - private func csvPath(fileName: String) -> String { - return NSBundle(forClass: self.dynamicType).pathForResource(fileName, ofType: "csv") ?? "" + fileprivate func csvPath(_ fileName: String) -> String { + return Bundle(for: type(of: self)).path(forResource: fileName, ofType: "csv") ?? "" } } diff --git a/TypesetterTests/TypesetterFontSizeTests.swift b/TypesetterTests/TypesetterFontSizeTests.swift index 50c90d2..97c5b07 100644 --- a/TypesetterTests/TypesetterFontSizeTests.swift +++ b/TypesetterTests/TypesetterFontSizeTests.swift @@ -6,19 +6,19 @@ import Nimble class TypesetterFontSizeTests: XCTestCase { func testSizeMapping() { - let mapping: [TypesetterFontSize: String] = [ - .Small: UIContentSizeCategorySmall, - .Medium: UIContentSizeCategoryMedium, - .Large: UIContentSizeCategoryLarge, - .ExtraSmall: UIContentSizeCategoryExtraSmall, - .ExtraLarge: UIContentSizeCategoryExtraLarge, - .ExtraExtraLarge: UIContentSizeCategoryExtraExtraLarge, - .ExtraExtraExtraLarge: UIContentSizeCategoryExtraExtraExtraLarge, - .AccessibilityMedium: UIContentSizeCategoryAccessibilityMedium, - .AccessibilityLarge: UIContentSizeCategoryAccessibilityLarge, - .AccessibilityExtraLarge: UIContentSizeCategoryAccessibilityExtraLarge, - .AccessibilityExtraExtraLarge: UIContentSizeCategoryAccessibilityExtraExtraLarge, - .AccessibilityExtraExtraExtraLarge: UIContentSizeCategoryAccessibilityExtraExtraExtraLarge + let mapping: [TypesetterFontSize: UIContentSizeCategory] = [ + .Small: .small, + .Medium: .medium, + .Large: .large, + .ExtraSmall: .extraSmall, + .ExtraLarge: .extraLarge, + .ExtraExtraLarge: .extraExtraLarge, + .ExtraExtraExtraLarge: .extraExtraExtraLarge, + .AccessibilityMedium: .accessibilityMedium, + .AccessibilityLarge: .accessibilityLarge, + .AccessibilityExtraLarge: .accessibilityExtraLarge, + .AccessibilityExtraExtraLarge: .accessibilityExtraExtraLarge, + .AccessibilityExtraExtraExtraLarge: .accessibilityExtraExtraExtraLarge ] for (expectedFontSize, inputContentSize) in mapping { diff --git a/TypesetterTests/TypesetterTests.swift b/TypesetterTests/TypesetterTests.swift index 21ba9db..1449e4e 100644 --- a/TypesetterTests/TypesetterTests.swift +++ b/TypesetterTests/TypesetterTests.swift @@ -29,7 +29,7 @@ class TypesetterTests: XCTestCase { continueAfterFailure = false - guard let csvPath = NSBundle(forClass: self.dynamicType).pathForResource("FontSizes", ofType: "csv") else { + guard let csvPath = Bundle(for: type(of: self)).path(forResource: "FontSizes", ofType: "csv") else { fail("Font fixture file TypesetterFontSizes.csv is missing") return } @@ -45,25 +45,25 @@ class TypesetterTests: XCTestCase { } func testConvenienceInit() { - let convenienceTypesetter = Typesetter(bundle: NSBundle(forClass: self.dynamicType)) + let convenienceTypesetter = Typesetter(bundle: Bundle(for: type(of: self))) expect(convenienceTypesetter.hasSizes).to(beTrue()) } func testConvenienceInitWithNoPath() { - let convenienceTypesetter = Typesetter(bundle: NSBundle()) + let convenienceTypesetter = Typesetter(bundle: Bundle()) expect(convenienceTypesetter.hasSizes).to(beFalse()) } func testFontForWithoutSizes() { - typesetter = Typesetter(bundle: NSBundle()) + typesetter = Typesetter(bundle: Bundle()) let font = typesetter.sizedFontFor(.Body, font: Font.Bold) expect(font.pointSize).to(equal(12.0)) } func testConvenienceInitPerformance() { - self.measureBlock { + self.measure { for _ in 1..<10000 { - let _ = Typesetter(bundle: NSBundle(forClass: self.dynamicType)) + let _ = Typesetter(bundle: Bundle(for: type(of: self))) } } } diff --git a/TypesetterTests/TypesetterTextStyleFontSizeMatrixLoaderTests.swift b/TypesetterTests/TypesetterTextStyleFontSizeMatrixLoaderTests.swift index 6d5b737..9439c40 100644 --- a/TypesetterTests/TypesetterTextStyleFontSizeMatrixLoaderTests.swift +++ b/TypesetterTests/TypesetterTextStyleFontSizeMatrixLoaderTests.swift @@ -5,10 +5,10 @@ import Nimble class TypesetterTextStyleFontSizeMatrixLoaderTests: XCTestCase { - var fileManager: NSFileManager! + var fileManager: FileManager! override func setUp() { - fileManager = NSFileManager.defaultManager() + fileManager = FileManager.default } override func tearDown() { @@ -17,7 +17,7 @@ class TypesetterTextStyleFontSizeMatrixLoaderTests: XCTestCase { func testCache() { let testPath = copyCSVFixtureToTestPath(csvPath("FontSizes")) - TypesetterTextStyleFontSizeMatrixLoader(path: testPath).load() + _ = TypesetterTextStyleFontSizeMatrixLoader(path: testPath).load() removeCSVFixtureAtPath(testPath) let cacheLoader = TypesetterTextStyleFontSizeMatrixLoader(path: testPath) @@ -32,10 +32,10 @@ class TypesetterTextStyleFontSizeMatrixLoaderTests: XCTestCase { expect(deletedResult).to(beNil()) } - private func copyCSVFixtureToTestPath(path: String) -> String { - let newPath = path.stringByReplacingOccurrencesOfString("FontSizes", withString: "CorrectFontSizes-CacheTest") + fileprivate func copyCSVFixtureToTestPath(_ path: String) -> String { + let newPath = path.replacingOccurrences(of: "FontSizes", with: "CorrectFontSizes-CacheTest") do { - try fileManager.copyItemAtPath(path, toPath: newPath) + try fileManager.copyItem(atPath: path, toPath: newPath) } catch _ { fail("Could not copy file for cache test") } @@ -43,9 +43,9 @@ class TypesetterTextStyleFontSizeMatrixLoaderTests: XCTestCase { return newPath } - private func removeCSVFixtureAtPath(path: String) { + fileprivate func removeCSVFixtureAtPath(_ path: String) { do { - try fileManager.removeItemAtPath(path) + try fileManager.removeItem(atPath: path) } catch _ { fail("Could not remove file for cache test") } @@ -86,7 +86,7 @@ class TypesetterTextStyleFontSizeMatrixLoaderTests: XCTestCase { expect(sizeMatrix).to(beNil()) } - private func csvPath(fileName: String) -> String { - return NSBundle(forClass: self.dynamicType).pathForResource(fileName, ofType: "csv") ?? "" + fileprivate func csvPath(_ fileName: String) -> String { + return Bundle(for: type(of: self)).path(forResource: fileName, ofType: "csv") ?? "" } } diff --git a/TypesetterTests/TypesetterTextStyleTests.swift b/TypesetterTests/TypesetterTextStyleTests.swift index e249020..0919aa9 100644 --- a/TypesetterTests/TypesetterTextStyleTests.swift +++ b/TypesetterTests/TypesetterTextStyleTests.swift @@ -6,21 +6,21 @@ import Nimble class TypesetterTextStyleTests: XCTestCase { func testStyleMapping() { - var mapping: [TypesetterTextStyle: String] = [ - .Body: UIFontTextStyleBody, - .Caption1: UIFontTextStyleCaption1, - .Caption2: UIFontTextStyleCaption2, - .Footnote: UIFontTextStyleFootnote, - .Headline: UIFontTextStyleHeadline, - .Subheadline: UIFontTextStyleSubheadline, + var mapping: [TypesetterTextStyle: UIFontTextStyle] = [ + .Body: .body, + .Caption1: .caption1, + .Caption2: .caption2, + .Footnote: .footnote, + .Headline: .headline, + .Subheadline: .subheadline, ] if #available(iOS 9.0, *) { - let additionals: [TypesetterTextStyle: String] = [ - .Callout: UIFontTextStyleCallout, - .Title1: UIFontTextStyleTitle1, - .Title2: UIFontTextStyleTitle2, - .Title3: UIFontTextStyleTitle3 + let additionals: [TypesetterTextStyle: UIFontTextStyle] = [ + .Callout: .callout, + .Title1: .title1, + .Title2: .title2, + .Title3: .title3 ] for (textStyle, textStyleString) in additionals { @@ -33,7 +33,7 @@ class TypesetterTextStyleTests: XCTestCase { expect(TypesetterTextStyle(textStyle: inputFontTextStyleString)).to(equal(expectedFontTextStyle)) } - expect(TypesetterTextStyle(textStyle: "Garbage")).to(equal(TypesetterTextStyle.Body)) + expect(TypesetterTextStyle(textStyle: UIFontTextStyle(rawValue: "Garbage"))).to(equal(TypesetterTextStyle.Body)) } func testStyleCount() {