Swiftgen: cannot pod install successfully

Created on 21 Mar 2017  ·  17Comments  ·  Source: SwiftGen/SwiftGen

I am in china,and I cannot pod install successfully,could everyone solve or remind me?

the error message is descriptor as below

[!] Error installing SwiftGen
[!] /usr/bin/curl -f -L -o /var/folders/zz/dc3fn0d542q8ztb5vt0jqbl40000gn/T/d20170321-13553-1cogrr9/file.zip https://github.com/SwiftGen/SwiftGen/releases/download/4.2.0/swiftgen-4.2.0.zip --create-dirs --netrc-optional

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 595 0 595 0 0 435 0 --:--:-- 0:00:01 --:--:-- 435
0 0 0 0 0 0 0 0 --:--:-- 0:01:06 --:--:-- 0curl: (7) Failed to connect to github-cloud.s3.amazonaws.com port 443: Connection refused

awaiting input question

All 17 comments

Hi,

From the error, it seems that the GitHub servers hosting the SwiftGen binary are not accessible from China. I'm not sure I'm gonna be able to do anything about that, it's more a GitHub issue or China firewall problem, and I can't really change where GitHub hosts the releases.

What I can suggest you instead is to:

  • install SwiftGen using homebrew
  • or download the swiftgen-4.2.0.zip release manually and unzip it where you want (it's ready to use after unzipping, you just have to either call it with the full path to where you unzipped the binary, or to add its path to $PATH)
  • or download/clone the project repository and run rake install in your Terminal to build it yourself.

@AliSoftware thank you for your help, I try to solve it by using the second suggestion,the result
is that I can generate swift file such as UIImage ,but it has an error as below and could‘t run my project:

dyld: Library not loaded: @rpath/SwiftGenKit.framework/Versions/A/SwiftGenKit
Referenced from: /Users/apple/Library/Developer/CoreSimulator/Devices/8D5944FC-375F-471B-84C2-D4742D5CF095/data/Containers/Bundle/Application/16313CBA-DB22-419B-BFCD-BD7F29F8C54B/GuideViewProject.app/GuideViewProject
Reason: image not found

could you help me solve it ? thanks

That probably means that you built the SwiftGen project using a Cmd-B using Xcode instead of doing rake install?

Note that the command should be rake cli:install, if you're cloning the project (and thus using the latest master). That command will also tell you where the resulting binary is, something like:

Finished installing. Binary is available in: .../SwiftGen/build/swiftgen/bin

@AliSoftware

thank you for your answer ,I use this method:

download the swiftgen-4.2.0.zip release manually and unzip it where you want (it's ready to use after unzipping, you just have to either call it with the full path to where you unzipped the binary, or to add its path to $PATH)

and write full path in script phase to make it work. according to your suggestion, this method may be can not run "rake install"? I just think the third suggestion should use "rake install".

@AliSoftware and I try to use this method;

download/clone the project repository and run rake install in your Terminal to build it yourself.

when I run "rake install", it failed and show:

The following build commands failed:
PhaseScriptExecution ⚠️\ SwiftLint build/Build/Intermediates/SwiftGen.build/Release/swiftgen.build/Script-234F7E7C1DEBD742001B3C10.sh
(1 failure)
rake aborted!
Command failed with status (65): [DEVELOPER_DIR="/Applications/Xcode.app/Con...]
/Users/apple/Downloads/SwiftGen-master-2/rakelib/utils.rake:51:in xcpretty' /Users/apple/Downloads/SwiftGen-master-2/rakelib/utils.rake:17:inrun'
/Users/apple/Downloads/SwiftGen-master-2/Rakefile:39:in `block (2 levels) in Tasks: TOP => cli:install => cli:build
(See full trace by running task with --trace)

@AliSoftware actually I just want to integrate SwiftGen into my project. the cocoapods isn't work. so I want to put SwiftGen in my project ,so my team member can use it directly rather than use homebrew or others. could you give me some suggestion? thank you very much.

Ah yeah sorry I read too fast and thought you used the 3rd method.
Indeed for the second method you don't need rake cli:install

That's very strange that you have this error when running the binary downloaded with the zip file because that's the same zip file used when installing via CocoaPods and I know this one works…

Will try to investigate later in the week

@AliSoftware Thank you for your patience to help me . I wait for your reply

@zhoufusong I don't understand, I just downloaded the ZIP file (https://github.com/SwiftGen/SwiftGen/releases/download/4.2.0/swiftgen-4.2.0.zip) here on my Mac then executed it and I don't have the error you have. Are we both talking about the same zip?

After downloading the ZIP file in my ~/Downloads folder, I unzipped it, then in the terminal I typed ~/Downloads/swiftgen-4.2.0/bin/swiftgen -h and ~/Downloads/swiftgen-4.2.0/bin/swiftgen templates list for example and both work as expected… So I don't understand why you have a different behavior 🤔

@AliSoftware you are right. and I can do it the same as your description.but my purpose is put it in my Xcode project and every member could write script to use it. but when I put it in my Xcode project and I run my project,it has the error:

dyld: Library not loaded: @rpath/SwiftGenKit.framework/Versions/A/SwiftGenKit
Referenced from: /Users/apple/Library/Developer/CoreSimulator/Devices/8D5944FC-375F-471B-84C2-D4742D5CF095/data/Containers/Bundle/Application/521B57C3-F0E7-4095-B198-B5E17C336168/GuideViewProject.app/GuideViewProject
Reason: image not found

and my script in build phases is:

GuideViewProject/swiftgen/bin/swiftgen images -t swift3 $TARGET_NAME/Assets.xcassets --output $TARGET_NAME/UIImage+Assets.swift
if [[ $? != 0 ]] ; then
cat << EOM
error: Failed to run the swiftgen command. If you do not have swiftgen installed, you can install it via homebrew:

$ brew update
$ brew install swiftgen

For more information, visit 'https://github.com/AliSoftware/SwiftGen'.
EOM
exit 1
fi

🤔 what I don't understand from your error is it says it can't load the SwiftGenKit library… referenced from your app bundle?!

Referenced from: …/GuideViewProject.app/GuideViewProject

So I actually don't think it's the invocation of your build phase that causes the problem

Maybe when you tried to make it work earlier you mistakenly added SwiftGenKit.framework to your project's linked libraries at some point? And thus it tries to… link SwiftGenKit to your app?! (Which is not how swiftgen works, it's not a library to be linked to your project, just a standalone tool to run)

but my purpose is put it in my Xcode project and every member could write script to use it. but when I put it in my Xcode project and I run my project,it has the error

That's not how SwiftGen is supposed to be integrated at all. SwiftGen is not to be added as files to your Xcode project like you'd add external frameworks to your project. It's a tool to be run in the Terminal or as a Build Phase. You are not supposed to link your Xcode project with its libraries!

Could it be that you changed the folder structure as found in the zip file? Or that you deleted the lib directory?

I am in China too. I fixed this by using second suggestion. I put unzip dir to my project dir, and configure script in build phases as:

"$PROJECT_DIR/swiftgen/bin/swiftgen" strings "$PROJECT_DIR/bong/Resources/Localization/zh-Hans.lproj/Localizable.strings" --output "$PROJECT_DIR/bong/Resources/Localizations.swift" --templatePath "$PROJECT_DIR/bong/Resources/Templates/strings-default.stencil"

"$PROJECT_DIR/swiftgen/bin/swiftgen" images "$PROJECT_DIR/bong/Resources/Images.xcassets" --output "$PROJECT_DIR/bong/Resources/Images.swift" --templatePath "$PROJECT_DIR/bong/Resources/Templates/images-default.stencil"

Thanks @iostalks for the feedback!
@zhoufusong any news on your end?

ping @zhoufusong : could we close this?

As a reminder, I think the issue is that you misunderstood how to integrate SwiftGen in your project:

but my purpose is put it in my Xcode project and every member could write script to use it. but when I put it in my Xcode project and I run my project,it has the error

That's not how SwiftGen is supposed to be integrated at all. SwiftGen is not to be added as files to your Xcode project like you'd add external frameworks to your project. It's a tool to be run in the Terminal or as a Build Phase. You are not supposed to link your Xcode project with its libraries! You just install SwiftGen on your machine, or unzip the zip file next to your project's _folder_ so that it's committed to GIT alongside your project… but you're not supposed to add its files to the Xcode project itself at all. It's not a library or framework you link your project with, it's a tool to be run by your Build Phases (similar to other tools like Sourcery, SwiftLint or SwiftFormat for example)

We've recently improved the installation instructions in the README, including now having a section to explain how to install SwiftGen using the ZIP file from the GitHub releases, so I hope this new section will help you understand that process better.

Closing this due to inactivity

Was this page helpful?
0 / 5 - 0 ratings

Related issues

embassem picture embassem  ·  3Comments

valerianb picture valerianb  ·  7Comments

marcelofabri picture marcelofabri  ·  6Comments

danielsaidi picture danielsaidi  ·  7Comments

stuffmc picture stuffmc  ·  3Comments