Skip to content

Commit

Permalink
Merge pull request #19 from eddiekaiger/method-renamings
Browse files Browse the repository at this point in the history
Enumeration Method Renamings
  • Loading branch information
eddiekaiger authored Sep 18, 2017
2 parents 33939dd + 06c0d8e commit 666a070
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 124 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ extension NSAttributedString {
func withAttribute(_ attribute: Attribute) -> NSMutableAttributedString
func attributedSubstring(from range: Range<Int>) -> NSAttributedString
func swiftyAttribute(_ attrName: NSAttributedStringKey, at location: Int, effectiveRange range: NSRangePointer? = nil) -> Attribute?
func attributes(in range: Range<Int>, options: NSAttributedString.EnumerationOptions = []) -> [([Attribute], Range<Int>)]
func enumerateAttributes(in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ attrs: [Attribute], _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
func enumerateAttribute(_ attrName: NSAttributedStringKey, in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ value: Any?, _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
func swiftyAttributes(in range: Range<Int>, options: NSAttributedString.EnumerationOptions = []) -> [([Attribute], Range<Int>)]
func enumerateSwiftyAttributes(in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ attrs: [Attribute], _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
func enumerateSwiftyAttribute(_ attrName: NSAttributedStringKey, in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ value: Any?, _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void)
}

extension String {
Expand Down
4 changes: 2 additions & 2 deletions SwiftyAttributes.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Pod::Spec.new do |s|

s.name = "SwiftyAttributes"
s.version = "4.0.0"
s.version = "4.1.0"
s.summary = "A Swifty API for attributed strings."

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

s.source_files = "SwiftyAttributes/Sources/common/*.swift"
s.osx.source_files = "SwiftyAttributes/Sources/macOS/*.swift"
Expand Down
18 changes: 15 additions & 3 deletions SwiftyAttributes.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0810;
LastUpgradeCheck = 0800;
LastUpgradeCheck = 0900;
ORGANIZATIONNAME = "Eddie Kaiger";
TargetAttributes = {
C03658F61DC859D80051F06D = {
Expand Down Expand Up @@ -687,15 +687,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_DOCUMENTATION_COMMENTS = YES;
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_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
Expand Down Expand Up @@ -727,7 +733,7 @@
SUPPORTED_PLATFORMS = "watchsimulator watchos appletvos appletvsimulator iphoneos iphonesimulator macosx";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
VERSIONING_SYSTEM = "apple-generic";
Expand All @@ -745,15 +751,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_DOCUMENTATION_COMMENTS = YES;
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_SUSPICIOUS_MOVES = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
Expand All @@ -777,7 +789,7 @@
PRODUCT_BUNDLE_PACKAGE_TYPE = BNDL;
SUPPORTED_PLATFORMS = "watchsimulator watchos appletvos appletvsimulator iphoneos iphonesimulator macosx";
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 4.0;
SWIFT_VERSION = 3.0;
TARGETED_DEVICE_FAMILY = "1,2,3,4";
TVOS_DEPLOYMENT_TARGET = 9.0;
VALIDATE_PRODUCT = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0800"
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>
</Testables>
Expand All @@ -45,6 +46,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
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>
</Testables>
Expand All @@ -45,6 +46,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
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"
codeCoverageEnabled = "YES">
<Testables>
Expand Down Expand Up @@ -56,6 +57,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0810"
LastUpgradeVersion = "0900"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand All @@ -10,6 +10,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
Expand All @@ -34,6 +35,7 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
language = ""
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,49 +66,31 @@ extension NSAttributedString {
return attributedSubstring(from: NSRange(range))
}

#if swift(>=4.0)
/**
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.

- parameters:
- attrName: The name of an attribute.
- location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
- range:
If non-nil:
- If the named attribute exists at `location`, upon return `range` contains a range over which the named attribute’s value applies.
- If the named attribute does not exist at `location`, upon return `range` contains the range over which the attribute does not exist.

The range isn’t necessarily the maximum range covered by `attrName`, and its extent is implementation-dependent.
If you need the maximum range, use attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass `nil`.
*/
public func swiftyAttribute(_ attrName: NSAttributedStringKey, at location: Int, effectiveRange range: NSRangePointer? = nil) -> Attribute? {
if let attributeValue: Any = attribute(attrName, at: location, effectiveRange: range) {
return Attribute(name: attrName, foundationValue: attributeValue)
}
return nil
}
#else
/**
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.

- parameters:
- attrName: The name of an attribute.
- location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
- range:
If non-nil:
- If the named attribute exists at `location`, upon return `range` contains a range over which the named attribute’s value applies.
- If the named attribute does not exist at `location`, upon return `range` contains the range over which the attribute does not exist.

The range isn’t necessarily the maximum range covered by `attrName`, and its extent is implementation-dependent.
If you need the maximum range, use attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass `nil`.
*/
public func attribute(_ attrName: AttributeName, at location: Int, effectiveRange range: NSRangePointer? = nil) -> Attribute? {
if let attributeValue = attribute(attrName.rawValue, at: location, effectiveRange: range) {
return Attribute(name: attrName, foundationValue: attributeValue)
}
return nil
/**
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.

- parameters:
- attrName: The name of an attribute.
- location: The index for which to return attributes. This value must not exceed the bounds of the receiver.
- range:
If non-nil:
- If the named attribute exists at `location`, upon return `range` contains a range over which the named attribute’s value applies.
- If the named attribute does not exist at `location`, upon return `range` contains the range over which the attribute does not exist.

The range isn’t necessarily the maximum range covered by `attrName`, and its extent is implementation-dependent.
If you need the maximum range, use attribute(_:at:longestEffectiveRange:in:). If you don't need this value, pass `nil`.
*/
public func swiftyAttribute(_ attrName: AttributeName, at location: Int, effectiveRange range: NSRangePointer? = nil) -> Attribute? {
#if swift(>=4.0)
let name = attrName
#else
let name = attrName.rawValue
#endif
if let attributeValue: Any = attribute(name, at: location, effectiveRange: range) {
return Attribute(name: attrName, foundationValue: attributeValue)
}
#endif
return nil
}

/**
Returns the enumerated attributes in a specified range as an array of attribute-range pairs.
Expand All @@ -118,9 +100,9 @@ extension NSAttributedString {
- options: The options used by the enumeration. The values can be combined using C-bitwise OR. The values are described in `NSAttributedString.EnumerationOptions`.
- returns: An array of attribute-range tuples. Each tuples contains a range and the array of attributes that exist in that range.
*/
public func attributes(in range: Range<Int>, options: NSAttributedString.EnumerationOptions = []) -> [([Attribute], Range<Int>)] {
public func swiftyAttributes(in range: Range<Int>, options: NSAttributedString.EnumerationOptions = []) -> [([Attribute], Range<Int>)] {
var attributeRanges = [([Attribute], Range<Int>)]()
enumerateAttributes(in: range, options: options) { attributes, range, _ in
enumerateSwiftyAttributes(in: range, options: options) { attributes, range, _ in
attributeRanges.append((attributes, range))
}
return attributeRanges
Expand All @@ -140,7 +122,7 @@ extension NSAttributedString {
+ stop: A reference to a Boolean value. The block can set the value to `true` to stop further processing of the set.
The stop argument is an out-only argument. You should only ever set this Boolean to `true` within the block.
*/
public func enumerateAttributes(in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ attrs: [Attribute], _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateSwiftyAttributes(in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ attrs: [Attribute], _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void) {
enumerateAttributes(in: NSRange(enumerationRange), options: options) { attributes, range, ptr in
block(attributes.swiftyAttributes, range.location ..< (range.location + range.length), ptr)
}
Expand All @@ -161,7 +143,7 @@ extension NSAttributedString {
+ stop: A reference to a Boolean value. The block can set the value to `true` to stop further processing of the set.
The stop argument is an out-only argument. You should only ever set this Boolean to `true` within the block.
*/
public func enumerateAttribute(_ attrName: AttributeName, in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ value: Any?, _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void) {
public func enumerateSwiftyAttribute(_ attrName: AttributeName, in enumerationRange: Range<Int>, options: NSAttributedString.EnumerationOptions = [], using block: (_ value: Any?, _ range: Range<Int>, _ stop: UnsafeMutablePointer<ObjCBool>) -> Void) {
#if swift(>=4.0)
enumerateAttribute(attrName, in: NSRange(enumerationRange), options: options) { value, range, ptr in
block(value, range.location ..< (range.location + range.length), ptr)
Expand Down
Loading

0 comments on commit 666a070

Please sign in to comment.