update playground files
This commit is contained in:
committed by
Olivier Halligon
parent
39d4cee748
commit
f43da400a1
@@ -1,62 +1,49 @@
|
||||
//: #### Other pages
|
||||
//:
|
||||
//: * [Demo for `swiftgen strings`](Strings-Demo)
|
||||
//: * [Demo for `swiftgen images`](Images-Demo)
|
||||
//: * [Demo for `swiftgen storyboards`](Storyboards-Demo)
|
||||
//: * Demo for `swiftgen colors`
|
||||
//: * [Demo for `swiftgen fonts`](Fonts-Demo)
|
||||
//: * [Demo for `swiftgen storyboards`](Storyboards-Demo)
|
||||
//: * [Demo for `swiftgen strings`](Strings-Demo)
|
||||
//: * [Demo for `swiftgen xcassets`](XCAssets-Demo)
|
||||
|
||||
//: #### Example of code generated by swiftgen-colors
|
||||
|
||||
import UIKit.UIColor
|
||||
typealias Color = UIColor
|
||||
|
||||
extension UIColor {
|
||||
convenience init(rgbaValue: UInt32) {
|
||||
let red = CGFloat((rgbaValue >> 24) & 0xff) / 255.0
|
||||
let green = CGFloat((rgbaValue >> 16) & 0xff) / 255.0
|
||||
let blue = CGFloat((rgbaValue >> 8) & 0xff) / 255.0
|
||||
let alpha = CGFloat((rgbaValue ) & 0xff) / 255.0
|
||||
|
||||
self.init(red: red, green: green, blue: blue, alpha: alpha)
|
||||
}
|
||||
extension Color {
|
||||
convenience init(rgbaValue: UInt32) {
|
||||
let red = CGFloat((rgbaValue >> 24) & 0xff) / 255.0
|
||||
let green = CGFloat((rgbaValue >> 16) & 0xff) / 255.0
|
||||
let blue = CGFloat((rgbaValue >> 8) & 0xff) / 255.0
|
||||
let alpha = CGFloat((rgbaValue ) & 0xff) / 255.0
|
||||
|
||||
self.init(red: red, green: green, blue: blue, alpha: alpha)
|
||||
}
|
||||
}
|
||||
|
||||
enum ColorName {
|
||||
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#339666"></span>
|
||||
/// Alpha: 100% <br/> (0x339666ff)
|
||||
case articleBody
|
||||
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
|
||||
/// Alpha: 100% <br/> (0xff66ccff)
|
||||
case articleFootnote
|
||||
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#33fe66"></span>
|
||||
/// Alpha: 100% <br/> (0x33fe66ff)
|
||||
case articleTitle
|
||||
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
|
||||
/// Alpha: 100% <br/> (0xff66ccff)
|
||||
case cyanColor
|
||||
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
|
||||
/// Alpha: 80% <br/> (0xffffffcc)
|
||||
case translucent
|
||||
|
||||
var rgbaValue: UInt32 {
|
||||
switch self {
|
||||
case .articleBody: return 0x339666ff
|
||||
case .articleFootnote: return 0xff66ccff
|
||||
case .articleTitle: return 0x33fe66ff
|
||||
case .cyanColor: return 0xff66ccff
|
||||
case .translucent: return 0xffffffcc
|
||||
}
|
||||
}
|
||||
|
||||
var color: UIColor {
|
||||
return UIColor(named: self)
|
||||
}
|
||||
struct ColorName {
|
||||
let rgbaValue: UInt32
|
||||
var color: Color { return Color(named: self) }
|
||||
|
||||
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#339666"></span>
|
||||
/// Alpha: 100% <br/> (0x339666ff)
|
||||
static let articleBody = ColorName(rgbaValue: 0x339666ff)
|
||||
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ff66cc"></span>
|
||||
/// Alpha: 100% <br/> (0xff66ccff)
|
||||
static let articleFootnote = ColorName(rgbaValue: 0xff66ccff)
|
||||
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#33fe66"></span>
|
||||
/// Alpha: 100% <br/> (0x33fe66ff)
|
||||
static let articleTitle = ColorName(rgbaValue: 0x33fe66ff)
|
||||
/// <span style="display:block;width:3em;height:2em;border:1px solid black;background:#ffffff"></span>
|
||||
/// Alpha: 80% <br/> (0xffffffcc)
|
||||
static let `private` = ColorName(rgbaValue: 0xffffffcc)
|
||||
}
|
||||
|
||||
extension UIColor {
|
||||
convenience init(named name: ColorName) {
|
||||
self.init(rgbaValue: name.rgbaValue)
|
||||
}
|
||||
extension Color {
|
||||
convenience init(named color: ColorName) {
|
||||
self.init(rgbaValue: color.rgbaValue)
|
||||
}
|
||||
}
|
||||
|
||||
//: #### Usage Example
|
||||
@@ -64,7 +51,7 @@ extension UIColor {
|
||||
UIColor(named: .articleTitle)
|
||||
ColorName.articleBody.color
|
||||
UIColor(named: .articleBody)
|
||||
UIColor(named: .translucent)
|
||||
/* Only possible if you used `enumBuilder.build(generateStringInit: true)` to generate the enum */
|
||||
//let orange = UIColor(hexString: "#ffcc88")
|
||||
UIColor(named: .private)
|
||||
|
||||
/* convenience initializer */
|
||||
let lightGreen = UIColor(rgbaValue: 0x00ff88ff)
|
||||
|
||||
@@ -1,43 +1,66 @@
|
||||
//: #### Other pages
|
||||
//: * [Demo for `swiftgen strings`](Colors-Demo)
|
||||
//: * [Demo for `swiftgen images`](Images-Demo)
|
||||
//: * [Demo for `swiftgen storyboards`](Storyboards-Demo)
|
||||
//:
|
||||
//: * [Demo for `swiftgen colors`](Colors-Demo)
|
||||
//: * Demo for `swiftgen fonts`
|
||||
//: * [Demo for `swiftgen storyboards`](Storyboards-Demo)
|
||||
//: * [Demo for `swiftgen strings`](Strings-Demo)
|
||||
//: * [Demo for `swiftgen xcassets`](XCAssets-Demo)
|
||||
|
||||
//: #### Example of code generated by swiftgen-fonts
|
||||
|
||||
import UIKit.UIFont
|
||||
typealias Font = UIFont
|
||||
|
||||
protocol FontConvertible {
|
||||
func font(size: CGFloat) -> UIFont!
|
||||
struct FontConvertible {
|
||||
let name: String
|
||||
let family: String
|
||||
let path: String
|
||||
|
||||
func font(size: CGFloat) -> Font! {
|
||||
return Font(font: self, size: size)
|
||||
}
|
||||
|
||||
func register() {
|
||||
let bundle = Bundle(for: BundleToken.self)
|
||||
|
||||
guard let url = bundle.url(forResource: path, withExtension: nil) else {
|
||||
return
|
||||
}
|
||||
|
||||
var errorRef: Unmanaged<CFError>?
|
||||
CTFontManagerRegisterFontsForURL(url as CFURL, .process, &errorRef)
|
||||
}
|
||||
}
|
||||
|
||||
extension FontConvertible where Self: RawRepresentable, Self.RawValue == String {
|
||||
func font(size: CGFloat) -> UIFont! {
|
||||
return UIFont(font: self, size: size)
|
||||
extension Font {
|
||||
convenience init!(font: FontConvertible, size: CGFloat) {
|
||||
#if os(iOS) || os(tvOS) || os(watchOS)
|
||||
if UIFont.fontNames(forFamilyName: font.family).isEmpty {
|
||||
font.register()
|
||||
}
|
||||
}
|
||||
#elseif os(OSX)
|
||||
if NSFontManager.shared().availableMembers(ofFontFamily: font.family) == nil {
|
||||
font.register()
|
||||
}
|
||||
#endif
|
||||
|
||||
extension UIFont {
|
||||
convenience init!<FontType: FontConvertible>
|
||||
(font: FontType, size: CGFloat)
|
||||
where FontType: RawRepresentable, FontType.RawValue == String {
|
||||
self.init(name: font.rawValue, size: size)
|
||||
}
|
||||
self.init(name: font.name, size: size)
|
||||
}
|
||||
}
|
||||
|
||||
struct FontFamily {
|
||||
enum Helvetica: String, FontConvertible {
|
||||
case regular = "Helvetica"
|
||||
case bold = "Helvetica-Bold"
|
||||
enum Helvetica {
|
||||
static let regular = FontConvertible(name: "Helvetica", family: "Helvetica", path: "Helvetica.ttf")
|
||||
static let bold = FontConvertible(name: "Helvetica-Bold", family: "Helvetica", path: "Helvetica-Bold.ttf")
|
||||
}
|
||||
enum HelveticaNeue: String, FontConvertible {
|
||||
case regular = "HelveticaNeue"
|
||||
case bold = "HelveticaNeue-Bold"
|
||||
enum HelveticaNeue {
|
||||
static let regular = FontConvertible(name: "HelveticaNeue", family: "HelveticaNeue", path: "HelveticaNeue.ttf")
|
||||
static let bold = FontConvertible(name: "HelveticaNeue-Bold", family: "HelveticaNeue", path: "HelveticaNeue-Bold.ttf")
|
||||
}
|
||||
}
|
||||
|
||||
private final class BundleToken {}
|
||||
|
||||
//: #### Usage Example
|
||||
// Using the UIFont constructor…
|
||||
let helvetica = UIFont(font: FontFamily.Helvetica.regular, size: 20.0)
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
//: #### Other pages
|
||||
//:
|
||||
//: * [Demo for `swiftgen strings`](Strings-Demo)
|
||||
//: * Demo for `swiftgen images`
|
||||
//: * [Demo for `swiftgen storyboards`](Storyboards-Demo)
|
||||
//: * [Demo for `swiftgen colors`](Colors-Demo)
|
||||
//: * [Demo for `swiftgen fonts`](Fonts-Demo)
|
||||
|
||||
//: #### Example of code generated by swiftgen-assets
|
||||
|
||||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
|
||||
|
||||
import UIKit
|
||||
|
||||
enum Asset: String {
|
||||
case exoticBanana = "Exotic/Banana"
|
||||
case exoticMango = "Exotic/Mango"
|
||||
case lemon = "Lemon"
|
||||
case roundApricot = "Round/Apricot"
|
||||
case roundOrange = "Round/Orange"
|
||||
case roundApple = "Round/Apple"
|
||||
case roundDoubleCherry = "Round/Double/Cherry"
|
||||
case roundTomato = "Round/Tomato"
|
||||
|
||||
var image: UIImage {
|
||||
return UIImage(asset: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension UIImage {
|
||||
convenience init!(asset: Asset) {
|
||||
self.init(named: asset.rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
//: #### Usage Example
|
||||
|
||||
let image = UIImage(asset: .exoticBanana)
|
||||
|
||||
Asset.roundTomato.image
|
||||
@@ -1,36 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Timeline
|
||||
version = "3.0">
|
||||
<TimelineItems>
|
||||
<LoggerValueHistoryTimelineItem
|
||||
documentLocation = "#CharacterRangeLen=0&CharacterRangeLoc=921&EndingColumnNumber=10&EndingLineNumber=35&StartingColumnNumber=5&StartingLineNumber=35&Timestamp=501444082.679985"
|
||||
selectedRepresentationIndex = "0"
|
||||
shouldTrackSuperviewWidth = "NO">
|
||||
</LoggerValueHistoryTimelineItem>
|
||||
<LoggerValueHistoryTimelineItem
|
||||
documentLocation = "#CharacterRangeLen=0&CharacterRangeLoc=921&EndingColumnNumber=27&EndingLineNumber=37&StartingColumnNumber=1&StartingLineNumber=37&Timestamp=501444082.680154"
|
||||
selectedRepresentationIndex = "0"
|
||||
shouldTrackSuperviewWidth = "NO">
|
||||
</LoggerValueHistoryTimelineItem>
|
||||
<LoggerValueHistoryTimelineItem
|
||||
documentLocation = "#CharacterRangeLen=0&CharacterRangeLoc=921&EndingColumnNumber=10&EndingLineNumber=25&StartingColumnNumber=5&StartingLineNumber=14&Timestamp=501444079.82523"
|
||||
selectedRepresentationIndex = "0"
|
||||
shouldTrackSuperviewWidth = "NO">
|
||||
</LoggerValueHistoryTimelineItem>
|
||||
<LoggerValueHistoryTimelineItem
|
||||
documentLocation = "#CharacterRangeLen=0&CharacterRangeLoc=921&EndingColumnNumber=27&EndingLineNumber=25&StartingColumnNumber=1&StartingLineNumber=14&Timestamp=501444079.825443"
|
||||
selectedRepresentationIndex = "0"
|
||||
shouldTrackSuperviewWidth = "NO">
|
||||
</LoggerValueHistoryTimelineItem>
|
||||
<LoggerValueHistoryTimelineItem
|
||||
documentLocation = "#CharacterRangeLen=23&CharacterRangeLoc=994&EndingColumnNumber=19&EndingLineNumber=39&StartingColumnNumber=1&StartingLineNumber=39&Timestamp=501444082.680539"
|
||||
selectedRepresentationIndex = "0"
|
||||
shouldTrackSuperviewWidth = "NO">
|
||||
</LoggerValueHistoryTimelineItem>
|
||||
<LoggerValueHistoryTimelineItem
|
||||
documentLocation = "#CharacterRangeLen=5&CharacterRangeLoc=955&EndingColumnNumber=10&EndingLineNumber=37&StartingColumnNumber=5&StartingLineNumber=37&Timestamp=501444082.680684"
|
||||
selectedRepresentationIndex = "0"
|
||||
shouldTrackSuperviewWidth = "NO">
|
||||
</LoggerValueHistoryTimelineItem>
|
||||
</TimelineItems>
|
||||
</Timeline>
|
||||
@@ -1,107 +1,92 @@
|
||||
//: #### Other pages
|
||||
//:
|
||||
//: * [Demo for `swiftgen strings`](Strings-Demo)
|
||||
//: * [Demo for `swiftgen images`](Images-Demo)
|
||||
//: * Demo for `swiftgen storyboards`
|
||||
//: * [Demo for `swiftgen colors`](Colors-Demo)
|
||||
//: * [Demo for `swiftgen fonts`](Fonts-Demo)
|
||||
//: * Demo for `swiftgen storyboards`
|
||||
//: * [Demo for `swiftgen strings`](Strings-Demo)
|
||||
//: * [Demo for `swiftgen xcassets`](XCAssets-Demo)
|
||||
|
||||
class CreateAccViewController: UIViewController {}
|
||||
|
||||
//: #### Example of code generated by swiftgen-storyboard
|
||||
//: #### Example of code generated by swiftgen-storyboards
|
||||
|
||||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
|
||||
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
protocol StoryboardSceneType {
|
||||
protocol StoryboardType {
|
||||
static var storyboardName: String { get }
|
||||
}
|
||||
|
||||
extension StoryboardSceneType {
|
||||
static func storyboard() -> UIStoryboard {
|
||||
return UIStoryboard(name: self.storyboardName, bundle: nil)
|
||||
}
|
||||
|
||||
static func initialViewController() -> UIViewController {
|
||||
guard let vc = storyboard().instantiateInitialViewController() else {
|
||||
fatalError("Failed to instantiate initialViewController for \(self.storyboardName)")
|
||||
}
|
||||
return vc
|
||||
}
|
||||
extension StoryboardType {
|
||||
static var storyboard: UIStoryboard {
|
||||
return UIStoryboard(name: self.storyboardName, bundle: Bundle(for: BundleToken.self))
|
||||
}
|
||||
}
|
||||
|
||||
extension StoryboardSceneType where Self: RawRepresentable, Self.RawValue == String {
|
||||
func viewController() -> UIViewController {
|
||||
return Self.storyboard().instantiateViewController(withIdentifier: self.rawValue)
|
||||
}
|
||||
static func viewController(identifier: Self) -> UIViewController {
|
||||
return identifier.viewController()
|
||||
}
|
||||
struct SceneType<T: Any> {
|
||||
let storyboard: StoryboardType.Type
|
||||
let identifier: String
|
||||
|
||||
var controller: T {
|
||||
guard let controller = storyboard.storyboard.instantiateViewController(withIdentifier: identifier) as? T else {
|
||||
fatalError("Controller '\(identifier)' is not of the expected class \(T.self).")
|
||||
}
|
||||
return controller
|
||||
}
|
||||
}
|
||||
|
||||
protocol StoryboardSegueType: RawRepresentable { }
|
||||
struct InitialSceneType<T: Any> {
|
||||
let storyboard: StoryboardType.Type
|
||||
|
||||
var controller: T {
|
||||
guard let controller = storyboard.storyboard.instantiateInitialViewController() as? T else {
|
||||
fatalError("Controller is not of the expected class \(T.self).")
|
||||
}
|
||||
return controller
|
||||
}
|
||||
}
|
||||
|
||||
protocol SegueType: RawRepresentable { }
|
||||
|
||||
extension UIViewController {
|
||||
func perform<S: StoryboardSegueType>(segue: S, sender: Any? = nil) where S.RawValue == String {
|
||||
performSegue(withIdentifier: segue.rawValue, sender: sender)
|
||||
}
|
||||
func perform<S: SegueType>(segue: S, sender: Any? = nil) where S.RawValue == String {
|
||||
performSegue(withIdentifier: segue.rawValue, sender: sender)
|
||||
}
|
||||
}
|
||||
|
||||
struct StoryboardScene {
|
||||
enum Wizard: String, StoryboardSceneType {
|
||||
enum Wizard: StoryboardType {
|
||||
static let storyboardName = "Wizard"
|
||||
|
||||
static func initialViewController() -> CreateAccViewController {
|
||||
guard let vc = storyboard().instantiateInitialViewController() as? CreateAccViewController else {
|
||||
fatalError("Failed to instantiate initialViewController for \(self.storyboardName)")
|
||||
}
|
||||
return vc
|
||||
}
|
||||
static let initialScene = InitialSceneType<CreateAccViewController>(storyboard: Wizard.self)
|
||||
|
||||
case acceptCGUScene = "Accept-CGU"
|
||||
static func instantiateAcceptCGU() -> UIViewController {
|
||||
return StoryboardScene.Wizard.acceptCGUScene.viewController()
|
||||
}
|
||||
static let acceptCGU = SceneType<UIViewController>(storyboard: Wizard.self, identifier: "Accept-CGU")
|
||||
|
||||
case createAccountScene = "CreateAccount"
|
||||
static func instantiateCreateAccount() -> CreateAccViewController {
|
||||
guard let vc = StoryboardScene.Wizard.createAccountScene.viewController() as? CreateAccViewController
|
||||
else {
|
||||
fatalError("ViewController 'CreateAccount' is not of the expected class CreateAccViewController.")
|
||||
}
|
||||
return vc
|
||||
}
|
||||
|
||||
case preferencesScene = "Preferences"
|
||||
static func instantiatePreferences() -> UITableViewController {
|
||||
guard let vc = StoryboardScene.Wizard.preferencesScene.viewController() as? UITableViewController
|
||||
else {
|
||||
fatalError("ViewController 'Preferences' is not of the expected class UITableViewController.")
|
||||
}
|
||||
return vc
|
||||
}
|
||||
|
||||
case validatePasswordScene = "Validate_Password"
|
||||
static func instantiateValidatePassword() -> UIViewController {
|
||||
return StoryboardScene.Wizard.validatePasswordScene.viewController()
|
||||
}
|
||||
static let createAccount = SceneType<CreateAccViewController>(storyboard: Wizard.self, identifier: "CreateAccount")
|
||||
|
||||
static let preferences = SceneType<UITableViewController>(storyboard: Wizard.self, identifier: "Preferences")
|
||||
|
||||
static let validatePassword = SceneType<UIViewController>(storyboard: Wizard.self, identifier: "Validate_Password")
|
||||
}
|
||||
}
|
||||
|
||||
struct StoryboardSegue {
|
||||
enum Wizard: String, StoryboardSegueType {
|
||||
enum Wizard: String, SegueType {
|
||||
case showPassword = "ShowPassword"
|
||||
}
|
||||
}
|
||||
|
||||
private final class BundleToken {}
|
||||
|
||||
//: #### Usage Example
|
||||
|
||||
let createAccountVC = StoryboardScene.Wizard.createAccountScene.viewController()
|
||||
let createAccountVC = StoryboardScene.Wizard.createAccount.controller
|
||||
type(of: createAccountVC)
|
||||
createAccountVC.title
|
||||
|
||||
let validateVC = StoryboardScene.Wizard.validatePasswordScene.viewController()
|
||||
let validateVC = StoryboardScene.Wizard.validatePassword.controller
|
||||
validateVC.title
|
||||
|
||||
let segue = StoryboardSegue.Wizard.showPassword
|
||||
@@ -120,10 +105,10 @@ you can easily switch or directly compare the passed in `segue` with the corresp
|
||||
segues for a specific storyboard.
|
||||
*******************************************************************************/
|
||||
//override func prepareForSegue(_ segue: UIStoryboardSegue, sender sender: AnyObject?) {
|
||||
// switch UIStoryboard.Segue.Message(rawValue: segue.identifier)! {
|
||||
// case .Custom:
|
||||
// switch UIStoryboard.Segue.Message(rawValue: segue.identifier ?? "")! {
|
||||
// case .custom:
|
||||
// // Prepare for your custom segue transition
|
||||
// case .NonCustom:
|
||||
// case .nonCustom:
|
||||
// // Pass in information to the destination View Controller
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -1,62 +1,47 @@
|
||||
//: #### Other pages
|
||||
//:
|
||||
//: * Demo for `swiftgen strings`
|
||||
//: * [Demo for `swiftgen images`](Images-Demo)
|
||||
//: * [Demo for `swiftgen storyboards`](Storyboards-Demo)
|
||||
//: * [Demo for `swiftgen colors`](Colors-Demo)
|
||||
//: * [Demo for `swiftgen fonts`](Fonts-Demo)
|
||||
//: * [Demo for `swiftgen storyboards`](Storyboards-Demo)
|
||||
//: * Demo for `swiftgen strings`
|
||||
//: * [Demo for `swiftgen xcassets`](XCAssets-Demo)
|
||||
|
||||
//: #### Example of code generated by swiftgen-l10n
|
||||
//: #### Example of code generated by swiftgen-strings
|
||||
|
||||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
|
||||
|
||||
import Foundation
|
||||
|
||||
enum L10n {
|
||||
case alertMessage
|
||||
case alertTitle
|
||||
case applesCount(Int)
|
||||
case bananasOwner(Int, String)
|
||||
case greetings(String, Int)
|
||||
case objectOwnership(Int, String, String)
|
||||
}
|
||||
// swiftlint:enable type_body_length
|
||||
|
||||
extension L10n: CustomStringConvertible {
|
||||
var description: String { return self.string }
|
||||
|
||||
var string: String {
|
||||
switch self {
|
||||
case .alertMessage:
|
||||
return L10n.tr(key: "alert_message")
|
||||
case .alertTitle:
|
||||
return L10n.tr(key: "alert_title")
|
||||
case .applesCount(let p0):
|
||||
return L10n.tr(key: "apples.count", p0)
|
||||
case .bananasOwner(let p0, let p1):
|
||||
return L10n.tr(key: "bananas.owner", p0, p1)
|
||||
case .greetings(let p0, let p1):
|
||||
return L10n.tr(key: "greetings", p0, p1)
|
||||
case .objectOwnership(let p0, let p1, let p2):
|
||||
return L10n.tr(key: "ObjectOwnership", p0, p1, p2)
|
||||
}
|
||||
}
|
||||
|
||||
private static func tr(key: String, _ args: CVarArg...) -> String {
|
||||
let format = NSLocalizedString(key, comment: "")
|
||||
return String(format: format, locale: Locale.current, arguments: args)
|
||||
}
|
||||
static let alertMessage = L10n.tr("Localizable", "alert_message")
|
||||
static let alertTitle = L10n.tr("Localizable", "alert_title")
|
||||
static func applesCount(_ p1: Int) -> String {
|
||||
return L10n.tr("Localizable", "apples.count", p1)
|
||||
}
|
||||
static func bananasOwner(_ p1: Int, _ p2: String) -> String {
|
||||
return L10n.tr("Localizable", "bananas.owner", p1, p2)
|
||||
}
|
||||
static func `private`(_ p1: String, _ p2: Int) -> String {
|
||||
return L10n.tr("Localizable", "private", p1, p2)
|
||||
}
|
||||
static func objectOwnership(_ p1: Int, _ p2: String, _ p3: String) -> String {
|
||||
return L10n.tr("Localizable", "ObjectOwnership", p1, p2, p3)
|
||||
}
|
||||
}
|
||||
|
||||
func tr(_ key: L10n) -> String {
|
||||
return key.string
|
||||
extension L10n {
|
||||
fileprivate static func tr(_ table: String, _ key: String, _ args: CVarArg...) -> String {
|
||||
let format = NSLocalizedString(key, tableName: table, bundle: Bundle(for: BundleToken.self), comment: "")
|
||||
return String(format: format, locale: Locale.current, arguments: args)
|
||||
}
|
||||
}
|
||||
|
||||
private final class BundleToken {}
|
||||
//: #### Usage example
|
||||
|
||||
let alertTitle = tr(.alertTitle)
|
||||
let hello1 = tr(.greetings("David", 29))
|
||||
let hello2 = L10n.greetings("Olivier", 32) // Prints as a string in the console because it's CustomStringConvertible
|
||||
let alertTitle = L10n.alertTitle
|
||||
let hello1 = L10n.private("David", 29)
|
||||
let hello2 = L10n.private("Olivier", 32) // Prints as a string in the console because it's CustomStringConvertible
|
||||
|
||||
// note the inversion of parameters' order due to usage of %1$d, %2$@ and %1$@ in Localizable.strings
|
||||
tr(.objectOwnership(3, "Apples", "John"))
|
||||
L10n.objectOwnership(3, "Apples", "John")
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
//: #### Other pages
|
||||
//:
|
||||
//: * [Demo for `swiftgen colors`](Colors-Demo)
|
||||
//: * [Demo for `swiftgen fonts`](Fonts-Demo)
|
||||
//: * [Demo for `swiftgen storyboards`](Storyboards-Demo)
|
||||
//: * [Demo for `swiftgen strings`](Strings-Demo)
|
||||
//: * Demo for `swiftgen xcassets`
|
||||
|
||||
//: #### Example of code generated by swiftgen-xcassets
|
||||
|
||||
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
|
||||
|
||||
import UIKit
|
||||
typealias Image = UIImage
|
||||
|
||||
struct AssetType: ExpressibleByStringLiteral {
|
||||
fileprivate var value: String
|
||||
|
||||
var image: Image {
|
||||
let bundle = Bundle(for: BundleToken.self)
|
||||
#if os(iOS) || os(tvOS)
|
||||
let image = Image(named: value, in: bundle, compatibleWith: nil)
|
||||
#elseif os(OSX)
|
||||
let image = bundle.image(forResource: value)
|
||||
#elseif os(watchOS)
|
||||
let image = Image(named: value)
|
||||
#endif
|
||||
guard let result = image else { fatalError("Unable to load image \(value).") }
|
||||
return result
|
||||
}
|
||||
|
||||
init(stringLiteral value: String) {
|
||||
self.value = value
|
||||
}
|
||||
|
||||
init(extendedGraphemeClusterLiteral value: String) {
|
||||
self.init(stringLiteral: value)
|
||||
}
|
||||
|
||||
init(unicodeScalarLiteral value: String) {
|
||||
self.init(stringLiteral: value)
|
||||
}
|
||||
}
|
||||
|
||||
enum Asset {
|
||||
enum Exotic {
|
||||
static let banana: AssetType = "Exotic/Banana"
|
||||
static let mango: AssetType = "Exotic/Mango"
|
||||
}
|
||||
static let `private`: AssetType = "private"
|
||||
enum Round {
|
||||
static let apricot: AssetType = "Round/Apricot"
|
||||
static let orange: AssetType = "Round/Orange"
|
||||
enum Red {
|
||||
static let apple: AssetType = "Round/Apple"
|
||||
enum Double {
|
||||
static let cherry: AssetType = "Round/Double/Cherry"
|
||||
}
|
||||
static let tomato: AssetType = "Round/Tomato"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Image {
|
||||
convenience init!(asset: AssetType) {
|
||||
#if os(iOS) || os(tvOS)
|
||||
let bundle = Bundle(for: BundleToken.self)
|
||||
self.init(named: asset.value, in: bundle, compatibleWith: nil)
|
||||
#elseif os(OSX) || os(watchOS)
|
||||
self.init(named: asset.value)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private final class BundleToken {}
|
||||
|
||||
//: #### Usage Example
|
||||
|
||||
let image = UIImage(asset: Asset.Exotic.banana)
|
||||
|
||||
Asset.Round.Red.tomato.image
|
||||
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,8 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="11201" systemVersion="15G1004" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="NO" initialViewController="txY-Mc-CKa">
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13156.6" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="txY-Mc-CKa">
|
||||
<device id="retina4_7" orientation="portrait">
|
||||
<adaptation id="fullscreen"/>
|
||||
</device>
|
||||
<dependencies>
|
||||
<development version="7000" identifier="xcode"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="11161"/>
|
||||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13137.5"/>
|
||||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
|
||||
</dependencies>
|
||||
<scenes>
|
||||
<!--Create-->
|
||||
@@ -14,18 +17,18 @@
|
||||
<viewControllerLayoutGuide type="bottom" id="vfS-Bb-QLU"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="wQH-MG-v6Y">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<subviews>
|
||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="k6D-nB-wS1">
|
||||
<rect key="frame" x="548" y="28" width="32" height="30"/>
|
||||
<rect key="frame" x="323" y="28" width="32" height="30"/>
|
||||
<state key="normal" title="Next"/>
|
||||
<connections>
|
||||
<segue destination="30h-14-fok" kind="show" identifier="ShowPassword" id="y7o-M4-oge"/>
|
||||
</connections>
|
||||
</button>
|
||||
</subviews>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<constraints>
|
||||
<constraint firstItem="k6D-nB-wS1" firstAttribute="top" secondItem="vW2-yr-H1F" secondAttribute="bottom" constant="8" symbolic="YES" id="G1k-Td-dUp"/>
|
||||
<constraint firstAttribute="trailing" secondItem="k6D-nB-wS1" secondAttribute="trailing" constant="20" symbolic="YES" id="vYq-og-l8D"/>
|
||||
@@ -45,9 +48,9 @@
|
||||
<viewControllerLayoutGuide type="bottom" id="jBq-Js-dZL"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="N1u-m6-6Oc">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="8As-JG-vCu" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
@@ -63,9 +66,9 @@
|
||||
<viewControllerLayoutGuide type="bottom" id="QTc-Go-gBx"/>
|
||||
</layoutGuides>
|
||||
<view key="view" contentMode="scaleToFill" id="rJE-c0-6Bp">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
</view>
|
||||
</viewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="ZIC-B7-2WB" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
@@ -77,15 +80,15 @@
|
||||
<objects>
|
||||
<tableViewController storyboardIdentifier="Preferences" id="rJ7-m2-Mn7" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="28" sectionFooterHeight="28" id="wtR-sc-VB5">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="calibratedRGB"/>
|
||||
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
|
||||
<prototypes>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="PrefCell" id="H4k-gA-zIi">
|
||||
<rect key="frame" x="0.0" y="28" width="600" height="44"/>
|
||||
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="H4k-gA-zIi" id="egQ-bG-uas">
|
||||
<rect key="frame" x="0.0" y="0.0" width="600" height="43"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
@@ -1,10 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<playground version='6.0' target-platform='ios' display-mode='rendered'>
|
||||
<pages>
|
||||
<page name='Strings-Demo'/>
|
||||
<page name='Images-Demo'/>
|
||||
<page name='Storyboards-Demo'/>
|
||||
<page name='Colors-Demo'/>
|
||||
<page name='Fonts-Demo'/>
|
||||
<page name='Storyboards-Demo'/>
|
||||
<page name='Strings-Demo'/>
|
||||
<page name='XCAssets-Demo'/>
|
||||
</pages>
|
||||
</playground>
|
||||
Reference in New Issue
Block a user