MagicSwiftNoStrings
Demo project demonstrate some nice patterns to get rid of String-based API using enums, mixins and SwiftGen
Install / Use
/learn @AliSoftware/MagicSwiftNoStringsREADME
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 pod.
Main concepts presented
- In Swift, any type can be used as a constant, you can declare
static leteven of typeUIColororUIFont. This was not true in Objective-C withstatic XXX* constdeclarations. - Namespace your related constants in
struct(seeAppFonts.swift) - You can use
enums, either withrawValueor associated value, to represent ressources finite in numbers, like images in your Assets catalog, colors or strings from yourLocalizable.strings - Use 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.
Related Skills
node-connect
343.3kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
92.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
343.3kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
343.3kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
