-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
295b17e
commit 3951ee4
Showing
8 changed files
with
145 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// swift-tools-version:5.1 | ||
// swift-tools-version:5.4 | ||
|
||
import PackageDescription | ||
|
||
|
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
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
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
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
46 changes: 46 additions & 0 deletions
46
SwiftyAttributes/Sources/common/SwiftyAttributedStringBuilder.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// SwiftyAttributedStringBuilder.swift | ||
// SwiftyAttributes | ||
// | ||
// Created by Roman Podymov on 09/09/21. | ||
// Copyright © 2021 Roman Podymov. All rights reserved. | ||
// | ||
|
||
#if swift(>=5.4) | ||
import Foundation | ||
|
||
public protocol AttributesProvider { | ||
var attributes: [Attribute] { get } | ||
} | ||
|
||
extension Attribute: AttributesProvider { | ||
public var attributes: [Attribute] { [self] } | ||
} | ||
|
||
extension Array: AttributesProvider where Element == Attribute { | ||
public var attributes: [Attribute] { self } | ||
} | ||
|
||
@resultBuilder | ||
public struct SwiftyAttributedStringBuilder { | ||
public static func buildBlock(_ components: AttributesProvider...) -> [Attribute] { | ||
components.flatMap { $0.attributes } | ||
} | ||
|
||
public static func buildEither(first components: [AttributesProvider]) -> [Attribute] { | ||
components.flatMap { $0.attributes } | ||
} | ||
|
||
public static func buildEither(second components: [AttributesProvider]) -> [Attribute] { | ||
components.flatMap { $0.attributes } | ||
} | ||
|
||
public static func buildOptional(_ components: [Attribute]?) -> [Attribute] { | ||
components?.flatMap { $0.attributes } ?? [] | ||
} | ||
|
||
public static func buildFinalResult(_ components: [Attribute]) -> [NSAttributedString.Key: Any] { | ||
dictionary(from: components) | ||
} | ||
} | ||
#endif |
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
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