Skip to content

Commit

Permalink
Update syntax for Xcode 9
Browse files Browse the repository at this point in the history
  • Loading branch information
zacwest committed Oct 16, 2017
1 parent d83e587 commit cea1822
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 47 deletions.
14 changes: 7 additions & 7 deletions Example/ZSWTappableLabel/DataDetectorsSwiftViewController.swift
Expand Up @@ -17,7 +17,7 @@ class DataDetectorsSwiftViewController: UIViewController, ZSWTappableLabelTapDel
return label
}()

static let TextCheckingResultAttributeName = "TextCheckingResultAttributeName"
static let TextCheckingResultAttributeName = NSAttributedStringKey(rawValue: "TextCheckingResultAttributeName")

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -35,11 +35,11 @@ class DataDetectorsSwiftViewController: UIViewController, ZSWTappableLabelTapDel
detector.enumerateMatches(in: attributedString.string, options: [], range: range) { (result, flags, _) in
guard let result = result else { return }

var attributes = [String: Any]()
attributes[ZSWTappableLabelTappableRegionAttributeName] = true
attributes[ZSWTappableLabelHighlightedBackgroundAttributeName] = UIColor.lightGray
attributes[ZSWTappableLabelHighlightedForegroundAttributeName] = UIColor.white
attributes[NSUnderlineStyleAttributeName] = NSUnderlineStyle.styleSingle.rawValue
var attributes = [NSAttributedStringKey: Any]()
attributes[.tappableRegion] = true
attributes[.tappableHighlightedBackgroundColor] = UIColor.lightGray
attributes[.tappableHighlightedForegroundColor] = UIColor.white
attributes[.underlineStyle] = NSUnderlineStyle.styleSingle.rawValue
attributes[DataDetectorsSwiftViewController.TextCheckingResultAttributeName] = result
attributedString.addAttributes(attributes, range: result.range)
}
Expand All @@ -53,7 +53,7 @@ class DataDetectorsSwiftViewController: UIViewController, ZSWTappableLabelTapDel

// MARK: - ZSWTappableLabelTapDelegate

func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [String : Any]) {
func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [NSAttributedStringKey : Any]) {
var URL: URL?

if let result = attributes[DataDetectorsSwiftViewController.TextCheckingResultAttributeName] as? NSTextCheckingResult {
Expand Down
Expand Up @@ -30,18 +30,18 @@ class InterfaceBuilderSwiftViewController: UIViewController, ZSWTappableLabelTap
let range = (attributedText.string as NSString).range(of: "label")
if range.location != NSNotFound {
attributedText.addAttributes([
ZSWTappableLabelTappableRegionAttributeName: true,
NSLinkAttributeName: URL(string: "https://gotofail.com")!,
ZSWTappableLabelHighlightedBackgroundAttributeName: UIColor.lightGray
.tappableRegion: true,
.link: URL(string: "https://gotofail.com")!,
.tappableHighlightedBackgroundColor: UIColor.lightGray
], range: range)
}
label.attributedText = attributedText
}
}

