-
Notifications
You must be signed in to change notification settings - Fork 286
Conversation
@fredpi Thank you very much for this PR. I just wanted to let you know that I am now looking into this PR which includes testing it locally and trying to figure out if there is anything else that needs to be done. The only concern I have at the moment - without having looked at it - is that there are currently 13+ iOS developers working on this project + several developers from the open source community. If this changes the workflow significantly we may have to document that and make everyone aware about the changes. That being said I am now starting the review and I am pretty curious what I will find once I open the box. :) |
@inf2381 I believe our CI is not being executed for PRs coming from other repos. It this done intentionally? |
@fredpi I now had a look at the PR. I think that we have to also adjust the circleci config.yml file so that swiftgen is installed before actually building the app. We also have to consider our internal CI landscape. I will ask around if this might cause any issues and report back to you. I have also assigned @inf2381 (aka Mr. CI) to make him aware about what is happening. |
@ChristianKienle Would love to see SwiftGen in this project as well, prevents many bugs and errors! Also I wonder why we are not using GitHub Actions for this regarding CI? @inf2381 |
8d487af
to
2fc20dd
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fredpi Why not build-script step that automatically runs SwiftGen on each build?
Ahh, you're totally right of course, I overlooked it. Looks good, thank you! 👍 |
@ChristianKienle Thanks for the suggestion, but I think that would be rather counterproductive: Every developer that adds news assets should build afterwards (automatically causing SwiftGen to update the Of course, this setup will yield a warning within the CI (that SwiftGen isn't installed), but I guess that won't be a problem with the current CI configuration that doesn't fail immediately on warnings. |
Gosh you are right. The CI does not need it. :D I really need more sleep lol. Okay so then the CI is not a concern. Then this PR is fine with me. So the plan is, if this gets merged to then actually start using |
We are using CircleCI because it was the first CI platform to have the Xcode beta version we needed back then... |
@ChristianKienle Thank you for the fast review and responses. The Beta explanation makes sense! 👍 Looking forward for this getting merged. I think as a subsequent PR @fredpi might want to migrate at least the more trivial uses of dynamic strings to SwiftGen. @ChristianKienle What is your opinion on also using BartyCrouch for fixing multiple potential issues with translations? After this is merged, @fredpi or I could continue with that as he has pointed out in his first post in this thread. |
95bf781
to
adb85d5
Compare
@ChristianKienle Thanks for the review! 👍 I've made some changes to this PR:
As from my side, this can be merged now. The next step would be to migrate the existing use to SwiftGen (+ enable the new SwiftLint rules). This can be done step by step, starting with storyboards, then colors and finally images. The latter may be a bit more time-intensive because the namespace must be looked up for each image. Also, SwiftGen & BartyCrouch work quite well together for localizations, so those could also be implemented as @Jeehut suggested. |
@ChristianKienle BartyCrouch works like magic without the need that anyone learns something new, it actually just fixes gaps in Xcode and makes things work as expected. For example, when you write But having that said, it should for sure be a separate PR because SwiftGen is already useful without BartyCrouch, so we can move the BartyCrouch discussion to it's own PR. @fredpi Instead of SwifLint custom rules (which I don't like because they neither support testing/validation nor autocorrection), could we use AnyLint which I have already basically configured in #104? I have also already prepared AnyLint checks for using SwiftGen in other projects, here they are: let swiftFiles: Regex = #"^(App|Tests|UITests)/Sources/.*\.swift$"#
let generatedSwiftFiles: Regex = #".*/Generated/.*\.swift|.*/SwiftGen/.*\.swift"#
// MARK: DynamicColorReference
try Lint.checkFileContents(
checkInfo: "DynamicColorReference: Don't use dynamic color references – use SwiftGen & Color instead.",
regex: #"UIColor\(\s*named:\s*\""#,
matchingExamples: [#"UIColor(named: "primary")"#],
nonMatchingExamples: ["Colors.primary.color"],
includeFilters: [swiftFiles],
excludeFilters: [generatedSwiftFiles]
)
// MARK: DynamicStoryboardReference
try Lint.checkFileContents(
checkInfo: "DynamicStoryboardReference: Don't use dynamic storyboard references – use SwiftGen & StoryboardScene instead.",
regex: #"UIStoryboard\(\s*name:\s*\""#,
matchingExamples: [#"UIStoryboard(name: "LoginViewController")"#],
nonMatchingExamples: ["StoryboardScene.Login.loginViewController.instantiate()"],
includeFilters: [swiftFiles],
excludeFilters: [generatedSwiftFiles]
)
// MARK: DynamicStringReference
try Lint.checkFileContents(
checkInfo: "DynamicStringReference@warning: Don't use dynamic localization string references via code strings – use SwiftGen & L10n instead.",
regex: #"NSLocalizedString\s*\("#,
matchingExamples: [#"NSLocalizedString(@"Test", comment: "");"#, #"NSLocalizedString("Test", comment: nil)"#],
includeFilters: [swiftFiles],
excludeFilters: [generatedSwiftFiles]
) |
Hi guys, enum BluetoothState {
case on
case off
private var imageName: String {
switch self {
case on: return "Illu_Bluetooth_Off"
case off: return "Illu_Bluetooth_On"
}
}
var image: UIImage { UIImage(named: imageName) }
} I think this is more logic. |
@haosap SwiftGen is a generalized approach to fixing any resource loading problem which is by default done by manually referincing dynamic strings in iOS development. Unfortunately, the default method is very prone to errors like typos, referencing no longer available or renamed files. Because Xcode neither has a built-in check for the existence of the files and also doesn't provide autocompletion, errors are quite common, especially if the project is open source and many different people work on it. In the end, yes, Android Studio for example has a similar concept built-in, and yes it's possible to set up a different solution like a custom one (that you suggested) or R.swift. But as SwiftGen is by far the most used solution here and many iOS developers know it, it's IMHO the best solution to tackle the problem of error-prone autocompletion-free nature of loading resources in iOS development without creating unnecessary obstacles for new contributors. |
adb85d5
to
eecd2f4
Compare
@ChristianKienle I have just rebased to fix conflicts. The tests pass so I think there's nothing holding back this PR from getting merged. Just one last addition to this PR: I have added SwiftGen for strings. I didn't do it until now because I thought it would be better if it would be in a PR together with BartyCrouch, but for me it seems like the general expectation is that this PR already adds SwiftGen for strings. Unfortunately, the keys for the strings use an underscore pattern ( @Jeehut Yes, using AnyLint would be better, but maybe this PR should still implement SwiftLint rules and AnyLint migration should be discussed in #104. @haosap Actually a pattern like |
From @haosap:
@haosap Firstly, I don't know why you edited my comment instead of clicking "Quote reply". I assume you are searching for a thread-like answer method like in other tools like Slack, which will be coming to GitHub soon (I think this summer): https://help.github.com/en/github/building-a-strong-community/about-team-discussions Apart from that, let me answer your question. Firstly, the way you ask your question seems to already include a logical issue: Your question implies that only one bug type ("Typo") can not lead to "many bugs", which is untrue. There can be thousand typos in the repo which would be thousand bugs but all of them consisting of one bug type. Having that said, I will also quote myself because I already mentioned 3 bug types that are prevented by using SwiftGen:
So not only typos are fixed, but also if one of the resources is removed (e.g. an image, a string or a color) then the project won't build anymore which makes clear that there's an issue. Without SwiftGen, it will continue to build, leaving to a user-error after shipping. Or if one of the resources was renamed (this usually happens in the last steps before a release where things are refactored to make things more consistent after a fast-progress period) then the same thing happens, SwiftGen again helps. In practice, we have prevented around 1-2 bugs shipping per 2-week sprints to users in teams of 3 developers. Here, we are many more developers so I expect more bugs, but of course that also means someone could check that all resources are still available before making a release – or we just use SwiftGen and save that poor guy from doing these manual checks. |
b21cfdd
to
8326cbd
Compare
25601d5
to
a103db8
Compare
a103db8
to
0167f3b
Compare
@ChristianKienle I rebased to fix conflicts and to adapt to the new asset catalog structure. In an additional commit, I renamed |
571870c
to
058cf88
Compare
@ChristianKienle As my asset catalog renaming caused a bunch of conflicts, I now switched to the different approach (modifying the SwiftGen template), that only renames the asset catalogs in the Also, as rebasing got trickier every time, I squashed the previous changes into one commit. |
46b36dd
to
4cb693f
Compare
4cb693f
to
a91b974
Compare
This PR adds SwiftGen for assets and thereby lays the foundation for #30.
As there are currently multiple ways assets are used within the code, I didn't actually change the asset access mechanism yet – it's probably better if the core team does it.
To go on, I suggest a few things:
Images.folderName.folderName.imageName
and all color assets using ~Colors.folderName.folderName.imageName