{"id":20564070,"url":"https://github.com/clintjang/sample-swiftgen","last_synced_at":"2025-04-14T15:10:41.811Z","repository":{"id":99120079,"uuid":"123111945","full_name":"ClintJang/sample-swiftgen","owner":"ClintJang","description":"The samples using the \"SwiftGen\" library. (SwiftGen 라이브러리 사용방법을 셈플로 설명했습니다.)","archived":false,"fork":false,"pushed_at":"2018-04-11T14:43:09.000Z","size":2270,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-28T04:02:29.394Z","etag":null,"topics":["localization","sample","sample-code","sample-swiftgen","stencil","swift","swift-sample","swiftgen","test-cases","xcassets"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ClintJang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-27T10:18:47.000Z","updated_at":"2024-08-21T09:49:03.000Z","dependencies_parsed_at":"2023-06-04T00:15:13.108Z","dependency_job_id":null,"html_url":"https://github.com/ClintJang/sample-swiftgen","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClintJang%2Fsample-swiftgen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClintJang%2Fsample-swiftgen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClintJang%2Fsample-swiftgen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ClintJang%2Fsample-swiftgen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ClintJang","download_url":"https://codeload.github.com/ClintJang/sample-swiftgen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248904640,"owners_count":21180835,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["localization","sample","sample-code","sample-swiftgen","stencil","swift","swift-sample","swiftgen","test-cases","xcassets"],"created_at":"2024-11-16T04:23:48.048Z","updated_at":"2025-04-14T15:10:41.804Z","avatar_url":"https://github.com/ClintJang.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sample SwiftGen\n[![License](http://img.shields.io/badge/License-MIT-green.svg?style=flat)](https://github.com/clintjang/JWSBoltsSwiftSample/blob/master/LICENSE) [![Swift 4](https://img.shields.io/badge/swift-4.0-orange.svg?style=flat)](https://swift.org) \n- [SwiftGen](https://github.com/SwiftGen/SwiftGen) : How to use it!!!!\n- SwiftGen is **a tool to auto-generate Swift code for resources** of your projects, to make them type-safe to use.\n- [한국어 설명 링크](https://github.com/ClintJang/sample-swiftgen/blob/master/READMEKO.md) : Sample description in Korean\n\n# Development Information\n| check version information?!!\n\u003cpre\u003e\n$ swiftgen --version\n  SwiftGen v5.2.1 (Stencil v0.9.0, StencilSwiftKit v2.3.0, SwiftGenKit v2.1.1)\n\u003c/pre\u003e\n- [Stencil](https://stenciljs.com/) : The magical, reusable web component compiler\n- [StencilSwiftKit](https://github.com/SwiftGen/StencilSwiftKit) : StencilSwiftKit is a framework bringing additional Stencil nodes \u0026 filters dedicated to Swift code generation.\n- [SwiftGenKit](https://github.com/SwiftGen/SwiftGenKit) : This is the framework behind SwiftGen, responsible for parsing various resources and turning them into Stencil contexts.\n\t- This repository has been merged into the main SwiftGen repository.\n\n# Installation\nBefore you test, be sure to follow the [link](https://github.com/SwiftGen/SwiftGen) and follow the installation process.\n```\nex) \ninstall\n\n$ brew update\n$ brew install swiftgen\n\nconfirm\n$ swiftgen ...\n```\n\n# Samples (Base Template)\n\u003e Download the sample source and modify the \"/Resources/TestCase0?Localizable.strings\" file. Then run the build. This will change the file \"/Constants/Test.Case0?.Localized.swift\".\n\n\u003ctable style=\"width:100%\"\u003e\n  \u003ctr\u003e\n\t\u003cth\u003eScript Setting\u003cbr\u003e(Target \u003e\u003e Bulid Phases Tap \u003e\u003e + Button Click \u003e\u003e New Run Script Phase)\u003c/th\u003e \n    \u003cth\u003eBase Template Detail\u003c/th\u003e \n  \u003c/tr\u003e\n  \u003ctr\u003e\n  \t\u003ctd\u003e\u003cimg width=\"382\" height=\"196\" src=\"/Image/script_setting00.png\"\u003e\u003c/img\u003e\u003c/td\u003e\n    \u003ctd\u003e\u003cimg width=\"424\" height=\"353\" src=\"/Image/script_setting01.png\"\u003e\u003c/img\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n- You can create a **** .sh file later and run it.\n- Now let 's test the basics of 5 things!\n\t- swiftgen strings [OPTIONS] FILE1 …\n\t- swiftgen storyboards [OPTIONS] DIR1 …\n\t- swiftgen xcassets [OPTIONS] CATALOG1 …\n\t- swiftgen colors [OPTIONS] FILE1 …\n\t- swiftgen fonts [OPTIONS] DIR1 …\n\t\n## Case 01 ~ 07 : Test results\n\u003ctable style=\"width:100%\"\u003e\n  \u003ctr\u003e\n  \t\u003ctd\u003e\u003cimg width=\"251\" height=\"494\" src=\"/Image/use_case_00.png\"\u003e\u003c/img\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n- ViewController.swift\n```swift\noverride func viewDidLoad() {\n        super.viewDidLoad()\n        \n        testSamplesBaseTemplates()\n    }\n\n    func testSamplesBaseTemplates() {\n        // Case 01 : String\n        case01Label.text = L10n.testCase01TitleTop01\n        \n        // Case 02 : String\n        case02Label.text = TestCase02Strings.testCase02TitleTop01\n        \n        // Case 03 : String\n        case03Label.text = TestCase03Strings.testCase03TitleBottom01\n        \n        // Case 04 : Storyboard\n        // Pass\n        \n        // Case 05-1 : Assets\n        //        let swiftGenSample01Image = UIImage(asset: Asset.imageSwiftGenSample01)\n        let swiftGenSample01Image = Asset.imageSwiftGenSample01.image\n        case0501ImageView.image = swiftGenSample01Image\n        debugPrint(Asset.allImages)\n        \n        //        case0502Label.textColor = UIColor(asset: Asset.test01Color)\n        case0502Label.textColor = Asset.test01Color.color\n        debugPrint(Asset.allColors)\n        \n        // Case 06 : Colors\n        //        case06Label.textColor = Color(named:ColorName.articleBody)\n        case06Label.textColor = ColorName.articleBody.color\n        \n        // Case 07 : Fonts\n        //        case06Label.font = UIFont(font: FontFamily.SFCompactDisplay.ultralight, size: 30.0)\n        case07Label.font = UIFont(font: FontFamily.SFProDisplay.blackItalic, size: 30.0)\n    }\n```\n\n\u003e Let's look at the details.\n\n## Case 01 : String\nLet's build it!\n- resource file : [TestCase01Localizable.strings](https://github.com/ClintJang/sample-swiftgen/blob/master/JWSSwiftGenSample/JWSSwiftGenSample/Resources/TestCase01Localizable.strings)\n\n\u003cpre\u003e\nScript..\n\n# testing script case 01\nswiftgen strings \"${SRCROOT}/${TARGETNAME}/Resources/TestCase01Localizable.strings\" --template structured-swift4 --output \"${SRCROOT}/${TARGETNAME}/Constants/BasicTemplate/Test.Case01.Localized.swift\"\n\u003c/pre\u003e\n\n\u003e Read the [Link(SwiftGen)](https://github.com/SwiftGen/SwiftGen) \"Templates bundled with SwiftGen:\".\n\u003cpre\u003e\nA swift2 template, compatible with Swift 2\nA swift3 template, compatible with Swift 3\nA swift4 template, compatible with Swift 4\nOther variants, like flat-swift2/3/4 and structured-swift2/3/4 templates for Strings, etc.\n\u003c/pre\u003e\n### result\n- file link : .. /Constants/BasicTemplate/[Test.Case01.Localized.swift](https://github.com/ClintJang/sample-swiftgen/blob/master/JWSSwiftGenSample/JWSSwiftGenSample/Constants/BasicTemplate/Test.Case01.Localized.swift)\n\n## Case 02 : String\nDefine the naming of the enum yourself, and abbreviate the command.\n- add : --param enumName=TestCase02Strings\n- modify : --output =\u003e -o\n- modify : --template =\u003e -t\n\n\u003cpre\u003e\nScript..\n\n# testing script case 02\nswiftgen strings --param enumName=TestCase02Strings \"${SRCROOT}/${TARGETNAME}/Resources/TestCase02Localizable.strings\" -t structured-swift4 -o \"${SRCROOT}/${TARGETNAME}/Constants/BasicTemplate/Test.Case02.Localized.swift\"\n\u003c/pre\u003e\n### result\n- file link : .. /Constants/BasicTemplate/[Test.Case02.Localized.swift](https://github.com/ClintJang/sample-swiftgen/blob/master/JWSSwiftGenSample/JWSSwiftGenSample/Constants/BasicTemplate/Test.Case02.Localized.swift)\n\n## Case 03 : String\nAdd localization\n- modify : ../Resources/.. =\u003e ../Resources/Base.lproj/..\n\u003ctable style=\"width:100%\"\u003e\n  \u003ctr\u003e\n\t\u003cth\u003edifference point\u003c/th\u003e \n  \u003c/tr\u003e\n  \u003ctr\u003e\n  \t\u003ctd\u003e\u003cimg width=\"282\" height=\"137\" src=\"/Image/Localizable.png\"\u003e\u003c/img\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cpre\u003e\nScript.. \n\n# testing script case 03\nswiftgen strings --param enumName=TestCase03Strings \"${SRCROOT}/${TARGETNAME}/Resources/Base.lproj/TestCase03Localizable.strings\" -t structured-swift4 -o \"${SRCROOT}/${TARGETNAME}/Constants/BasicTemplate/Test.Case03.Localized.swift\"\n\u003c/pre\u003e\n\n### result\n- file link : .. /Constants/BasicTemplate/[Test.Case03.Localized.swift](https://github.com/ClintJang/sample-swiftgen/blob/master/JWSSwiftGenSample/JWSSwiftGenSample/Constants/BasicTemplate/Test.Case03.Localized.swift)\n\n## Case 04 : StoryBoard\n\u003e Storyboards are a little different but similar.\n\u003cpre\u003e\nScript.. \n\n# testing script case 04\nswiftgen storyboards -t swift4 \"${SRCROOT}/${TARGETNAME}/Base.lproj/Main.storyboard\" -o \"${SRCROOT}/${TARGETNAME}/Constants/BasicTemplate/Test.Case04.Storyboards.swift\"\n\u003c/pre\u003e\n\n### result\n- file link : .. /Constants/BasicTemplate/[Test.Case04.Storyboards.swift](https://github.com/ClintJang/sample-swiftgen/blob/master/JWSSwiftGenSample/JWSSwiftGenSample/Constants/BasicTemplate/Test.Case04.Storyboards.swift)\n\n## Case 05 : Xcassets\n\u003e Let's try Xcassets!\n\n\u003cpre\u003e\nScript.. \n\n# testing script case 05\nswiftgen xcassets \"${SRCROOT}/${TARGETNAME}/Assets.xcassets\" -t swift4 -o \"${SRCROOT}/${TARGETNAME}/Constants/BasicTemplate/Test.Case05.Xcassets.swift\"\n\u003c/pre\u003e\n\n### result\n- file link : .. /Constants/BasicTemplate/[Test.Case05.Xcassets.swift](https://github.com/ClintJang/sample-swiftgen/blob/master/JWSSwiftGenSample/JWSSwiftGenSample/Constants/BasicTemplate/Test.Case05.Xcassets.swift)\n\n## Case 06 : Colors\n\u003e I added color samples. However, you can add color in xcassets. It will then be added to the output of case 5.\n\u003e\u003e https://github.com/SwiftGen/SwiftGen/issues/315\n\n- add file (colors.txt)\n\u003ctable style=\"width:100%\"\u003e\n  \u003ctr\u003e\n\t\u003cth\u003eadd colors.txt\u003c/th\u003e \n  \u003c/tr\u003e\n  \u003ctr\u003e\n  \t\u003ctd\u003e\u003cimg width=\"615\" height=\"337\" src=\"/Image/case6_color.png\"\u003e\u003c/img\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cpre\u003e\nScript.. \n\n# testing script case 06\nswiftgen colors -t swift4 \"${SRCROOT}/${TARGETNAME}/Resources/colors.txt\"  -o \"${SRCROOT}/${TARGETNAME}/Constants/BasicTemplate/Test.Case06.Colors.swift\"\n\u003c/pre\u003e\n\n### result\n- file link : .. /Constants/BasicTemplate/[Test.Case06.Colors.swift](https://github.com/ClintJang/sample-swiftgen/blob/master/JWSSwiftGenSample/JWSSwiftGenSample/Constants/BasicTemplate/Test.Case06.Colors.swift)\n\n## Case 07 : Fonts\n\u003e I added some of the font files from Apple, and tried to code-generate the fonts in that path into files.\n\n- add fonts file (in \"Font\" folder)\n\u003ctable style=\"width:100%\"\u003e\n  \u003ctr\u003e\n\t\u003cth\u003eadd fonts file\u003c/th\u003e \n  \u003c/tr\u003e\n  \u003ctr\u003e\n  \t\u003ctd\u003e\u003cimg width=\"275\" height=\"329\" src=\"/Image/case7_fonts.png\"\u003e\u003c/img\u003e\u003c/td\u003e\n  \u003c/tr\u003e\n\u003c/table\u003e\n\n\u003cpre\u003e\nScript.. \n\n# testing script case 07\n# https://developer.apple.com/fonts/\nswiftgen fonts -t swift4 \"${SRCROOT}/${TARGETNAME}/Resources/Font\"  -o \"${SRCROOT}/${TARGETNAME}/Constants/BasicTemplate/Test.Case07.Fonts.swift\"\n\u003c/pre\u003e\n\n### result\n- file link : .. /Constants/BasicTemplate/[Test.Case07.Fonts.swift](https://github.com/ClintJang/sample-swiftgen/blob/master/JWSSwiftGenSample/JWSSwiftGenSample/Constants/BasicTemplate/Test.Case07.Fonts.swift)\n\n\n# Samples (User Custom, Use of Stencil)\n\u003e Let's create a file that you want to make.\n\n\n- What is Stencil? : https://stencil.fuller.li/en/latest/\n\u003cpre\u003e\nThe Stencil template language\n\nStencil is a simple and powerful template language for Swift. \nIt provides a syntax similar to Django and Mustache. \nIf you’re familiar with these, \nyou will feel right at home with Stencil.\n\u003c/pre\u003e\n\n- You only need to know how to use it, and you can use Stencil by default.\n- Take a look at the use cases below.\n\n## How do I customize it?\n- If you know the grammar, how can you customize it? That way, you can click the link below to get the template source. This can be analyzed and corrected.\n\u003e https://github.com/SwiftGen/SwiftGen/tree/master/templates\n\n## Case 01 : String, Objective-C?\n\u003e What if you want to make it an Objective-C source? Let's try it.\n\n- I tried to make it #define simply. :)\n\n\u003cpre\u003e\nScript.. \n\n# testing script case 01\nswiftgen strings \"${SRCROOT}/${TARGETNAME}/Resources/TestCase01Localizable.strings\" --templatePath ${SRCROOT}/swiftgen/StencilTemplates/Localization/objLocalization.stencil --output \"${SRCROOT}/${TARGETNAME}/Constants/CustomTemplate/Test.Custom.Case01.Localized.h\"\n\u003c/pre\u003e\n\n- objLocalization.stencil\n\u003cpre\u003e\n{% if tables.count \u003e 0 %}\n\n{# You can modify the value below with the actual value. #}\n{% macro recursiveBlock table item sp %}\n{{sp}}  {% for string in item.strings %}\n{{sp}}  {% if not param.noComments %}\n{{sp}}  /// {{string.translation}}\n{{sp}}  #define {{string.name}} \"{{string.key}}\"\n{{sp}}  {% endif %}\n{{sp}}  {% if not param.noComments %}\n{{sp}}  /// LOG : {{string}}\n{{sp}}  {% endif %}\n{{sp}}  {% endfor %}\n{% endmacro %}\n\n{# print #}\n{% call recursiveBlock tables.first.name tables.first.levels \"\" %}\n\n{% else %}\n// No string found\n{% endif %}\n\u003c/pre\u003e\n\n### result\n- file link : .. /Constants/CustomTemplate/[Test.Custom.Case01.Localized.h](https://github.com/ClintJang/sample-swiftgen/blob/master/JWSSwiftGenSample/JWSSwiftGenSample/Constants/CustomTemplate/Test.Custom.Case01.Localized.h)\n\n\u003cpre\u003e\n  /// test(case01) string 1\n  #define test_case01_sub_index01 \"test_case01_sub_index01\"\n  /// LOG : [\"translation\": \"test(case01) string 1\", \"name\": \"test_case01_sub_index01\", \"key\": \"test_case01_sub_index01\"]\n  /// test(case01) string 2\n  #define test_case01_sub_index02 \"test_case01_sub_index02\"\n  /// LOG : [\"translation\": \"test(case01) string 2\", \"name\": \"test_case01_sub_index02\", \"key\": \"test_case01_sub_index02\"]\n  /// test(case01) sample 2\n  #define test_case01_title_bottom01 \"test_case01_title_bottom01\"\n  /// LOG : [\"translation\": \"test(case01) sample 2\", \"name\": \"test_case01_title_bottom01\", \"key\": \"test_case01_title_bottom01\"]\n  /// test(case01) sample 1\n  #define test_case01_title_top01 \"test_case01_title_top01\"\n  /// LOG : [\"translation\": \"test(case01) sample 1\", \"name\": \"test_case01_title_top01\", \"key\": \"test_case01_title_top01\"]\n\u003c/pre\u003e\n\n\n## Case 02 : String\n\u003e Want to make your default template look different?\n\n.. doing it.\n\n\n# Conclusion\n\u003e Why not try it?\n\n\u003e You can also manage it by running it as a script command from the shell separately.\n\n- [iOSSampleApp] (https://github.com/igorkulman/iOSSampleApp) In this way, a single project can be packaged.\n- Thank you.\n\t- I will try to make some more samples\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclintjang%2Fsample-swiftgen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fclintjang%2Fsample-swiftgen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fclintjang%2Fsample-swiftgen/lists"}