Skip to content

Commit 2d87582

Browse files
authored
Merge pull request SwiftGen#715 from SwiftGen/update-playground
Update playground before 6.2.0 release #trivial
2 parents 596c9da + b066bcc commit 2d87582

File tree

20 files changed

+87
-32
lines changed

20 files changed

+87
-32
lines changed

CHANGELOG.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,22 @@
3535
* You can now use `swiftgen template doc [parser] [templateName]` on the command line to quickly open the documentation for templates on GitHub directly from your terminal.
3636
[@AliSoftware](https://github.com/AliSoftware)
3737
[#697](https://github.com/SwiftGen/SwiftGen/pull/697)
38-
* Each command now accepts an `options` dictionary, with which you can set internal parser settings to change its behaviour. See the commands' specific documentation for available options.
38+
* Each parser now accepts an `options` dictionary, with which you can set internal parser settings to change its behaviour. See the parser's specific documentation for available options.
3939
[David Jennes](https://github.com/djbe)
4040
[#587](https://github.com/SwiftGen/SwiftGen/pull/587)
4141
[#597](https://github.com/SwiftGen/SwiftGen/pull/597)
42-
* Strings: the parser now accepts a `separator` option, used to split keys into structured components. The default separator remains `.`. For more information, check the [command's documentation](Documentation/Parsers/strings.md#customization).
42+
* Strings: the parser now accepts a `separator` option, used to split keys into structured components. The default separator remains `.`. For more information, check the [parser's documentation](Documentation/Parsers/strings.md#customization).
4343
[David Jennes](https://github.com/djbe)
44-
[#576](https://github.com/SwiftGen/SwiftGen/issue/576)
44+
[#576](https://github.com/SwiftGen/SwiftGen/issues/576)
4545
[#588](https://github.com/SwiftGen/SwiftGen/pull/588)
4646
* Core Data: the built-in templates now support an optional `extraImports` parameter. With this you can provide a list of modules to additionally import, for when you have properties with types from external modules. For more information, check the [template's documentation](Documentation/templates/coredata/swift4.md#customization).
4747
[David Jennes](https://github.com/djbe)
48-
[#591](https://github.com/SwiftGen/SwiftGen/issue/591)
48+
[#591](https://github.com/SwiftGen/SwiftGen/issues/591)
4949
[#592](https://github.com/SwiftGen/SwiftGen/pull/592)
5050
* Core Data: the built-in templates now support `RawRepresentable` attributes (such as `enum`, `OptionSet`, …). They'll check the "User Info" of an attribute for a `RawType` key, which should be set to the type name you want to use for that attribute. To avoid optional attributes, you can also add the `unwrapOptional` user info key. For more information, check the [template's documentation](Documentation/templates/coredata/swift4.md#userinfo-keys).
5151
[David Jennes](https://github.com/djbe)
52-
[#566](https://github.com/SwiftGen/SwiftGen/issue/566)
53-
[#609](https://github.com/SwiftGen/SwiftGen/issue/609)
52+
[#566](https://github.com/SwiftGen/SwiftGen/issues/566)
53+
[#609](https://github.com/SwiftGen/SwiftGen/issues/609)
5454
[#593](https://github.com/SwiftGen/SwiftGen/pull/593)
5555
[#610](https://github.com/SwiftGen/SwiftGen/pull/610)
5656
* Strings: the built-in templates now accept a parameter for customizing the localization function.
@@ -67,13 +67,13 @@
6767
* Templates: Bundle now use static property on BundleToken for better performance.
6868
[shuoli84](https://github.com/shuoli84)
6969
[#623](https://github.com/SwiftGen/SwiftGen/issues/623)
70-
* All commands now have built-in Swift 5 templates.
70+
* All parsers now have built-in Swift 5 templates.
7171
[David Jennes](https://github.com/djbe)
72-
[#595](https://github.com/SwiftGen/SwiftGen/issue/595)
72+
[#595](https://github.com/SwiftGen/SwiftGen/issues/595)
7373
[#600](https://github.com/SwiftGen/SwiftGen/pull/600)
7474
* Most templates now accept a parameter to force having the file name used as namespace (`enum <FileName>`) in generated code _even if_ there's only one single input file.
7575
[Viktoras Laukevičius](https://github.com/viktorasl)
76-
[#669](https://github.com/SwiftGen/SwiftGen/issue/669)
76+
[#669](https://github.com/SwiftGen/SwiftGen/issues/669)
7777
[@AliSoftware](https://github.com/AliSoftware)
7878
[#693](https://github.com/SwiftGen/SwiftGen/pull/693)
7979

@@ -84,7 +84,7 @@
8484
[#706](https://github.com/SwiftGen/SwiftGen/pull/706)
8585
* XCAssets: improved the performance for color assets by caching the resolved colors.
8686
[David Jennes](https://github.com/djbe)
87-
[#578](https://github.com/SwiftGen/SwiftGen/issue/578)
87+
[#578](https://github.com/SwiftGen/SwiftGen/issues/578)
8888
[#589](https://github.com/SwiftGen/SwiftGen/pull/589)
8989
* Core Data: `entityName` is now correctly a `class var` instead of a `class func`.
9090
[David Jennes](https://github.com/djbe)
@@ -158,7 +158,7 @@
158158
[Wolfgang Lutz](https://github.com/lutzifer)
159159
[#355](https://github.com/SwiftGen/SwiftGen/issues/355)
160160
[#564](https://github.com/SwiftGen/SwiftGen/pull/564)
161-
* Each command now accepts a `filter` option, which accepts a regular expression for filtering input paths. The filter is applied to individual paths as well as when the command recurses into directories.
161+
* Each parser now accepts a `filter` option, which accepts a regular expression for filtering input paths. The filter is applied to individual paths as well as when the parser recurses into directories.
162162
[David Jennes](https://github.com/djbe)
163163
[#383](https://github.com/SwiftGen/SwiftGen/issues/383)
164164
[#570](https://github.com/SwiftGen/SwiftGen/pull/570)
@@ -281,7 +281,7 @@ Read the [SwiftGen 6.0 Migration Guide](Documentation/MigrationGuide.md#swiftgen
281281
* Add support for Swift Package Manager and Mint.
282282
[Yonas Kolb](https://github.com/yonaskolb)
283283
[#411](https://github.com/SwiftGen/SwiftGen/pull/411)
284-
* The `swiftgen.yml` config file now accepts multiple outputs for each command, allowing you to generate multiple outputs from the same files and content. This also means that the `output` parameter is now deprecated, in favour of the `outputs` parameter, and it may be removed in a future version of SwiftGen. Similarly, the `paths` parameter has been renamed to `inputs` for consistency. You can always use `swiftgen config lint` to validate your configuration file.
284+
* The `swiftgen.yml` config file now accepts multiple outputs for each parser, allowing you to generate multiple outputs from the same files and content. This also means that the `output` parameter is now deprecated, in favour of the `outputs` parameter, and it may be removed in a future version of SwiftGen. Similarly, the `paths` parameter has been renamed to `inputs` for consistency. You can always use `swiftgen config lint` to validate your configuration file.
285285
[David Jennes](https://github.com/djbe)
286286
[#424](https://github.com/SwiftGen/SwiftGen/pull/424)
287287
[#510](https://github.com/SwiftGen/SwiftGen/pull/510)
@@ -298,7 +298,7 @@ Read the [SwiftGen 6.0 Migration Guide](Documentation/MigrationGuide.md#swiftgen
298298
[Olivier Halligon](https://github.com/AliSoftware)
299299
[#456](https://github.com/SwiftGen/SwiftGen/pull/456)
300300
[#481](https://github.com/SwiftGen/SwiftGen/pull/481)
301-
* Added support for JSON, Plist and YAML files using the `swiftgen json`, `swiftgen plist` and `swiftgen yaml` commands. The parsed contexts and the generated files for each command have been kept quite similar, for easier switching between file formats.
301+
* Added support for JSON, Plist and YAML files using the `swiftgen json`, `swiftgen plist` and `swiftgen yaml` commands. The parsed contexts and the generated files for each parser have been kept quite similar, for easier switching between file formats.
302302
[John T McIntosh](https://github.com/johntmcintosh)
303303
[Toshihiro Suzuki](https://github.com/toshi0383)
304304
[Peter Livesey](https://github.com/plivesey)
@@ -309,7 +309,7 @@ Read the [SwiftGen 6.0 Migration Guide](Documentation/MigrationGuide.md#swiftgen
309309
[#188](https://github.com/SwiftGen/SwiftGen/pull/188)
310310
[#493](https://github.com/SwiftGen/SwiftGen/pull/493)
311311
[#504](https://github.com/SwiftGen/SwiftGen/pull/504)
312-
* Updated the playgrounds with the new `json`, `plist` and `yaml` commands, and updated the other pages to reflect the template changes.
312+
* Updated the playgrounds with the new `json`, `plist` and `yaml` parsers, and updated the other pages to reflect the template changes.
313313
[David Jennes](https://github.com/djbe)
314314
[#495](https://github.com/SwiftGen/SwiftGen/pull/495)
315315
* We're deprecating the old `--template` CLI option in favor of `--templateName`, to better match the naming of the other options and the configuration file. The old `--template` option will remain until the next major version.

SwiftGen.playground/Pages/Colors-Demo.xcplaygroundpage/Contents.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
//: * [Demo for `yaml` parser](YAML-Demo)
1212

1313
//: #### Example of code generated by `colors` parser with "literals-swift4" template
14+
//: - Note: The `colors` parsers is primarily aimed to parse Android `colors.xml` files and text files.
15+
//: In most cases, you should prefer defining your colors in asset catalogs – as those support multiple variants for light/dark mode, P3 colorspace, and more – and use the `xcassets` parser instead to generate constants for those colors.
1416

1517
#if os(OSX)
1618
import AppKit

SwiftGen.playground/Pages/InterfaceBuilder-Demo.xcplaygroundpage/Contents.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,12 @@ you can easily switch or directly compare the passed in `segue` with the corresp
9696
segues for a specific storyboard.
9797
*******************************************************************************/
9898
//override func prepareForSegue(_ segue: UIStoryboardSegue, sender sender: AnyObject?) {
99-
// switch UIStoryboard.Segue.Message(segue) {
100-
// case .custom?:
99+
// switch StoryboardSegue.Message(segue) {
100+
// case .showNavCtrl?:
101101
// // Prepare for your custom segue transition
102102
// case .nonCustom?:
103103
// // Pass in information to the destination View Controller
104+
// default:
105+
// break // not the expected segue
104106
// }
105107
//}

SwiftGen.playground/Pages/XCAssets-Demo.xcplaygroundpage/Contents.swift

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//: * Demo for `xcassets` parser
1111
//: * [Demo for `yaml` parser](YAML-Demo)
1212

13-
// setup code
13+
// setup code to make this work in playground
1414
// swiftlint:disable convenience_type
1515
private final class BundleToken {
1616
static let bundle: Bundle = {
@@ -82,16 +82,49 @@ internal enum Asset {
8282
//: #### Usage Example
8383

8484
// images
85+
86+
// Tip: Use "Show Result" box on the right to display the images inline in playground
8587
let image1 = UIImage(asset: Asset.Food.Exotic.banana)
8688
let image2 = Asset.Food.Round.tomato.image
8789

90+
import PlaygroundSupport
91+
// Show fruits animated in the playground's liveView
92+
PlaygroundPage.current.liveView = {
93+
let assets = [
94+
Asset.Food.Exotic.banana,
95+
Asset.Food.Exotic.mango,
96+
Asset.Food.Round.apricot,
97+
Asset.Food.Round.apple,
98+
Asset.Food.Round.tomato,
99+
Asset.Food.Round.Double.cherry
100+
]
101+
let iv = UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
102+
iv.animationImages = assets.map(\.image)
103+
iv.animationDuration = TimeInterval(assets.count)/2 // 0.5s per image
104+
iv.startAnimating()
105+
return iv
106+
}()
107+
88108
// colors
89109
let color1 = UIColor(asset: Asset.Styles.Vengo.primary)
90110
let color2 = Asset.Styles.Vengo.tint.color
91111

112+
113+
/* Colors support variations for different interface styles (light/dark mode) */ _ = {
114+
let vc = UIViewController()
115+
vc.overrideUserInterfaceStyle = .dark
116+
vc.view.backgroundColor = Asset.Styles.Vengo.primary.color
117+
vc.view // Use "Show Result" box on the right to display contextualized color inline in playground
118+
119+
vc.overrideUserInterfaceStyle = .light
120+
vc.view // Use "Show Result" box on the right to display contextualized color inline in playground
121+
}()
122+
92123
// data
93-
let data1 = NSDataAsset(asset: Asset.Files.data)
94-
let data2 = Asset.Files.readme.data
124+
let dataAsset1 = NSDataAsset(asset: Asset.Files.data)
125+
let dataAsset2 = Asset.Files.readme.data
126+
let readmeText = String(data: dataAsset2.data, encoding: .utf8) ?? "-"
127+
print(readmeText)
95128

96129
// AR resources
97130
let paintingReferenceImages = Asset.Targets.paintings.referenceImages
546 KB
Binary file not shown.
0 Bytes
Binary file not shown.
403 Bytes
Binary file not shown.
496 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)