Giter Site home page Giter Site logo

fulldecent / swift5-module-template Goto Github PK

View Code? Open in Web Editor NEW
441.0 14.0 57.0 330 KB

An opinionated starting point for awesome, reusable Swift 5 modules

License: MIT License

Ruby 21.68% Swift 78.32%
swift cocoapods ios template xcode swift-package-manager

swift5-module-template's Introduction

Swift 5 Module Template

Use this template as a starting point for any Swift 5 module that you want other people to include in their projects.

STATUS: This template is ready and works in production code, compatible with Xcode 15.2 (15C500b)

Swift 5 Module directory layout

Features

Your new Swift 5 module will immediately have working, compilable code, and implement these best practices:

  • Ability to be used from Swift Package Manager
  • Clean folder structure
  • MIT license
  • Testing as a standard
  • Turnkey access to GitHub Actions testing
  • Semantic versioning and a CHANGELOG
  • Included example/demo app using SwiftUI
  • Use a Xcode project to manage your code

How to use this

Clone or download a release and run the ./configure.rb program. It will ask you some questions and generate a project.

You then add all the interesting features you want your module to have.

Automating the configure script

To skip interactive prompts in the ./configure script, use these environment variables:

Template variable Environment variable
__PROJECT_NAME__ SMT_PROJECT_NAME
__ORGANIZATION NAME__ SMT_ORGANIZATION_NAME
com.AN.ORGANIZATION.IDENTIFIER SMT_COM_AN_ORGANIZATION_IDENTIFIER
__AUTHOR NAME__ SMT_AUTHOR_NAME
__TODAYS_DATE__ SMT_TODAYS_DATE
__TODAYS_DATE__ (date format) SMT_DATE_FORMAT_STRING Note: this will ask you for today’s date but it will use this format in the template.
__TODAYS_YEAR__ SMT_TODAYS_YEAR
__GITHUB_USERNAME__ SMT_GITHUB_USERNAME

For example, you may use: export SMT_ORGANIZATION_NAME='Awesome Org' before running ./configure.

How it works

graph LR
    subgraph Contributors to this project
    X[Use Xcode] --> R[Update Recipe.md]
    R --> T[Update template]
    end
    T --> C
    subgraph End users of this project
    C[Run ./configure.rb] --> M[Use your own module]
    end

Contributing

See the file Recipe.md for the complete steps (e.g. Open Xcode, make new project, click here, type that, …) of how we made the template.

swift5-module-template's People

Contributors

claui avatar cybrox avatar fulldecent avatar lanza avatar wtrocki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swift5-module-template's Issues

Improvements for pod dependencies [DISCUSSION, HELP REQUESTED]

This template is great, it should be the default of pod lib create as soon as possible. The current template provided by CocoaPods is very confusing.

I've changed the project generated by the swift3-module-template a bit so that it is easier to create a pod that has dependencies on other pods (see issue #8). The podfile in the root of my project looks like this:

platform :ios, '9.0'
inhibit_all_warnings!
use_frameworks!

workspace 'Abc'

target 'iOS Example' do
  project 'iOS Example'

  pod 'Abc', path: '.'
end

target 'Abc' do
  project 'Abc'

  pod 'Dependency1'
  pod 'Dependency2'

  target 'AbcTests'
end

It will create one workspace that contains three projects:

  • Pods
  • iOS Example
  • Abc

The pod spec looks like this:

Pod::Spec.new do |s|
  s.name = 'Abc'
  s.version = '0.1.0'
  s.license = { :type => 'MIT', :file => 'LICENSE' }
  s.summary = 'The greatest pod ever made'
  s.description = <<-DESC
      Let me tell you about the greatest pod ever made.
    DESC
  s.homepage = 'https://about.abc'
  s.authors = { 'Abc' => '[email protected]' }
  s.source = { :git => 'https://github.com/abc/abc.git', :tag => s.version }

  s.ios.deployment_target = '8.0'
  s.source_files = 'Abc/Source/**/*.swift'

  s.dependency 'Dependency1', '~> 1.2.0'
  s.dependency 'Dependency2', '~> 2.3.0'
