Skip to content

Commit 666a070

Browse files
authored
Merge pull request #19 from eddiekaiger/method-renamings
Enumeration Method Renamings
2 parents 33939dd + 06c0d8e commit 666a070

9 files changed

+96
-124
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,9 @@ extension NSAttributedString {
9696
func withAttribute(_ attribute: Attribute) -> NSMutableAttributedString
9797
func attributedSubstring(from range: Range<Int>) -> NSAttributedString
9898
func swiftyAttribute(_ attrName: NSAttributedStringKey, at location: Int, effectiveRange range: NSRangePointer? = nil) -> Attribute?
99-
func attributes(in range: Range<Int>, options: NSAttributedString.EnumerationOptions = []) -> [([Attribute], Range<Int>)]
100-
func enumerateAttributes(in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ attrs: [Attribute], _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
101-
func enumerateAttribute(_ attrName: NSAttributedStringKey, in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ value: Any?, _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
99+
func swiftyAttributes(in range: Range<Int>, options: NSAttributedString.EnumerationOptions = []) -> [([Attribute], Range<Int>)]
100+
func enumerateSwiftyAttributes(in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ attrs: [Attribute], _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
101+
func enumerateSwiftyAttribute(_ attrName: NSAttributedStringKey, in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ value: Any?, _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
102102
}
103103

104104
extension String {

SwiftyAttributes.podspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Pod::Spec.new do |s|
33

44
s.name = "SwiftyAttributes"
5-
s.version = "4.0.0"
5+
s.version = "4.1.0"
66
s.summary = "A Swifty API for attributed strings."
77

88
s.description = <<-DESC
@@ -14,7 +14,7 @@ Pod::Spec.new do |s|
1414
s.homepage = "https://github.com/eddiekaiger/SwiftyAttributes"
1515
s.license = { :type => "MIT", :file => "LICENSE" }
1616
s.author = { "Eddie Kaiger" => "eddiekaiger@gmail.com" }
17-
s.source = { :git => "https://github.com/eddiekaiger/SwiftyAttributes.git", :tag => "v4.0.0" }
17+
s.source = { :git => "https://github.com/eddiekaiger/SwiftyAttributes.git", :tag => "v4.1.0" }
1818

1919
s.source_files = "SwiftyAttributes/Sources/common/*.swift"
2020
s.osx.source_files = "SwiftyAttributes/Sources/macOS/*.swift"

SwiftyAttributes.xcodeproj/project.pbxproj

+15-3
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@
355355
isa = PBXProject;
356356
attributes = {
357357
LastSwiftUpdateCheck = 0810;
358-
LastUpgradeCheck = 0800;
358+
LastUpgradeCheck = 0900;
359359
ORGANIZATIONNAME = "Eddie Kaiger";
360360
TargetAttributes = {
361361
C03658F61DC859D80051F06D = {
@@ -687,15 +687,21 @@
687687
CLANG_CXX_LIBRARY = "libc++";
688688
CLANG_ENABLE_MODULES = YES;
689689
CLANG_ENABLE_OBJC_ARC = YES;
690+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
690691
CLANG_WARN_BOOL_CONVERSION = YES;
692+
CLANG_WARN_COMMA = YES;
691693
CLANG_WARN_CONSTANT_CONVERSION = YES;
692694
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
693695
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
694696
CLANG_WARN_EMPTY_BODY = YES;
695697
CLANG_WARN_ENUM_CONVERSION = YES;
696698
CLANG_WARN_INFINITE_RECURSION = YES;
697699
CLANG_WARN_INT_CONVERSION = YES;
700+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
701+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
698702
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
703+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
704+
CLANG_WARN_STRICT_PROTOTYPES = YES;
699705
CLANG_WARN_SUSPICIOUS_MOVE = YES;
700706
CLANG_WARN_SUSPICIOUS_MOVES = YES;
701707
CLANG_WARN_UNREACHABLE_CODE = YES;
@@ -727,7 +733,7 @@
727733
SUPPORTED_PLATFORMS = "watchsimulator watchos appletvos appletvsimulator iphoneos iphonesimulator macosx";
728734
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
729735
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
730-
SWIFT_VERSION = 4.0;
736+
SWIFT_VERSION = 3.0;
731737
TARGETED_DEVICE_FAMILY = "1,2,3,4";
732738
TVOS_DEPLOYMENT_TARGET = 9.0;
733739
VERSIONING_SYSTEM = "apple-generic";
@@ -745,15 +751,21 @@
745751
CLANG_CXX_LIBRARY = "libc++";
746752
CLANG_ENABLE_MODULES = YES;
747753
CLANG_ENABLE_OBJC_ARC = YES;
754+
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
748755
CLANG_WARN_BOOL_CONVERSION = YES;
756+
CLANG_WARN_COMMA = YES;
749757
CLANG_WARN_CONSTANT_CONVERSION = YES;
750758
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
751759
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
752760
CLANG_WARN_EMPTY_BODY = YES;
753761
CLANG_WARN_ENUM_CONVERSION = YES;
754762
CLANG_WARN_INFINITE_RECURSION = YES;
755763
CLANG_WARN_INT_CONVERSION = YES;
764+
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
765+
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
756766
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
767+
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
768+
CLANG_WARN_STRICT_PROTOTYPES = YES;
757769
CLANG_WARN_SUSPICIOUS_MOVE = YES;
758770
CLANG_WARN_SUSPICIOUS_MOVES = YES;
759771
CLANG_WARN_UNREACHABLE_CODE = YES;
@@ -777,7 +789,7 @@
777789
PRODUCT_BUNDLE_PACKAGE_TYPE = BNDL;
778790
SUPPORTED_PLATFORMS = "watchsimulator watchos appletvos appletvsimulator iphoneos iphonesimulator macosx";
779791
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
780-
SWIFT_VERSION = 4.0;
792+
SWIFT_VERSION = 3.0;
781793
TARGETED_DEVICE_FAMILY = "1,2,3,4";
782794
TVOS_DEPLOYMENT_TARGET = 9.0;
783795
VALIDATE_PRODUCT = YES;

SwiftyAttributes.xcodeproj/xcshareddata/xcschemes/ExampleApp-iOS.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0800"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
</Testables>
@@ -45,6 +46,7 @@
4546
buildConfiguration = "Debug"
4647
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4748
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49+
language = ""
4850
launchStyle = "0"
4951
useCustomWorkingDirectory = "NO"
5052
ignoresPersistentStateOnLaunch = "NO"

SwiftyAttributes.xcodeproj/xcshareddata/xcschemes/ExampleApp-macOS.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0810"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES">
3031
<Testables>
3132
</Testables>
@@ -45,6 +46,7 @@
4546
buildConfiguration = "Debug"
4647
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
4748
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
49+
language = ""
4850
launchStyle = "0"
4951
useCustomWorkingDirectory = "NO"
5052
ignoresPersistentStateOnLaunch = "NO"

SwiftyAttributes.xcodeproj/xcshareddata/xcschemes/SwiftyAttributes.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0810"
3+
LastUpgradeVersion = "0900"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -26,6 +26,7 @@
2626
buildConfiguration = "Debug"
2727
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
2828
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
29+
language = ""
2930
shouldUseLaunchSchemeArgsEnv = "YES"
3031
codeCoverageEnabled = "YES">
3132
<Testables>
@@ -56,6 +57,7 @@
5657
buildConfiguration = "Debug"
5758
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
5859
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
60+
language = ""
5961
launchStyle = "0"
6062
useCustomWorkingDirectory = "NO"
6163
ignoresPersistentStateOnLaunch = "NO"

SwiftyAttributes.xcodeproj/xcshareddata/xcschemes/SwiftyAttributesTests.xcscheme

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0810"
3+
LastUpgradeVersion = "0900"
44
version = "1.7">
55
<BuildAction
66
parallelizeBuildables = "YES"
@@ -10,6 +10,7 @@
1010
buildConfiguration = "Debug"
1111
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
1212
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
13+
language = ""
1314
shouldUseLaunchSchemeArgsEnv = "YES">
1415
<Testables>
1516
<TestableReference
@@ -34,6 +35,7 @@
3435
buildConfiguration = "Debug"
3536
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
3637
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
38+
language = ""
3739
launchStyle = "0"
3840
useCustomWorkingDirectory = "NO"
3941
ignoresPersistentStateOnLaunch = "NO"

SwiftyAttributes/Sources/common/NSAttributedString+SwiftyAttributes.swift

+28-46
Original file line numberDiff line numberDiff line change
@@ -66,49 +66,31 @@ extension NSAttributedString {
6666
return attributedSubstring(from: NSRange(range))
6767
}
6868

69-
#if swift(>=4.0)
70-
/**
71-
Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.
72-
73-
- parameters:
74-
- attrName: The name of an attribute.
75-
- location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
76-
- range:
77-
If non-nil:
78-
- If the named attribute exists at `location`, upon return `range` contains a range over which the named attribute’s value applies.
79-
- If the named attribute does not exist at `location`, upon return `range` contains the range over which the attribute does not exist.
80-
81-
The range isn’t necessarily the maximum range covered by `attrName`, and its extent is implementation-dependent.
82-
If you need the maximum range, use attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass `nil`.
83-
*/
84-
public func swiftyAttribute(_ attrName: NSAttributedStringKey, at location: Int, effectiveRange range: NSRangePointer? = nil) -> Attribute? {
85-
if let attributeValue: Any = attribute(attrName, at: location, effectiveRange: range) {
86-
return Attribute(name: attrName, foundationValue: attributeValue)
87-
}
88-
return nil
89-
}
90-
#else
91-
/**
92-
Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.
93-
94-
- parameters:
95-
- attrName: The name of an attribute.
96-
- location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
97-
- range:
98-
If non-nil:
99-
- If the named attribute exists at `location`, upon return `range` contains a range over which the named attribute’s value applies.
100-
- If the named attribute does not exist at `location`, upon return `range` contains the range over which the attribute does not exist.
101-
102-
The range isn’t necessarily the maximum range covered by `attrName`, and its extent is implementation-dependent.
103-
If you need the maximum range, use attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass `nil`.
104-
*/
105-
public func attribute(_ attrName: AttributeName, at location: Int, effectiveRange range: NSRangePointer? = nil) -> Attribute? {
106-
if let attributeValue = attribute(attrName.rawValue, at: location, effectiveRange: range) {
107-
return Attribute(name: attrName, foundationValue: attributeValue)
108-
}
109-
return nil
69+
/**
70+
Returns the value for an attribute with a given name of the character at a given index, and by reference the range over which the attribute applies.
71+
72+
- parameters:
73+
- attrName: The name of an attribute.
74+
- location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
75+
- range:
76+
If non-nil:
77+
- If the named attribute exists at `location`, upon return `range` contains a range over which the named attribute’s value applies.
78+
- If the named attribute does not exist at `location`, upon return `range` contains the range over which the attribute does not exist.
79+
80+
The range isn’t necessarily the maximum range covered by `attrName`, and its extent is implementation-dependent.
81+
If you need the maximum range, use attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass `nil`.
82+
*/
83+
public func swiftyAttribute(_ attrName: AttributeName, at location: Int, effectiveRange range: NSRangePointer? = nil) -> Attribute? {
84+
#if swift(>=4.0)
85+
let name = attrName
86+
#else
87+
let name = attrName.rawValue
88+
#endif
89+
if let attributeValue: Any = attribute(name, at: location, effectiveRange: range) {
90+
return Attribute(name: attrName, foundationValue: attributeValue)
11091
}
111-
#endif
92+
return nil
93+
}
11294

11395
/**
11496
Returns the enumerated attributes in a specified range as an array of attribute-range pairs.
@@ -118,9 +100,9 @@ extension NSAttributedString {
118100
- options: The options used by the enumeration. The values can be combined using C-bitwise OR. The values are described in `NSAttributedString.EnumerationOptions`.
119101
- returns: An array of attribute-range tuples. Each tuples contains a range and the array of attributes that exist in that range.
120102
*/
121-
public func attributes(in range: Range<Int>, options: NSAttributedString.EnumerationOptions = []) -> [([Attribute], Range<Int>)] {
103+
public func swiftyAttributes(in range: Range<Int>, options: NSAttributedString.EnumerationOptions = []) -> [([Attribute], Range<Int>)] {
122104
var attributeRanges = [([Attribute], Range<Int>)]()
123-
enumerateAttributes(in: range, options: options) { attributes, range, _ in
105+
enumerateSwiftyAttributes(in: range, options: options) { attributes, range, _ in
124106
attributeRanges.append((attributes, range))
125107
}
126108
return attributeRanges
@@ -140,7 +122,7 @@ extension NSAttributedString {
140122
+ stop: A reference to a Boolean value. The block can set the value to `true` to stop further processing of the set.
141123
The stop argument is an out-only argument. You should only ever set this Boolean to `true` within the block.
142124
*/
143-
public func enumerateAttributes(in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ attrs: [Attribute], _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void) {
125+
public func enumerateSwiftyAttributes(in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ attrs: [Attribute], _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void) {
144126
enumerateAttributes(in: NSRange(enumerationRange), options: options) { attributes, range, ptr in
145127
block(attributes.swiftyAttributes, range.location ..< (range.location + range.length), ptr)
146128
}
@@ -161,7 +143,7 @@ extension NSAttributedString {
161143
+ stop: A reference to a Boolean value. The block can set the value to `true` to stop further processing of the set.
162144
The stop argument is an out-only argument. You should only ever set this Boolean to `true` within the block.
163145
*/
164-
public func enumerateAttribute(_ attrName: AttributeName, in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ value: Any?, _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void) {
146+
public func enumerateSwiftyAttribute(_ attrName: AttributeName, in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ value: Any?, _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void) {
165147
#if swift(>=4.0)
166148
enumerateAttribute(attrName, in: NSRange(enumerationRange), options: options) { value, range, ptr in
167149
block(value, range.location ..< (range.location + range.length), ptr)

0 commit comments

Comments
 (0)