// MARK: - ZSWTappableLabelTapDelegate
func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [String : Any]) {
guard let URL = attributes[NSLinkAttributeName] as? URL else {
func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [NSAttributedStringKey : Any]) {
guard let URL = attributes[.link] as? URL else {
return
}

Expand Down
18 changes: 9 additions & 9 deletions Example/ZSWTappableLabel/LongPressSwiftViewController.swift
Expand Up @@ -17,7 +17,7 @@ class LongPressSwiftViewController: UIViewController, ZSWTappableLabelTapDelegat
return label
}()

static let URLAttributeName = "URL"
static let URLAttributeName = NSAttributedStringKey(rawValue: "URL")

enum LinkType: String {
case Privacy = "privacy"
Expand Down Expand Up @@ -46,15 +46,15 @@ class LongPressSwiftViewController: UIViewController, ZSWTappableLabelTapDelegat
options["link"] = .dynamic({ tagName, tagAttributes, stringAttributes in
guard let typeString = tagAttributes["type"] as? String,
let type = LinkType(rawValue: typeString) else {
return [String: AnyObject]()
return [NSAttributedStringKey: AnyObject]()
}

return [
ZSWTappableLabelTappableRegionAttributeName: true,
ZSWTappableLabelHighlightedBackgroundAttributeName: UIColor.lightGray,
ZSWTappableLabelHighlightedForegroundAttributeName: UIColor.white,
NSForegroundColorAttributeName: UIColor.blue,
NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue,
.tappableRegion: true,
.tappableHighlightedBackgroundColor: UIColor.lightGray,
.tappableHighlightedForegroundColor: UIColor.white,
.foregroundColor: UIColor.blue,
.underlineStyle: NSUnderlineStyle.styleSingle.rawValue,
MultipleSwiftViewController.URLAttributeName: type.URL
]
})
Expand All @@ -70,7 +70,7 @@ class LongPressSwiftViewController: UIViewController, ZSWTappableLabelTapDelegat

// MARK: - ZSWTappableLabelTapDelegate

func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [String : Any]) {
func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [NSAttributedStringKey : Any]) {
guard let URL = attributes[SimpleSwiftViewController.URLAttributeName] as? URL else {
return
}
Expand All @@ -84,7 +84,7 @@ class LongPressSwiftViewController: UIViewController, ZSWTappableLabelTapDelegat

// MARK: - ZSWTappableLabelLongPressDelegate

func tappableLabel(_ tappableLabel: ZSWTappableLabel, longPressedAt idx: Int, withAttributes attributes: [String : Any]) {
func tappableLabel(_ tappableLabel: ZSWTappableLabel, longPressedAt idx: Int, withAttributes attributes: [NSAttributedStringKey : Any]) {
guard let URL = attributes[SimpleSwiftViewController.URLAttributeName] as? URL else {
return
}
Expand Down
16 changes: 8 additions & 8 deletions Example/ZSWTappableLabel/MultipleSwiftViewController.swift
Expand Up @@ -18,7 +18,7 @@ class MultipleSwiftViewController: UIViewController, ZSWTappableLabelTapDelegate
return label
}()

static let URLAttributeName = "URL"
static let URLAttributeName = NSAttributedStringKey(rawValue: "URL")

enum LinkType: String {
case Privacy = "privacy"
Expand All @@ -45,15 +45,15 @@ class MultipleSwiftViewController: UIViewController, ZSWTappableLabelTapDelegate
options["link"] = .dynamic({ tagName, tagAttributes, stringAttributes in
guard let typeString = tagAttributes["type"] as? String,
let type = LinkType(rawValue: typeString) else {
return [String: AnyObject]()
return [NSAttributedStringKey: AnyObject]()
}

return [
ZSWTappableLabelTappableRegionAttributeName: true,
ZSWTappableLabelHighlightedBackgroundAttributeName: UIColor.lightGray,
ZSWTappableLabelHighlightedForegroundAttributeName: UIColor.white,
NSForegroundColorAttributeName: UIColor.blue,
NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue,
.tappableRegion: true,
.tappableHighlightedBackgroundColor: UIColor.lightGray,
.tappableHighlightedForegroundColor: UIColor.white,
.foregroundColor: UIColor.blue,
.underlineStyle: NSUnderlineStyle.styleSingle.rawValue,
MultipleSwiftViewController.URLAttributeName: type.URL
]
})
Expand All @@ -69,7 +69,7 @@ class MultipleSwiftViewController: UIViewController, ZSWTappableLabelTapDelegate

// MARK: - ZSWTappableLabelTapDelegate

func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [String : Any] = [:]) {
func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [NSAttributedStringKey : Any] = [:]) {
guard let URL = attributes[SimpleSwiftViewController.URLAttributeName] as? URL else {
return
}
Expand Down
2 changes: 1 addition & 1 deletion Example/ZSWTappableLabel/RootExampleCell.swift
Expand Up @@ -61,7 +61,7 @@ class RootExampleCell: UITableViewCell {
fatalError()
}

func selectButton(_ sender: UIButton) {
@objc func selectButton(_ sender: UIButton) {
if sender === swiftButton {
delegate?.rootExampleCellSelectedSwift(self)
} else {
Expand Down
16 changes: 8 additions & 8 deletions Example/ZSWTappableLabel/SimpleSwiftViewController.swift
Expand Up @@ -16,7 +16,7 @@ class SimpleSwiftViewController: UIViewController, ZSWTappableLabelTapDelegate {
return label
}()

static let URLAttributeName = "URL"
static let URLAttributeName = NSAttributedStringKey(rawValue: "URL")

override func viewDidLoad() {
super.viewDidLoad()
Expand All @@ -26,12 +26,12 @@ class SimpleSwiftViewController: UIViewController, ZSWTappableLabelTapDelegate {
label.tapDelegate = self

let string = NSLocalizedString("Privacy Policy", comment: "")
let attributes: [String: Any] = [
ZSWTappableLabelTappableRegionAttributeName: true,
ZSWTappableLabelHighlightedBackgroundAttributeName: UIColor.lightGray,
ZSWTappableLabelHighlightedForegroundAttributeName: UIColor.white,
NSForegroundColorAttributeName: UIColor.blue,
NSUnderlineStyleAttributeName: NSUnderlineStyle.styleSingle.rawValue,
let attributes: [NSAttributedStringKey: Any] = [
.tappableRegion: true,
.tappableHighlightedBackgroundColor: UIColor.lightGray,
.tappableHighlightedForegroundColor: UIColor.white,
.foregroundColor: UIColor.blue,
.underlineStyle: NSUnderlineStyle.styleSingle.rawValue,
SimpleSwiftViewController.URLAttributeName: URL(string: "http://imgur.com/gallery/VgXCk")!
]

Expand All @@ -45,7 +45,7 @@ class SimpleSwiftViewController: UIViewController, ZSWTappableLabelTapDelegate {

// MARK: - ZSWTappableLabelTapDelegate

func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [String : Any]) {
func tappableLabel(_ tappableLabel: ZSWTappableLabel, tappedAt idx: Int, withAttributes attributes: [NSAttributedStringKey : Any]) {
guard let URL = attributes[SimpleSwiftViewController.URLAttributeName] as? URL else {
return
}
Expand Down
10 changes: 5 additions & 5 deletions ZSWTappableLabel/ZSWTappableLabel.h
Expand Up @@ -21,22 +21,22 @@ NS_ASSUME_NONNULL_BEGIN
* Value is a UIColor. When a touch event occurs within this range, the attribute
* \a NSBackgroundColorAttributeName is applied to the tappable region.
*/
extern NSString *const ZSWTappableLabelHighlightedBackgroundAttributeName;
extern NSAttributedStringKey const ZSWTappableLabelHighlightedBackgroundAttributeName NS_SWIFT_NAME(tappableHighlightedBackgroundColor);
/*!
* @brief Highlight the text color when selected
*
* Value is a UIColor. When a touch event occurs within this range, the attribute
* \a NSForegroundColorAttributeName is applied to the tappable region.
*/
extern NSString *const ZSWTappableLabelHighlightedForegroundAttributeName;
extern NSAttributedStringKey const ZSWTappableLabelHighlightedForegroundAttributeName NS_SWIFT_NAME(tappableHighlightedForegroundColor);

/*!
* @brief A highlighted region - enables interaction
*
* Value is an NSNumber (BOOL). If the location of a touch has this attribute,
* the \ref -[ZSWTappableLabel tapDelegate] will be invoked.
*/
extern NSString *const ZSWTappableLabelTappableRegionAttributeName;
extern NSAttributedStringKey const ZSWTappableLabelTappableRegionAttributeName NS_SWIFT_NAME(tappableRegion);

#pragma mark - Tap delegate

Expand All @@ -59,7 +59,7 @@ extern NSString *const ZSWTappableLabelTappableRegionAttributeName;
*/
- (void)tappableLabel:(ZSWTappableLabel *)tappableLabel
tappedAtIndex:(NSInteger)idx
withAttributes:(NSDictionary<NSString *, id> *)attributes;
withAttributes:(NSDictionary<NSAttributedStringKey, id> *)attributes;
@end

@protocol ZSWTappableLabelLongPressDelegate
Expand All @@ -82,7 +82,7 @@ extern NSString *const ZSWTappableLabelTappableRegionAttributeName;
*/
- (void)tappableLabel:(ZSWTappableLabel *)tappableLabel
longPressedAtIndex:(NSInteger)idx
withAttributes:(NSDictionary<NSString *, id> *)attributes;
withAttributes:(NSDictionary<NSAttributedStringKey, id> *)attributes;
@end

#pragma mark -
Expand Down
8 changes: 4 additions & 4 deletions ZSWTappableLabel/ZSWTappableLabel.m
Expand Up @@ -20,9 +20,9 @@ @implementation ZSWTappableLabelAccessibilityActionLongPress

#pragma mark -

NSString *const ZSWTappableLabelHighlightedBackgroundAttributeName = @"ZSWTappableLabelHighlightedBackgroundAttributeName";
NSString *const ZSWTappableLabelTappableRegionAttributeName = @"ZSWTappableLabelTappableRegionAttributeName";
NSString *const ZSWTappableLabelHighlightedForegroundAttributeName = @"ZSWTappableLabelHighlightedForegroundAttributeName";
NSAttributedStringKey const ZSWTappableLabelHighlightedBackgroundAttributeName = @"ZSWTappableLabelHighlightedBackgroundAttributeName";
NSAttributedStringKey const ZSWTappableLabelTappableRegionAttributeName = @"ZSWTappableLabelTappableRegionAttributeName";
NSAttributedStringKey const ZSWTappableLabelHighlightedForegroundAttributeName = @"ZSWTappableLabelHighlightedForegroundAttributeName";

NSString *const ZSWTappableLabelCharacterIndexUserInfoKey = @"CharacterIndex";

Expand Down Expand Up @@ -331,7 +331,7 @@ - (void)applyHighlightAtIndex:(NSUInteger)characterIndex {

UIColor *foregroundColor = [attributedString attribute:ZSWTappableLabelHighlightedForegroundAttributeName
atIndex:characterIndex
longestEffectiveRange:&foregroundEffectiveRange
longestEffectiveRange:&foregroundEffectiveRange
inRange:NSMakeRange(0, attributedString.length)];

if (highlightColor || foregroundColor) {
Expand Down

0 comments on commit cea1822

Please sign in to comment.