end

When you add or remove files from your pod, just run pod update and the updated pod will be used.

My folder looks like this:

.git
.gitignore
.swift-version
.swiftlint.yml
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
LICENSE
Package.swift
Podfile
Podfile.lock
Pods
README.md
Abc.podspec
Abc.xcodeproj
Abc.xcworkspace
Abc
  - Source
  - Resources
AbcTests
  - Resources
AbcTestsHost
iOS Example
  - Source
  - Resources
iOS Example.xcodeproj

What do you guys think?

Support for Non-ASCII characters

The ./configure script works great, but I had to change the author name from the usual "Nicolás Miari" to "Nicolas Miari" (no diactritics) to get it to work, otherwise it would fail with:

Traceback (most recent call last):
	8: from ./configure:107:in `<main>'
	7: from ./configure:13:in `replace_variables_in_files'
	6: from ./configure:13:in `glob'
	5: from ./configure:17:in `block in replace_variables_in_files'
	4: from ./configure:17:in `open'
	3: from ./configure:19:in `block (2 levels) in replace_variables_in_files'
	2: from ./configure:19:in `each'
	1: from ./configure:20:in `block (3 levels) in replace_variables_in_files'
./configure:20:in `gsub!': incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError)

I guess I can go back to the generate files and fix it, but it would be nice to have.

Update Package.swift to use Swift 5+

Upgrade Package.swift so it can take advantage of the latest features.

  • Use swift-tools-version:5+ instead of swift-tools-version:4.2
  • Add "platform" parameter to the package declaration
  • Add "swiftLanguageVersions" parameter to the package declaration

Documentation references:
https://developer.apple.com/documentation/swift_packages/package
https://developer.apple.com/documentation/swift_packages/platform
https://developer.apple.com/documentation/swift_packages/package/3197887-swiftlanguageversions
https://developer.apple.com/documentation/swift_packages/swiftversion

Update for Swift 4

Work plan

  • Rerun the RECIPE using Xcode 9 Seed GM and update the recipe as needed (one commit)
  • Double check best practices upstream and elsewhere to see if we should update recipe further

Xcode 8.2.1 released, update recipe

Xcode 8.2.1 is released, update the recipe.

Basically just rerun everything and change the recipe which include the Xcode version number.

I don't think anything else whatsoever has changed.

Update recipe images

The images in the recipe folder show an example of using Xcode.

The pictures illustrate an old version of Xcode.

Update the pictures to show the same thing but using the current version of Xcode (with default themes, font sizes, etc.)

Create a travis test

Create a travis test for this test (it should test the configurator)

This is separate from the test inside the template.

Upgrade to support Swift 5

We can make a branch for this during the Xcode beta. But don't merge to master until Xcode gold master with Swift 5 support.

THEN THE UPGRADE GAMES BEGIN ON ALL YOUR PROJECTS!

Unable to Drag and drop 'xxProjectxNamexx' in to iOS Example.

At Step: VI. Make your iOS Example application depend on your module

I am unable to drag and drop 'xxProjectxNamexx' into Opened 'iOS Example' as a separate package. When I do so it appears with int the iOS Example Project and not as a separate package

Screenshot 2021-02-26 at 9 16 46 AM

I am trying to create a UIKit Version of the template.

File radar for Info.plist bug

Xcode does not update the Info.plist file when you rename a folder. See [Recipe.md] for the workaround.

Report this bug to Apple as a radar and update [Recipe.md] to reference that radar.

Pod dependencies

How would you go about creating a pod with dependencies? Currently there is no use of CocoaPods in either the module project or the example app project.

path to the *.framework in the related example app

path to the Example.framework

I had an issue with the path to the Example.framework.

In the iOS Example generated project path to the Example.framework was set to "Relative to Group".
At the same time in the Xcode Preferences (tab: Locations) I had Derived Data location set to Default (/Users/aniawidera/Library/Developer/Xcode/DerivedData).
When I built the Example.framework it was not within Example workspace directory.

issue with launching an iOS Example app on the device

I had also an issue with launching an iOS Example app on the device.
The error was: Library not found.
I noticed that Example.framework was added only as Linked Frameworks and Libraries (Project iOS Example --> Target iOS Example --> tab: General).
I got it working eventually by adding the Example.framework also to the Embedded Binaries but I am not sure if it is the best solution?

Thank you for your effort! Any help will be greatly appreciated.

Add notes to readme

In the templated readme, leave a list of check off able items that they need to do:

Replace source code
Update podspec
Update readme
Make 0.1a release
etc

Move from Travis CI to GitHub Actions

I would like to promote GitHub Actions as the new, better-maintained alternative to Travis CI.

GitHub Actions appears to be the new best practice.

Work plan:

  • Remove .travis.yml in the project folder
  • Add corresponding GitHub Actions CI to the project folder
  • Update the recipe so that the correct GitHub Actions CI is now included (see the curl commands)
  • Test that it works:
    • Complete the recipe, ensure that the generated product folder matches the files already in your pull request
      • Attach screenshot of empty diff -r
    • Deploy the generated product folder as a new repository on GitHub and ensure that the GitHub Action was successfully triggered
      • Attach link to the GitHub Action CI task that was triggered

Rename to swift4-module-template

Rename this project to swift4-module template. The new Xcode just hit Gold Master so it is GO time.

Alternatives considered:

  • Make a new project -- this is stupid because nobody wants to make new swift3 projects once Xcode 9 is out. AND because this project is only about making NEW projects.

Work plan:

  • Rename the project
  • Update the REMOTES on my computer
  • Ask people linking to the old project to now link to the new one
  • s/oldurl/newurl/g in the GitHub

Old links, care of AHREFS:

  • Reach out to them to offer updated link to this project.

.travis.yml file has some issues. Also an issue with the location of info.plist for the test target.

  1. The WORKSPACE variable currently is set to WORKSPACE="__PROJECT_NAME__.xcworkspace"

  2. Similarly, IOS_FRAMEWORK_SCHEME="__PROJECT_NAME__"

  3. I had to set my DESTINATION="platform=iOS Simulator,OS=10.2,id=E40727B3-41FB-4D6E-B4CB-BFA87109EB12" for the destination to not be invalid and cause failure.

  4. The last line being CheckCocoaPodsQualityIndexes.rb ProjectName fails to find the file. I currently am trying ruby Tests/CheckCocoaPodsQualityIndexes.rb. But travis is running slow for some reason at the moment.

  5. The test target is looking for the info.plist file at ProjectNameTests/info.plist while it's actually at Tests/info.plist. This has to be changed in the test target's build settings.

Swift 3

Use Swift 3 wording wherever we can because people care about that.

Remember preferences

Remember certain template variable assignments and then default to them next time

Crash when using Swift standard libraries

I've found an interesting crash, and I'm not sure what would be an ideal solution to fix it.

So steps to reproduce:

  1. Generate a project from template
  2. Add function to YourProjectName.swift
    func crushFunc() {
    print("Let's crash!")
    }
  3. Compile the project for target "iOS Example" or "YouProjectNameTests", you don't even need to call a function, it will crash on launch

To fix this, I had to turn on build setting "Always Embed Swift Standard Libraries" -> YES for both targets (Example and Tests), otherwise it will crash on launch. But this fix will generate warnings if user wants to add Pod Dependencies to the project (Debug + Release for Example and Test targets - 4 combined warning when installing cocoapods):

[!] The iOS Example [Debug] target overrides the ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES build setting defined in ../Pods/Target Support Files/Pods-iOS Example/Pods-iOS Example.debug.xcconfig'. This can lead to problems with the CocoaPods installation - Use the $(inherited)` flag, or
- Remove the build settings from the target.

Adding ObjC file to template

Hey,

Thanks a lot for merging my pull request #35

I have a question after merging - should I add one ObjC class to the template, so it would be obvious for users how to add objc files and have interoperability with swift code? What do you think?

P.S. I think that this template can be universal for both languages. Ofc example and tests will still be in Swift, which is not a problem for me.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.