This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
label.adjustsFontForContentSizeCategory = true | |
NotificationCenter.default.addObserver(self, | |
selector: #selector (uiContentSizeCategoryChanged), | |
name: .FontMetricsContentSizeCategoryDidChange, | |
object: nil) | |
// ... | |
// ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import UIKit | |
// MARK: - AttributedStringView | |
class AttributedStringView: UIView { | |
/// `FontSetter` is a closure type used to recalculate the font size. | |
typealias FontSetter = () -> UIFont | |
/// A `UILabel` that will render the attributed string with Dynamic Type. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSCharacterSet { | |
var characters: [String] { | |
/// An array to hold all the found characters | |
var characters: [String] = [] | |
/// Iterate over the 17 Unicode planes (0..16) | |
for plane:UInt8 in 0..<17 { | |
/// Iterating over all potential code points of each plane could be expensive as | |
/// there can be as many as 2^16 code points per plane. Therefore, only search |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let string4 = "᧐᪂᧐" | |
print("\"\(string4)\" only contains numbers: \(isValidNumeral(input4: string4))") | |
/// "᧐᪂᧐" only contains numbers: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func isValidNumeral(input4: String) -> Bool { | |
let numbers = CharacterSet.decimalDigits | |
let rangeOfInvalidCharacters = input4.rangeOfCharacter(from: numbers.inverted) | |
return rangeOfInvalidCharacters == nil | |
} | |
let string1 = "qwerty12345" | |
let string2 = "qwerty" | |
let string3 = "12345" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let numbers: NSCharacterSet = NSCharacterSet.decimalDigits as NSCharacterSet | |
let character: UTF32Char = UTF32Char(48) /// U+0030 is "0" (48 Decimal = 0x30 Hex) | |
numbers.longCharacterIsMember(character) /// returns `true` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print(CharacterSet.decimalDigits) | |
/// <CFCharacterSet Predefined DecimalDigit Set> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let stringToCheck: String = "42" | |
let numbers: CharacterSet = CharacterSet.decimalDigits | |
let stringIsANumber: Bool = stringToCheck.rangeOfCharacter(from: numbers.inverted) == nil | |
/// returns: `true` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
@testable import PracticalDynamicTypePart2 | |
class PracticalDynamicTypePart2Tests: XCTestCase { | |
var subject: Hal9000! | |
override func setUp() { | |
super.setUp() | |
subject = Hal9000() |