From 6e36ce80e2a0bb6e560347b5cc008f06f02b383f Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Sun, 26 May 2019 22:24:09 +0200 Subject: [PATCH 1/9] extension NSString for macOS --- Gemfile | 2 +- Gemfile.lock | 66 ++++++++++--------- SwiftyAttributes.xcodeproj/project.pbxproj | 4 ++ .../Sources/common/Attribute.swift | 10 +++ .../common/NSString+SwiftyAttributes.swift | 46 +++++++++++++ 5 files changed, 96 insertions(+), 32 deletions(-) create mode 100644 SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift diff --git a/Gemfile b/Gemfile index 7f2d0a9..d3e50f4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,3 @@ source 'https://rubygems.org' -gem 'cocoapods', '~> 1.3.0' +gem 'cocoapods', '~> 1.7.0' diff --git a/Gemfile.lock b/Gemfile.lock index 329ff4d..7857fdf 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,72 +1,76 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (2.3.5) - activesupport (4.2.9) + CFPropertyList (3.0.0) + activesupport (4.2.11.1) i18n (~> 0.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) + atomos (0.1.3) claide (1.0.2) - cocoapods (1.3.1) + cocoapods (1.7.0) activesupport (>= 4.0.2, < 5) claide (>= 1.0.2, < 2.0) - cocoapods-core (= 1.3.1) - cocoapods-deintegrate (>= 1.0.1, < 2.0) - cocoapods-downloader (>= 1.1.3, < 2.0) + cocoapods-core (= 1.7.0) + cocoapods-deintegrate (>= 1.0.3, < 2.0) + cocoapods-downloader (>= 1.2.2, < 2.0) cocoapods-plugins (>= 1.0.0, < 2.0) cocoapods-search (>= 1.0.0, < 2.0) cocoapods-stats (>= 1.0.0, < 2.0) - cocoapods-trunk (>= 1.2.0, < 2.0) + cocoapods-trunk (>= 1.3.1, < 2.0) cocoapods-try (>= 1.1.0, < 2.0) colored2 (~> 3.1) escape (~> 0.0.4) - fourflusher (~> 2.0.1) + fourflusher (>= 2.2.0, < 3.0) gh_inspector (~> 1.0) - molinillo (~> 0.5.7) + molinillo (~> 0.6.6) nap (~> 1.0) - ruby-macho (~> 1.1) - xcodeproj (>= 1.5.1, < 2.0) - cocoapods-core (1.3.1) + ruby-macho (~> 1.4) + xcodeproj (>= 1.8.2, < 2.0) + cocoapods-core (1.7.0) activesupport (>= 4.0.2, < 6) fuzzy_match (~> 2.0.4) nap (~> 1.0) - cocoapods-deintegrate (1.0.1) - cocoapods-downloader (1.1.3) + cocoapods-deintegrate (1.0.4) + cocoapods-downloader (1.2.2) cocoapods-plugins (1.0.0) nap cocoapods-search (1.0.0) - cocoapods-stats (1.0.0) - cocoapods-trunk (1.2.0) + cocoapods-stats (1.1.0) + cocoapods-trunk (1.3.1) nap (>= 0.8, < 2.0) - netrc (= 0.7.8) + netrc (~> 0.11) cocoapods-try (1.1.0) colored2 (3.1.2) + concurrent-ruby (1.1.5) escape (0.0.4) - fourflusher (2.0.1) + fourflusher (2.2.0) fuzzy_match (2.0.4) - gh_inspector (1.0.3) - i18n (0.8.6) - minitest (5.10.3) - molinillo (0.5.7) - nanaimo (0.2.3) + gh_inspector (1.1.3) + i18n (0.9.5) + concurrent-ruby (~> 1.0) + minitest (5.11.3) + molinillo (0.6.6) + nanaimo (0.2.6) nap (1.1.0) - netrc (0.7.8) - ruby-macho (1.1.0) + netrc (0.11.0) + ruby-macho (1.4.0) thread_safe (0.3.6) - tzinfo (1.2.3) + tzinfo (1.2.5) thread_safe (~> 0.1) - xcodeproj (1.5.1) - CFPropertyList (~> 2.3.3) + xcodeproj (1.9.0) + CFPropertyList (>= 2.3.3, < 4.0) + atomos (~> 0.1.3) claide (>= 1.0.2, < 2.0) colored2 (~> 3.1) - nanaimo (~> 0.2.3) + nanaimo (~> 0.2.6) PLATFORMS ruby DEPENDENCIES - cocoapods (~> 1.3.0) + cocoapods (~> 1.7.0) BUNDLED WITH - 1.13.6 + 1.17.3 diff --git a/SwiftyAttributes.xcodeproj/project.pbxproj b/SwiftyAttributes.xcodeproj/project.pbxproj index e7c85a1..133fec9 100644 --- a/SwiftyAttributes.xcodeproj/project.pbxproj +++ b/SwiftyAttributes.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 9E0DA887229B1F5000E29BFD /* NSString+SwiftyAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA886229B1F5000E29BFD /* NSString+SwiftyAttributes.swift */; }; C027C0C91DEA0A0100953C09 /* SpellingState_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C027C0C81DEA0A0100953C09 /* SpellingState_Tests.swift */; }; C027C0CB1DEA452500953C09 /* Attribute+Sequence_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C027C0CA1DEA452500953C09 /* Attribute+Sequence_Tests.swift */; }; C03658FA1DC859D80051F06D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C03658F91DC859D80051F06D /* AppDelegate.swift */; }; @@ -69,6 +70,7 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ + 9E0DA886229B1F5000E29BFD /* NSString+SwiftyAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSString+SwiftyAttributes.swift"; path = "common/NSString+SwiftyAttributes.swift"; sourceTree = ""; }; C027C0C81DEA0A0100953C09 /* SpellingState_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpellingState_Tests.swift; sourceTree = ""; }; C027C0CA1DEA452500953C09 /* Attribute+Sequence_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Attribute+Sequence_Tests.swift"; sourceTree = ""; }; C0335B631DC0877C009F9B51 /* WritingDirection_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WritingDirection_Tests.swift; sourceTree = ""; }; @@ -226,6 +228,7 @@ C05082211DFA72F700D39B3B /* Ligatures.swift */, C05082221DFA72F700D39B3B /* NSAttributedString+SwiftyAttributes.swift */, C05082231DFA72F700D39B3B /* NSMutableAttributedString+SwiftyAttributes.swift */, + 9E0DA886229B1F5000E29BFD /* NSString+SwiftyAttributes.swift */, C05082241DFA72F700D39B3B /* Operators.swift */, C05082251DFA72F700D39B3B /* String+SwiftyAttributes.swift */, C05082261DFA72F700D39B3B /* TextEffect.swift */, @@ -462,6 +465,7 @@ C05082331DFA72F700D39B3B /* WritingDirection.swift in Sources */, C050822C1DFA72F700D39B3B /* Ligatures.swift in Sources */, C05082311DFA72F700D39B3B /* TextEffect.swift in Sources */, + 9E0DA887229B1F5000E29BFD /* NSString+SwiftyAttributes.swift in Sources */, C05082301DFA72F700D39B3B /* String+SwiftyAttributes.swift in Sources */, C0DB42EC1DDED3500093A6FA /* NSAttributedString+macOS.swift in Sources */, C05082321DFA72F700D39B3B /* VerticalGlyphForm.swift in Sources */, diff --git a/SwiftyAttributes/Sources/common/Attribute.swift b/SwiftyAttributes/Sources/common/Attribute.swift index aa70edf..9d4986e 100644 --- a/SwiftyAttributes/Sources/common/Attribute.swift +++ b/SwiftyAttributes/Sources/common/Attribute.swift @@ -12,15 +12,25 @@ public typealias Font = NSFont public typealias Cursor = NSCursor public typealias TextAlternatives = NSTextAlternatives + public typealias Point = NSPoint + public typealias Size = NSSize + public typealias Rect = NSRect + public typealias DrawingOptions = NSString.DrawingOptions #else import UIKit public typealias Color = UIColor public typealias Font = UIFont + public typealias DrawingOptions = DrawingOptions + public typealias Point = CGPoint + public typealias Size = CGSize + public typealias Rect = CGRect + public typealias DrawingOptions = NSStringDrawingOptions #endif public typealias UnderlineStyle = NSUnderlineStyle public typealias StrikethroughStyle = NSUnderlineStyle public typealias ParagraphStyle = NSParagraphStyle +public typealias DrawingContext = NSStringDrawingContext #if os(watchOS) #else diff --git a/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift b/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift new file mode 100644 index 0000000..4d8c66c --- /dev/null +++ b/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift @@ -0,0 +1,46 @@ +// +// NSString+SwiftyAttributes.swift +// SwiftyAttributes +// +// Created by Roman Podymov on 26/05/19. +// Copyright © 2019 Roman Podymov. All rights reserved. +// + +#if os(macOS) + import AppKit +#else + import UIKit +#endif + +extension NSString { + + public func draw(at point: Point, withAttributes attrs: [Attribute]? = nil) { + draw(at: point, withAttributes: attrs?.foundationAttributes) + } + + public func draw(in rect: Rect, withAttributes attrs: [Attribute]? = nil) { + draw(in: rect, withAttributes: attrs?.foundationAttributes) + } + + @available(macOS, deprecated: 10.12) + public func draw(with rect: Rect, options: DrawingOptions = [], attributes: [Attribute]? = nil) { + draw(with: rect, options: options, attributes: attributes?.foundationAttributes) + } + + public func draw(with rect: Rect, options: DrawingOptions = [], attributes: [Attribute]? = nil, context: DrawingContext?) { + draw(with: rect, options: options, attributes: attributes?.foundationAttributes, context: context) + } + + func size(withAttributes attrs: [Attribute]? = nil) -> Size { + return size(withAttributes: attrs?.foundationAttributes) + } + + func boundingRect(with size: Size, options: DrawingOptions = [], attributes: [Attribute]? = nil, context: DrawingContext?) -> Rect { + return boundingRect(with: size, options: options, attributes: attributes?.foundationAttributes, context: context) + } + + @available(macOS, deprecated: 10.12) + func boundingRect(with size: Size, options: DrawingOptions = [], attributes: [Attribute]? = nil) -> Rect { + return boundingRect(with: size, options: options, attributes: attributes?.foundationAttributes) + } +} From 50f25091dad3a6a78d8b474b8278a95c46f0735c Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Mon, 27 May 2019 00:00:43 +0200 Subject: [PATCH 2/9] UIKit + SwiftyAttributes --- SwiftyAttributes.podspec | 4 +- SwiftyAttributes.xcodeproj/project.pbxproj | 26 +++++++++--- .../NSString+SwiftyAttributes.swift | 4 ++ .../Sources/common/Attribute.swift | 1 - .../iOS_tvOS/UIKit+SwiftyAttributes.swift | 42 +++++++++++++++++++ .../UIKit+SwiftyAttributes_Tests.swift | 36 ++++++++++++++++ 6 files changed, 106 insertions(+), 7 deletions(-) rename SwiftyAttributes/Sources/{common => }/NSString+SwiftyAttributes.swift (96%) create mode 100644 SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift create mode 100644 SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift diff --git a/SwiftyAttributes.podspec b/SwiftyAttributes.podspec index c2fc9a8..177eaf6 100644 --- a/SwiftyAttributes.podspec +++ b/SwiftyAttributes.podspec @@ -17,8 +17,10 @@ Pod::Spec.new do |s| s.source = { :git => "https://github.com/eddiekaiger/SwiftyAttributes.git", :tag => "v" + s.version.to_s } s.source_files = "SwiftyAttributes/Sources/common/*.swift" + s.ios.source_files = "SwiftyAttributes/Sources/iOS_tvOS/*.swift" + s.tvos.source_files = "SwiftyAttributes/Sources/iOS_tvOS/*.swift" s.osx.source_files = "SwiftyAttributes/Sources/macOS/*.swift" - + s.ios.deployment_target = '8.0' s.osx.deployment_target = '10.11' s.tvos.deployment_target = '9.0' diff --git a/SwiftyAttributes.xcodeproj/project.pbxproj b/SwiftyAttributes.xcodeproj/project.pbxproj index 133fec9..651fa0d 100644 --- a/SwiftyAttributes.xcodeproj/project.pbxproj +++ b/SwiftyAttributes.xcodeproj/project.pbxproj @@ -7,7 +7,9 @@ objects = { /* Begin PBXBuildFile section */ - 9E0DA887229B1F5000E29BFD /* NSString+SwiftyAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA886229B1F5000E29BFD /* NSString+SwiftyAttributes.swift */; }; + 9E0DA889229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA888229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift */; }; + 9E0DA88C229B33F600E29BFD /* NSString+SwiftyAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA88B229B33F600E29BFD /* NSString+SwiftyAttributes.swift */; }; + 9E0DA88E229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA88D229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift */; }; C027C0C91DEA0A0100953C09 /* SpellingState_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C027C0C81DEA0A0100953C09 /* SpellingState_Tests.swift */; }; C027C0CB1DEA452500953C09 /* Attribute+Sequence_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C027C0CA1DEA452500953C09 /* Attribute+Sequence_Tests.swift */; }; C03658FA1DC859D80051F06D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C03658F91DC859D80051F06D /* AppDelegate.swift */; }; @@ -70,7 +72,9 @@ /* End PBXContainerItemProxy section */ /* Begin PBXFileReference section */ - 9E0DA886229B1F5000E29BFD /* NSString+SwiftyAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSString+SwiftyAttributes.swift"; path = "common/NSString+SwiftyAttributes.swift"; sourceTree = ""; }; + 9E0DA888229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIKit+SwiftyAttributes.swift"; sourceTree = ""; }; + 9E0DA88B229B33F600E29BFD /* NSString+SwiftyAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSString+SwiftyAttributes.swift"; sourceTree = ""; }; + 9E0DA88D229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIKit+SwiftyAttributes_Tests.swift"; sourceTree = ""; }; C027C0C81DEA0A0100953C09 /* SpellingState_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpellingState_Tests.swift; sourceTree = ""; }; C027C0CA1DEA452500953C09 /* Attribute+Sequence_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Attribute+Sequence_Tests.swift"; sourceTree = ""; }; C0335B631DC0877C009F9B51 /* WritingDirection_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WritingDirection_Tests.swift; sourceTree = ""; }; @@ -147,6 +151,14 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 9E0DA88A229B33F600E29BFD /* iOS_tvOS */ = { + isa = PBXGroup; + children = ( + 9E0DA888229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift */, + ); + path = iOS_tvOS; + sourceTree = ""; + }; C03658F81DC859D80051F06D /* ExampleApp-iOS */ = { isa = PBXGroup; children = ( @@ -214,8 +226,9 @@ C0335B651DC087A3009F9B51 /* Operators_Tests.swift */, C027C0C81DEA0A0100953C09 /* SpellingState_Tests.swift */, C0D753FA1DC5C77E00BB9754 /* TextEffect_Tests.swift */, - C09633DA1DD8016800059332 /* Info.plist */, + 9E0DA88D229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift */, C0F96A021DEDE1D300D039A4 /* VerticalGlyphForm_Tests.swift */, + C09633DA1DD8016800059332 /* Info.plist */, ); path = SwiftyAttributesTests; sourceTree = ""; @@ -228,12 +241,13 @@ C05082211DFA72F700D39B3B /* Ligatures.swift */, C05082221DFA72F700D39B3B /* NSAttributedString+SwiftyAttributes.swift */, C05082231DFA72F700D39B3B /* NSMutableAttributedString+SwiftyAttributes.swift */, - 9E0DA886229B1F5000E29BFD /* NSString+SwiftyAttributes.swift */, + 9E0DA88B229B33F600E29BFD /* NSString+SwiftyAttributes.swift */, C05082241DFA72F700D39B3B /* Operators.swift */, C05082251DFA72F700D39B3B /* String+SwiftyAttributes.swift */, C05082261DFA72F700D39B3B /* TextEffect.swift */, C05082271DFA72F700D39B3B /* VerticalGlyphForm.swift */, C05082281DFA72F700D39B3B /* WritingDirection.swift */, + 9E0DA88A229B33F600E29BFD /* iOS_tvOS */, C0F001661DDD8E56009AD8E0 /* macOS */, ); path = Sources; @@ -465,14 +479,15 @@ C05082331DFA72F700D39B3B /* WritingDirection.swift in Sources */, C050822C1DFA72F700D39B3B /* Ligatures.swift in Sources */, C05082311DFA72F700D39B3B /* TextEffect.swift in Sources */, - 9E0DA887229B1F5000E29BFD /* NSString+SwiftyAttributes.swift in Sources */, C05082301DFA72F700D39B3B /* String+SwiftyAttributes.swift in Sources */, C0DB42EC1DDED3500093A6FA /* NSAttributedString+macOS.swift in Sources */, C05082321DFA72F700D39B3B /* VerticalGlyphForm.swift in Sources */, C050822D1DFA72F700D39B3B /* NSAttributedString+SwiftyAttributes.swift in Sources */, + 9E0DA88C229B33F600E29BFD /* NSString+SwiftyAttributes.swift in Sources */, C0F96A051DEDE23200D039A4 /* String+macOS.swift in Sources */, C0F001761DDD8EA5009AD8E0 /* SpellingState.swift in Sources */, C05082291DFA72F700D39B3B /* Attribute+Sequence.swift in Sources */, + 9E0DA889229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -487,6 +502,7 @@ C027C0C91DEA0A0100953C09 /* SpellingState_Tests.swift in Sources */, C0F96A031DEDE1D300D039A4 /* VerticalGlyphForm_Tests.swift in Sources */, C027C0CB1DEA452500953C09 /* Attribute+Sequence_Tests.swift in Sources */, + 9E0DA88E229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift in Sources */, C0E1C96F1DD31A0D0068E85C /* Operators_Tests.swift in Sources */, C0E1C96C1DD31A0D0068E85C /* NSAttributedString_Tests.swift in Sources */, ); diff --git a/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift b/SwiftyAttributes/Sources/NSString+SwiftyAttributes.swift similarity index 96% rename from SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift rename to SwiftyAttributes/Sources/NSString+SwiftyAttributes.swift index 4d8c66c..bbafc39 100644 --- a/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift +++ b/SwiftyAttributes/Sources/NSString+SwiftyAttributes.swift @@ -22,10 +22,12 @@ extension NSString { draw(in: rect, withAttributes: attrs?.foundationAttributes) } + #if os(macOS) @available(macOS, deprecated: 10.12) public func draw(with rect: Rect, options: DrawingOptions = [], attributes: [Attribute]? = nil) { draw(with: rect, options: options, attributes: attributes?.foundationAttributes) } + #endif public func draw(with rect: Rect, options: DrawingOptions = [], attributes: [Attribute]? = nil, context: DrawingContext?) { draw(with: rect, options: options, attributes: attributes?.foundationAttributes, context: context) @@ -39,8 +41,10 @@ extension NSString { return boundingRect(with: size, options: options, attributes: attributes?.foundationAttributes, context: context) } + #if os(macOS) @available(macOS, deprecated: 10.12) func boundingRect(with size: Size, options: DrawingOptions = [], attributes: [Attribute]? = nil) -> Rect { return boundingRect(with: size, options: options, attributes: attributes?.foundationAttributes) } + #endif } diff --git a/SwiftyAttributes/Sources/common/Attribute.swift b/SwiftyAttributes/Sources/common/Attribute.swift index 9d4986e..c274198 100644 --- a/SwiftyAttributes/Sources/common/Attribute.swift +++ b/SwiftyAttributes/Sources/common/Attribute.swift @@ -20,7 +20,6 @@ import UIKit public typealias Color = UIColor public typealias Font = UIFont - public typealias DrawingOptions = DrawingOptions public typealias Point = CGPoint public typealias Size = CGSize public typealias Rect = CGRect diff --git a/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift new file mode 100644 index 0000000..2e0ae24 --- /dev/null +++ b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift @@ -0,0 +1,42 @@ +// +// UIKit+SwiftyAttributes.swift +// SwiftyAttributes +// +// Created by Roman Podymov on 26/05/19. +// Copyright © 2019 Roman Podymov. All rights reserved. +// + +#if os(macOS) +#elseif os(watchOS) +#else + import UIKit + public typealias NavigationBar = UINavigationBar +#endif + +#if os(macOS) +#elseif os(watchOS) +#else +extension NavigationBar { + + public var swiftyTitleTextAttributes: [Attribute]? { + set { + titleTextAttributes = newValue?.foundationAttributes + } + + get { + return titleTextAttributes?.swiftyAttributes + } + } + + @available(iOS 11, tvOS 11, *) + public var swiftyLargeTextAttributes: [Attribute]? { + set { + largeTitleTextAttributes = newValue?.foundationAttributes + } + + get { + return largeTitleTextAttributes?.swiftyAttributes + } + } +} +#endif diff --git a/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift new file mode 100644 index 0000000..9f5a2ce --- /dev/null +++ b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift @@ -0,0 +1,36 @@ +// +// UIKit+SwiftyAttributes_Tests.swift +// SwiftyAttributes +// +// Created by Roman Podymov on 26/05/19. +// Copyright © 2019 Roman Podymov. All rights reserved. +// + +import XCTest +import SwiftyAttributes + +#if os(macOS) +#elseif os(watchOS) +#else +class UIKit_SwiftyAttributes_Tests: XCTestCase { + + func testTitleTextAttributes() { + + let subject = NavigationBar() + subject.swiftyTitleTextAttributes = [ + .backgroundColor(.yellow), + .font(.systemFont(ofSize: 19)) + ] + + let exptected = NavigationBar() + exptected.titleTextAttributes = [ + NSAttributedString.Key.backgroundColor: UIColor.yellow, + NSAttributedString.Key.font: Font.systemFont(ofSize: 19.0) + ] + + XCTAssertNotNil(subject.swiftyTitleTextAttributes?.foundationAttributes) + XCTAssertNotNil(exptected.titleTextAttributes) + XCTAssertEqual(subject.swiftyTitleTextAttributes!.foundationAttributes as NSDictionary, exptected.titleTextAttributes! as NSDictionary) + } +} +#endif From a8da890477b6afbc166025a0b58d7f9a9c85594a Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Mon, 27 May 2019 08:03:07 +0200 Subject: [PATCH 3/9] tests for public var swiftyLargeTitleTextAttributes --- .../iOS_tvOS/UIKit+SwiftyAttributes.swift | 2 +- .../UIKit+SwiftyAttributes_Tests.swift | 25 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift index 2e0ae24..0309580 100644 --- a/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift +++ b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift @@ -29,7 +29,7 @@ extension NavigationBar { } @available(iOS 11, tvOS 11, *) - public var swiftyLargeTextAttributes: [Attribute]? { + public var swiftyLargeTitleTextAttributes: [Attribute]? { set { largeTitleTextAttributes = newValue?.foundationAttributes } diff --git a/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift index 9f5a2ce..dd17546 100644 --- a/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift +++ b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift @@ -25,12 +25,35 @@ class UIKit_SwiftyAttributes_Tests: XCTestCase { let exptected = NavigationBar() exptected.titleTextAttributes = [ NSAttributedString.Key.backgroundColor: UIColor.yellow, - NSAttributedString.Key.font: Font.systemFont(ofSize: 19.0) + NSAttributedString.Key.font: Font.systemFont(ofSize: 19) ] XCTAssertNotNil(subject.swiftyTitleTextAttributes?.foundationAttributes) XCTAssertNotNil(exptected.titleTextAttributes) XCTAssertEqual(subject.swiftyTitleTextAttributes!.foundationAttributes as NSDictionary, exptected.titleTextAttributes! as NSDictionary) } + + func testLargeTitleTextAttributes() { + + guard #available(iOS 11.0, tvOS 11.0, *) else { + return + } + + let subject = NavigationBar() + subject.swiftyLargeTitleTextAttributes = [ + .backgroundColor(.yellow), + .font(.systemFont(ofSize: 19)) + ] + + let exptected = NavigationBar() + exptected.largeTitleTextAttributes = [ + NSAttributedString.Key.backgroundColor: UIColor.yellow, + NSAttributedString.Key.font: Font.systemFont(ofSize: 19) + ] + + XCTAssertNotNil(subject.swiftyLargeTitleTextAttributes?.foundationAttributes) + XCTAssertNotNil(exptected.largeTitleTextAttributes) + XCTAssertEqual(subject.swiftyLargeTitleTextAttributes!.foundationAttributes as NSDictionary, exptected.largeTitleTextAttributes! as NSDictionary) + } } #endif From 4480f79e8cb2cb94d0ae1bd0f60af15a831e66dc Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Mon, 27 May 2019 08:16:39 +0200 Subject: [PATCH 4/9] fixed build error on tvOS --- SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift | 2 +- SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift index 0309580..5e4a3d0 100644 --- a/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift +++ b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift @@ -28,7 +28,7 @@ extension NavigationBar { } } - @available(iOS 11, tvOS 11, *) + @available(iOS 11, *) public var swiftyLargeTitleTextAttributes: [Attribute]? { set { largeTitleTextAttributes = newValue?.foundationAttributes diff --git a/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift index dd17546..30b397a 100644 --- a/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift +++ b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift @@ -35,7 +35,7 @@ class UIKit_SwiftyAttributes_Tests: XCTestCase { func testLargeTitleTextAttributes() { - guard #available(iOS 11.0, tvOS 11.0, *) else { + guard #available(iOS 11.0, *) else { return } From d7597a1fcdf1b06ca97bc1028b1854e0a8115421 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Mon, 27 May 2019 08:29:14 +0200 Subject: [PATCH 5/9] fixed for tvOS again --- SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift | 2 ++ SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift | 2 ++ 2 files changed, 4 insertions(+) diff --git a/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift index 5e4a3d0..678d110 100644 --- a/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift +++ b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift @@ -28,6 +28,7 @@ extension NavigationBar { } } + #if os(iOS) @available(iOS 11, *) public var swiftyLargeTitleTextAttributes: [Attribute]? { set { @@ -38,5 +39,6 @@ extension NavigationBar { return largeTitleTextAttributes?.swiftyAttributes } } + #endif } #endif diff --git a/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift index 30b397a..d1d315b 100644 --- a/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift +++ b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift @@ -33,6 +33,7 @@ class UIKit_SwiftyAttributes_Tests: XCTestCase { XCTAssertEqual(subject.swiftyTitleTextAttributes!.foundationAttributes as NSDictionary, exptected.titleTextAttributes! as NSDictionary) } + #if os(iOS) func testLargeTitleTextAttributes() { guard #available(iOS 11.0, *) else { @@ -55,5 +56,6 @@ class UIKit_SwiftyAttributes_Tests: XCTestCase { XCTAssertNotNil(exptected.largeTitleTextAttributes) XCTAssertEqual(subject.swiftyLargeTitleTextAttributes!.foundationAttributes as NSDictionary, exptected.largeTitleTextAttributes! as NSDictionary) } + #endif } #endif From c31f4ceb3a831b6645fe58aa14786a7bd2c5475a Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Mon, 27 May 2019 21:30:38 +0200 Subject: [PATCH 6/9] moved NSString+SwiftyAttributes --- SwiftyAttributes.xcodeproj/project.pbxproj | 8 ++++---- .../NSString+SwiftyAttributes.swift | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) rename SwiftyAttributes/Sources/{ => common}/NSString+SwiftyAttributes.swift (63%) diff --git a/SwiftyAttributes.xcodeproj/project.pbxproj b/SwiftyAttributes.xcodeproj/project.pbxproj index 651fa0d..e537854 100644 --- a/SwiftyAttributes.xcodeproj/project.pbxproj +++ b/SwiftyAttributes.xcodeproj/project.pbxproj @@ -8,8 +8,8 @@ /* Begin PBXBuildFile section */ 9E0DA889229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA888229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift */; }; - 9E0DA88C229B33F600E29BFD /* NSString+SwiftyAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA88B229B33F600E29BFD /* NSString+SwiftyAttributes.swift */; }; 9E0DA88E229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA88D229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift */; }; + 9E25A318229C5E3100B3F637 /* NSString+SwiftyAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E25A317229C5E3100B3F637 /* NSString+SwiftyAttributes.swift */; }; C027C0C91DEA0A0100953C09 /* SpellingState_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C027C0C81DEA0A0100953C09 /* SpellingState_Tests.swift */; }; C027C0CB1DEA452500953C09 /* Attribute+Sequence_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C027C0CA1DEA452500953C09 /* Attribute+Sequence_Tests.swift */; }; C03658FA1DC859D80051F06D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C03658F91DC859D80051F06D /* AppDelegate.swift */; }; @@ -73,8 +73,8 @@ /* Begin PBXFileReference section */ 9E0DA888229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIKit+SwiftyAttributes.swift"; sourceTree = ""; }; - 9E0DA88B229B33F600E29BFD /* NSString+SwiftyAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSString+SwiftyAttributes.swift"; sourceTree = ""; }; 9E0DA88D229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIKit+SwiftyAttributes_Tests.swift"; sourceTree = ""; }; + 9E25A317229C5E3100B3F637 /* NSString+SwiftyAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSString+SwiftyAttributes.swift"; path = "common/NSString+SwiftyAttributes.swift"; sourceTree = ""; }; C027C0C81DEA0A0100953C09 /* SpellingState_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpellingState_Tests.swift; sourceTree = ""; }; C027C0CA1DEA452500953C09 /* Attribute+Sequence_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Attribute+Sequence_Tests.swift"; sourceTree = ""; }; C0335B631DC0877C009F9B51 /* WritingDirection_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WritingDirection_Tests.swift; sourceTree = ""; }; @@ -241,7 +241,7 @@ C05082211DFA72F700D39B3B /* Ligatures.swift */, C05082221DFA72F700D39B3B /* NSAttributedString+SwiftyAttributes.swift */, C05082231DFA72F700D39B3B /* NSMutableAttributedString+SwiftyAttributes.swift */, - 9E0DA88B229B33F600E29BFD /* NSString+SwiftyAttributes.swift */, + 9E25A317229C5E3100B3F637 /* NSString+SwiftyAttributes.swift */, C05082241DFA72F700D39B3B /* Operators.swift */, C05082251DFA72F700D39B3B /* String+SwiftyAttributes.swift */, C05082261DFA72F700D39B3B /* TextEffect.swift */, @@ -483,7 +483,7 @@ C0DB42EC1DDED3500093A6FA /* NSAttributedString+macOS.swift in Sources */, C05082321DFA72F700D39B3B /* VerticalGlyphForm.swift in Sources */, C050822D1DFA72F700D39B3B /* NSAttributedString+SwiftyAttributes.swift in Sources */, - 9E0DA88C229B33F600E29BFD /* NSString+SwiftyAttributes.swift in Sources */, + 9E25A318229C5E3100B3F637 /* NSString+SwiftyAttributes.swift in Sources */, C0F96A051DEDE23200D039A4 /* String+macOS.swift in Sources */, C0F001761DDD8EA5009AD8E0 /* SpellingState.swift in Sources */, C05082291DFA72F700D39B3B /* Attribute+Sequence.swift in Sources */, diff --git a/SwiftyAttributes/Sources/NSString+SwiftyAttributes.swift b/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift similarity index 63% rename from SwiftyAttributes/Sources/NSString+SwiftyAttributes.swift rename to SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift index bbafc39..cd5efda 100644 --- a/SwiftyAttributes/Sources/NSString+SwiftyAttributes.swift +++ b/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift @@ -14,36 +14,36 @@ extension NSString { - public func draw(at point: Point, withAttributes attrs: [Attribute]? = nil) { + public func draw(at point: Point, withSwiftyAttributes attrs: [Attribute]? = nil) { draw(at: point, withAttributes: attrs?.foundationAttributes) } - public func draw(in rect: Rect, withAttributes attrs: [Attribute]? = nil) { + public func draw(in rect: Rect, withSwiftyAttributes attrs: [Attribute]? = nil) { draw(in: rect, withAttributes: attrs?.foundationAttributes) } #if os(macOS) @available(macOS, deprecated: 10.12) - public func draw(with rect: Rect, options: DrawingOptions = [], attributes: [Attribute]? = nil) { + public func draw(with rect: Rect, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil) { draw(with: rect, options: options, attributes: attributes?.foundationAttributes) } #endif - public func draw(with rect: Rect, options: DrawingOptions = [], attributes: [Attribute]? = nil, context: DrawingContext?) { - draw(with: rect, options: options, attributes: attributes?.foundationAttributes, context: context) + public func draw(with rect: Rect, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil, context: DrawingContext?) { + draw(with: rect, options: options, attributes: swiftyAttributes?.foundationAttributes, context: context) } - func size(withAttributes attrs: [Attribute]? = nil) -> Size { + func size(withSwiftyAttributes attrs: [Attribute]? = nil) -> Size { return size(withAttributes: attrs?.foundationAttributes) } - func boundingRect(with size: Size, options: DrawingOptions = [], attributes: [Attribute]? = nil, context: DrawingContext?) -> Rect { - return boundingRect(with: size, options: options, attributes: attributes?.foundationAttributes, context: context) + func boundingRect(with size: Size, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil, context: DrawingContext?) -> Rect { + return boundingRect(with: size, options: options, attributes: swiftyAttributes?.foundationAttributes, context: context) } #if os(macOS) @available(macOS, deprecated: 10.12) - func boundingRect(with size: Size, options: DrawingOptions = [], attributes: [Attribute]? = nil) -> Rect { + func boundingRect(with size: Size, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil) -> Rect { return boundingRect(with: size, options: options, attributes: attributes?.foundationAttributes) } #endif From c4b2e9656c55c70f21523df7393f6ad2192a5898 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Mon, 27 May 2019 22:32:14 +0200 Subject: [PATCH 7/9] fixed macOS build error --- .../Sources/common/NSString+SwiftyAttributes.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift b/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift index cd5efda..2ca7d61 100644 --- a/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift +++ b/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift @@ -25,7 +25,7 @@ extension NSString { #if os(macOS) @available(macOS, deprecated: 10.12) public func draw(with rect: Rect, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil) { - draw(with: rect, options: options, attributes: attributes?.foundationAttributes) + draw(with: rect, options: options, attributes: swiftyAttributes?.foundationAttributes) } #endif @@ -44,7 +44,7 @@ extension NSString { #if os(macOS) @available(macOS, deprecated: 10.12) func boundingRect(with size: Size, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil) -> Rect { - return boundingRect(with: size, options: options, attributes: attributes?.foundationAttributes) + return boundingRect(with: size, options: options, attributes: swiftyAttributes?.foundationAttributes) } #endif } From cceb1970e7394ea8eebe8078c77bb649e7eb66aa Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Mon, 27 May 2019 22:43:29 +0200 Subject: [PATCH 8/9] less functions --- SwiftyAttributes.xcodeproj/project.pbxproj | 4 -- .../common/NSString+SwiftyAttributes.swift | 50 ------------------- 2 files changed, 54 deletions(-) delete mode 100644 SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift diff --git a/SwiftyAttributes.xcodeproj/project.pbxproj b/SwiftyAttributes.xcodeproj/project.pbxproj index e537854..fd2626b 100644 --- a/SwiftyAttributes.xcodeproj/project.pbxproj +++ b/SwiftyAttributes.xcodeproj/project.pbxproj @@ -9,7 +9,6 @@ /* Begin PBXBuildFile section */ 9E0DA889229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA888229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift */; }; 9E0DA88E229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E0DA88D229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift */; }; - 9E25A318229C5E3100B3F637 /* NSString+SwiftyAttributes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9E25A317229C5E3100B3F637 /* NSString+SwiftyAttributes.swift */; }; C027C0C91DEA0A0100953C09 /* SpellingState_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C027C0C81DEA0A0100953C09 /* SpellingState_Tests.swift */; }; C027C0CB1DEA452500953C09 /* Attribute+Sequence_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C027C0CA1DEA452500953C09 /* Attribute+Sequence_Tests.swift */; }; C03658FA1DC859D80051F06D /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C03658F91DC859D80051F06D /* AppDelegate.swift */; }; @@ -74,7 +73,6 @@ /* Begin PBXFileReference section */ 9E0DA888229B2F8600E29BFD /* UIKit+SwiftyAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIKit+SwiftyAttributes.swift"; sourceTree = ""; }; 9E0DA88D229B34D800E29BFD /* UIKit+SwiftyAttributes_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIKit+SwiftyAttributes_Tests.swift"; sourceTree = ""; }; - 9E25A317229C5E3100B3F637 /* NSString+SwiftyAttributes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = "NSString+SwiftyAttributes.swift"; path = "common/NSString+SwiftyAttributes.swift"; sourceTree = ""; }; C027C0C81DEA0A0100953C09 /* SpellingState_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SpellingState_Tests.swift; sourceTree = ""; }; C027C0CA1DEA452500953C09 /* Attribute+Sequence_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Attribute+Sequence_Tests.swift"; sourceTree = ""; }; C0335B631DC0877C009F9B51 /* WritingDirection_Tests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WritingDirection_Tests.swift; sourceTree = ""; }; @@ -241,7 +239,6 @@ C05082211DFA72F700D39B3B /* Ligatures.swift */, C05082221DFA72F700D39B3B /* NSAttributedString+SwiftyAttributes.swift */, C05082231DFA72F700D39B3B /* NSMutableAttributedString+SwiftyAttributes.swift */, - 9E25A317229C5E3100B3F637 /* NSString+SwiftyAttributes.swift */, C05082241DFA72F700D39B3B /* Operators.swift */, C05082251DFA72F700D39B3B /* String+SwiftyAttributes.swift */, C05082261DFA72F700D39B3B /* TextEffect.swift */, @@ -483,7 +480,6 @@ C0DB42EC1DDED3500093A6FA /* NSAttributedString+macOS.swift in Sources */, C05082321DFA72F700D39B3B /* VerticalGlyphForm.swift in Sources */, C050822D1DFA72F700D39B3B /* NSAttributedString+SwiftyAttributes.swift in Sources */, - 9E25A318229C5E3100B3F637 /* NSString+SwiftyAttributes.swift in Sources */, C0F96A051DEDE23200D039A4 /* String+macOS.swift in Sources */, C0F001761DDD8EA5009AD8E0 /* SpellingState.swift in Sources */, C05082291DFA72F700D39B3B /* Attribute+Sequence.swift in Sources */, diff --git a/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift b/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift deleted file mode 100644 index 2ca7d61..0000000 --- a/SwiftyAttributes/Sources/common/NSString+SwiftyAttributes.swift +++ /dev/null @@ -1,50 +0,0 @@ -// -// NSString+SwiftyAttributes.swift -// SwiftyAttributes -// -// Created by Roman Podymov on 26/05/19. -// Copyright © 2019 Roman Podymov. All rights reserved. -// - -#if os(macOS) - import AppKit -#else - import UIKit -#endif - -extension NSString { - - public func draw(at point: Point, withSwiftyAttributes attrs: [Attribute]? = nil) { - draw(at: point, withAttributes: attrs?.foundationAttributes) - } - - public func draw(in rect: Rect, withSwiftyAttributes attrs: [Attribute]? = nil) { - draw(in: rect, withAttributes: attrs?.foundationAttributes) - } - - #if os(macOS) - @available(macOS, deprecated: 10.12) - public func draw(with rect: Rect, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil) { - draw(with: rect, options: options, attributes: swiftyAttributes?.foundationAttributes) - } - #endif - - public func draw(with rect: Rect, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil, context: DrawingContext?) { - draw(with: rect, options: options, attributes: swiftyAttributes?.foundationAttributes, context: context) - } - - func size(withSwiftyAttributes attrs: [Attribute]? = nil) -> Size { - return size(withAttributes: attrs?.foundationAttributes) - } - - func boundingRect(with size: Size, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil, context: DrawingContext?) -> Rect { - return boundingRect(with: size, options: options, attributes: swiftyAttributes?.foundationAttributes, context: context) - } - - #if os(macOS) - @available(macOS, deprecated: 10.12) - func boundingRect(with size: Size, options: DrawingOptions = [], swiftyAttributes: [Attribute]? = nil) -> Rect { - return boundingRect(with: size, options: options, attributes: swiftyAttributes?.foundationAttributes) - } - #endif -} From af6f7b5b28c3dcc08a5b699988eecd24aa265440 Mon Sep 17 00:00:00 2001 From: Roman Podymov Date: Wed, 29 May 2019 23:33:09 +0200 Subject: [PATCH 9/9] removed unused typealiases. less #if os. added documentation for new properties. --- SwiftyAttributes/Sources/common/Attribute.swift | 9 --------- .../Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift | 12 ++++-------- .../UIKit+SwiftyAttributes_Tests.swift | 8 ++++---- 3 files changed, 8 insertions(+), 21 deletions(-) diff --git a/SwiftyAttributes/Sources/common/Attribute.swift b/SwiftyAttributes/Sources/common/Attribute.swift index c274198..aa70edf 100644 --- a/SwiftyAttributes/Sources/common/Attribute.swift +++ b/SwiftyAttributes/Sources/common/Attribute.swift @@ -12,24 +12,15 @@ public typealias Font = NSFont public typealias Cursor = NSCursor public typealias TextAlternatives = NSTextAlternatives - public typealias Point = NSPoint - public typealias Size = NSSize - public typealias Rect = NSRect - public typealias DrawingOptions = NSString.DrawingOptions #else import UIKit public typealias Color = UIColor public typealias Font = UIFont - public typealias Point = CGPoint - public typealias Size = CGSize - public typealias Rect = CGRect - public typealias DrawingOptions = NSStringDrawingOptions #endif public typealias UnderlineStyle = NSUnderlineStyle public typealias StrikethroughStyle = NSUnderlineStyle public typealias ParagraphStyle = NSParagraphStyle -public typealias DrawingContext = NSStringDrawingContext #if os(watchOS) #else diff --git a/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift index 678d110..b47c0cd 100644 --- a/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift +++ b/SwiftyAttributes/Sources/iOS_tvOS/UIKit+SwiftyAttributes.swift @@ -9,15 +9,10 @@ #if os(macOS) #elseif os(watchOS) #else - import UIKit - public typealias NavigationBar = UINavigationBar -#endif - -#if os(macOS) -#elseif os(watchOS) -#else -extension NavigationBar { +import UIKit +extension UINavigationBar { + /// A swifty wrapper for UINavigationBar.titleTextAttributes. Use it if you prefer [Attribute] to [NSAttributedString.Key:Any]. public var swiftyTitleTextAttributes: [Attribute]? { set { titleTextAttributes = newValue?.foundationAttributes @@ -28,6 +23,7 @@ extension NavigationBar { } } + /// A swifty wrapper for UINavigationBar.largeTitleTextAttributes. Use it if you prefer [Attribute] to [NSAttributedString.Key:Any]. #if os(iOS) @available(iOS 11, *) public var swiftyLargeTitleTextAttributes: [Attribute]? { diff --git a/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift index d1d315b..7fc53bc 100644 --- a/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift +++ b/SwiftyAttributesTests/UIKit+SwiftyAttributes_Tests.swift @@ -16,13 +16,13 @@ class UIKit_SwiftyAttributes_Tests: XCTestCase { func testTitleTextAttributes() { - let subject = NavigationBar() + let subject = UINavigationBar() subject.swiftyTitleTextAttributes = [ .backgroundColor(.yellow), .font(.systemFont(ofSize: 19)) ] - let exptected = NavigationBar() + let exptected = UINavigationBar() exptected.titleTextAttributes = [ NSAttributedString.Key.backgroundColor: UIColor.yellow, NSAttributedString.Key.font: Font.systemFont(ofSize: 19) @@ -40,13 +40,13 @@ class UIKit_SwiftyAttributes_Tests: XCTestCase { return } - let subject = NavigationBar() + let subject = UINavigationBar() subject.swiftyLargeTitleTextAttributes = [ .backgroundColor(.yellow), .font(.systemFont(ofSize: 19)) ] - let exptected = NavigationBar() + let exptected = UINavigationBar() exptected.largeTitleTextAttributes = [ NSAttributedString.Key.backgroundColor: UIColor.yellow, NSAttributedString.Key.font: Font.systemFont(ofSize: 19)