diff --git a/ShortcutsSwift.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Contents.swift b/ShortcutsSwift.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Contents.swift index ebc91a9..ffaec32 100644 --- a/ShortcutsSwift.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Contents.swift +++ b/ShortcutsSwift.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page1.playgroundpage/Contents.swift @@ -1,13 +1,13 @@ var batteryLevel = Variable.actionOutput() -let shortcut = buildShortcut( - comment("This Shortcut was generated in Swift.") + - getBatteryLevel(&batteryLevel) + - ifLessThan(20, ifTrue: ( - setLowPowerMode(true) + - showResult("Your battery is at \(batteryLevel)%, you might want to charge it.") - ), ifFalse: ( +let shortcut = buildShortcut([ + comment("This Shortcut was generated in Swift."), + getBatteryLevel(&batteryLevel), + ifLessThan(20, ifTrue: [ + setLowPowerMode(true), + showResult("Your battery is at \(batteryLevel)%, you might want to charge it."), + ], ifFalse: ( showResult("Your battery is at \(batteryLevel)%, you're probably fine for now.") - )) -) + )), +]) shareShortcut(shortcut, named: "Warn for Low Battery Level") diff --git a/ShortcutsSwift.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Contents.swift b/ShortcutsSwift.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Contents.swift index 8a7b701..74d076c 100644 --- a/ShortcutsSwift.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Contents.swift +++ b/ShortcutsSwift.playgroundbook/Contents/Chapters/Chapter1.playgroundchapter/Pages/Page2.playgroundpage/Contents.swift @@ -1,12 +1,12 @@ -let shortcut = buildShortcut( - comment("This Shortcut was generated in Swift.") + - ask(question: "WHAT 👏 DO 👏 YOU 👏 WANT 👏 TO 👏 SAY") + - changeCase(to: .uppercase) + - replaceText("[\\s]", replaceWith: " 👏 ", regularExpression: true) + +let shortcut = buildShortcut([ + comment("This Shortcut was generated in Swift."), + ask(question: "WHAT 👏 DO 👏 YOU 👏 WANT 👏 TO 👏 SAY"), + changeCase(to: .uppercase), + replaceText("[\\s]", replaceWith: " 👏 ", regularExpression: true), chooseFromMenu(items: [ ("Share", share()), ("Copy to Clipboard", copyToClipboard()), - ]) -) + ]), +]) shareShortcut(shortcut, named: "Clap Along") diff --git a/ShortcutsSwift.playgroundbook/Contents/Sources/Action.swift b/ShortcutsSwift.playgroundbook/Contents/Sources/Action.swift index 04be609..beccaf9 100644 --- a/ShortcutsSwift.playgroundbook/Contents/Sources/Action.swift +++ b/ShortcutsSwift.playgroundbook/Contents/Sources/Action.swift @@ -16,9 +16,9 @@ public protocol ActionContainer { var actions: [Action] { get } } -extension Array: ActionContainer where Element == Action { +extension Array: ActionContainer where Element: ActionContainer { public var actions: [Action] { - return self + return flatMap { $0.actions } } } @@ -27,13 +27,3 @@ extension Action: ActionContainer { return [self] } } - -public func + (lhs: ActionContainer, rhs: ActionContainer) -> ActionContainer { - let leftActions = lhs.actions - let rightActions = rhs.actions - var result = [Action]() - result.reserveCapacity(leftActions.count + rightActions.count) - result.append(contentsOf: leftActions) - result.append(contentsOf: rightActions) - return result -}