Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alisoftware/magicswiftnostrings
Demo project demonstrate some nice patterns to get rid of String-based API using enums, mixins and SwiftGen
https://github.com/alisoftware/magicswiftnostrings
Last synced: about 1 month ago
JSON representation
Demo project demonstrate some nice patterns to get rid of String-based API using enums, mixins and SwiftGen
- Host: GitHub
- URL: https://github.com/alisoftware/magicswiftnostrings
- Owner: AliSoftware
- Created: 2016-02-20T20:36:36.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2016-02-26T17:55:18.000Z (almost 9 years ago)
- Last Synced: 2025-01-05T08:51:23.043Z (about 2 months ago)
- Language: Swift
- Homepage:
- Size: 1.48 MB
- Stars: 8
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Enums as Constants — SwiftGen Demo
## Context
This project has been used as a demo during some live coding talks (like iOS Perth Meetup talk in February 2016).
## Aim of this demo
This project is used to demonstrate various tricks and pattern to make constants more Swifty:
* using enums as constants for various stuff (images, colors, fonts, …)
* using Protocols with Default Implementations for Storyboard Scenes/Segues and for UITableViewCells / UICollectionViewCells, like with the [Reusable](https://github.com/AliSoftware/Reusable) pod.## Main concepts presented
* In Swift, any type can be used as a constant, you can declare `static let` even of type `UIColor` or `UIFont`. This was not true in Objective-C with `static XXX* const` declarations.
* Namespace your related constants in `struct` (see `AppFonts.swift`)
* You can use `enums`, either with `rawValue` or associated value, to represent ressources finite in numbers, like images in your Assets catalog, colors or strings from your `Localizable.strings`
* Use [SwiftGen](https://github.com/AliSoftware/SwiftGen) to auto-generate the Swift code containing your constants. Adding the tool as a "Script Build Phase" in your project will ensure your constants are always up to date with your resources (images, colors, strings, …) even after adding or removing some of those resources from your project.