Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upSupport manual application of StringStyle transforms via attributes dictionary #298
Conversation
|
@jvisenti have you been using this in production code? Think it's up to snuff for merging? |
|
@ZevEisenberg We ended up being able to get by without these changes, so I leave it up to you whether you think these changes should be included. I still think the attributes dict should have everything you need to create the attributed string manually, but you may want to hold off until at least one other person requests it. |
|
Sounds reasonable. We should rebase this at some point, or port the changes over, now that #296 has landed. Rebase looks a little hairy, so a by-hand port might make more sense. |
| @@ -25,7 +25,7 @@ public enum Transform { | |||
| case capitalizedWithLocale(Locale) | |||
| case custom(TransformFunction) | |||
|
|
|||
| var transformer: TransformFunction { | |||
| public var transformer: TransformFunction { | |||
This comment has been minimized.
This comment has been minimized.
|
|
||
| internal var name: Name { | ||
| switch self { | ||
| case .lowercase, .lowercaseWithLocale: return Name.lowercase |
This comment has been minimized.
This comment has been minimized.
cjamie
Jun 2, 2019
would like to take advantage of swift's type inference:
| case .lowercase, .lowercaseWithLocale: return Name.lowercase | |
| case .lowercase, .lowercaseWithLocale: return .lowercase |
| @@ -37,7 +37,7 @@ class StringStyleTests: XCTestCase { | |||
| #if os(iOS) || os(tvOS) | |||
| func testTextStyle() { | |||
| let style = StringStyle(.textStyle(titleTextStyle)) | |||
| for (style, fullStyle) in additiviePermutations(for: style) { | |||
| for (style, fullStyle) in additivePermutations(for: style) { | |||
This comment has been minimized.
This comment has been minimized.
cjamie
Jun 2, 2019
while we're here, why don't we prefer forEach instead?
| for (style, fullStyle) in additivePermutations(for: style) { | |
| additivePermutations(for: style).forEach { (style, fullStyle) in |
| @@ -60,7 +60,7 @@ internal enum EmbeddedTransformationHelpers { | |||
| let representations = styleAttributes[BonMotTransformationsAttributeName] as? [StyleAttributes] ?? [] | |||
| let results: [T?] = representations.map { representation in | |||
| for type in embeddedTransformationTypes { | |||
| if let transformation = type.from(dictionary: representation) as? T { | |||
| if let transformation = type.init(dictionary: representation) as? T { | |||
This comment has been minimized.
This comment has been minimized.
cjamie
Jun 2, 2019
for line 61, we can change this to a compactMap so we don't need to go through the collection again, and with flattop
| if let transformation = type.init(dictionary: representation) as? T { | |
| let results: [T] = representations.compactMap { representation in |
| let transform = (attributes[BonMotTransformationsAttributeName] as? StyleAttributes).flatMap(Transform.init) | ||
| XCTAssertNotNil(transform) | ||
|
|
||
| if let transformer = transform?.transformer { |
jvisenti commentedAug 9, 2017
Addresses #297