-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Mike Packard <[email protected]>
- Loading branch information
1 parent
ae028e9
commit cdbd56e
Showing
9 changed files
with
201 additions
and
7 deletions.
There are no files selected for viewing
Binary file modified
BIN
+10.2 KB
(110%)
...ode/package.xcworkspace/xcuserdata/nguyenphong.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# ConvertSwift | ||
# Swift Extension | ||
|
||
A description of this package. | ||
|
||
|
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,14 @@ | ||
import Foundation | ||
|
||
@resultBuilder | ||
public enum ArrayBuilder<Element> { | ||
public static func buildBlock(_ components: Element...) -> [Element] { | ||
components | ||
} | ||
} | ||
|
||
public extension Array { | ||
init(@ArrayBuilder<Element> builder: () -> [Element]) { | ||
self = builder() | ||
} | ||
} |
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,16 @@ | ||
import Foundation | ||
|
||
@resultBuilder | ||
public enum DictionaryBuilder<Key: Hashable, Value> { | ||
static func buildBlock(_ components: Dictionary<Key, Value>...) -> Dictionary<Key, Value> { | ||
components.reduce(into: [:]) { | ||
$0.merge($1) { _, new in new } | ||
} | ||
} | ||
} | ||
|
||
public extension Dictionary { | ||
init(@DictionaryBuilder<Key, Value> builder: () -> Dictionary) { | ||
self = builder() | ||
} | ||
} |
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,48 @@ | ||
import Foundation | ||
|
||
public protocol StringBuilerProtocol { | ||
var value: String {get} | ||
} | ||
|
||
@resultBuilder | ||
public enum StringBuilder { | ||
public static func buildArray(_ strings: [[String]]) -> [String] { | ||
strings.flatMap { $0 } | ||
} | ||
|
||
public static func buildBlock(_ strings: [String]...) -> [String] { | ||
strings.flatMap { $0 } | ||
} | ||
|
||
public static func buildEither(first strings: [String]) -> [String] { | ||
strings | ||
} | ||
|
||
public static func buildEither(second strings: [String]) -> [String] { | ||
strings | ||
} | ||
|
||
public static func buildExpression(_ string: String) -> [String] { | ||
[string] | ||
} | ||
|
||
public static func buildLimitedAvailability(_ string: [String]) -> [String] { | ||
string | ||
} | ||
|
||
public static func buildOptional(_ strings: [String]?) -> [String] { | ||
strings ?? [] | ||
} | ||
|
||
public static func buildFinalResult(_ strings: [String]) -> [String] { | ||
strings | ||
} | ||
} | ||
|
||
extension String { | ||
|
||
public init(separator: String = "", @StringBuilder builder: () -> [String]) { | ||
self = builder().joined(separator: separator) | ||
} | ||
|
||
} |
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,69 @@ | ||
import Foundation | ||
import SwiftUI | ||
|
||
#if canImport(SwiftUI) | ||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) | ||
public extension String { | ||
func toText() -> Text { | ||
Text(self) | ||
} | ||
} | ||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) | ||
public extension Sequence where Element == Text { | ||
func joined(separator: Text = Text("")) -> Text { | ||
return reduce(Text("")) { (result, text) in | ||
return result + separator + text | ||
} | ||
} | ||
} | ||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) | ||
@resultBuilder | ||
public struct TextBuilder { | ||
public static func buildArray(_ texts: [[Text]]) -> [Text] { | ||
texts.flatMap { $0 } | ||
} | ||
|
||
public static func buildBlock(_ texts: [Text]...) -> [Text] { | ||
texts.flatMap { $0 } | ||
} | ||
|
||
public static func buildEither(first texts: [Text]) -> [Text] { | ||
texts | ||
} | ||
|
||
public static func buildEither(second texts: [Text]) -> [Text] { | ||
texts | ||
} | ||
|
||
public static func buildExpression(_ string: String) -> [Text] { | ||
[string.toText()] | ||
} | ||
|
||
public static func buildExpression(_ text: Text) -> [Text] { | ||
[text] | ||
} | ||
|
||
public static func buildLimitedAvailability(_ texts: [Text]) -> [Text] { | ||
texts | ||
} | ||
|
||
public static func buildOptional(_ texts: [Text]?) -> [Text] { | ||
texts ?? [] | ||
} | ||
|
||
public static func buildFinalResult(_ texts: [Text]) -> [Text] { | ||
texts | ||
} | ||
} | ||
|
||
@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *) | ||
public extension Text { | ||
init(separator: Text = Text(""), @TextBuilder builder: () -> [Text]) { | ||
self = builder().joined(separator: separator) | ||
} | ||
|
||
init(separator: String = "", @TextBuilder builder: () -> [Text]) { | ||
self.init(separator: Text(separator), builder: builder) | ||
} | ||
} | ||
#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