-
-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improved README examples #212
Conversation
Thanks for opening this pull request! Please check out our contributing guidelines. |
@@ -155,8 +155,8 @@ try project.write(path: "MyApp.xcodeproj") | |||
#### Adding `Home` group inside `Sources` group | |||
|
|||
```swift | |||
guard var sourcesGroup = project.pbxproj.objects.groups.first(where: {$0.value.name == "Sources"})?.value else { return } | |||
let homeGroup = PBXGroup(reference: "xxx", children: [], sourceTree: .group, path: "Home") | |||
guard var sourcesGroup = project.pbxproj.objects.groups.first(where: {$0.value.name == "Sources" || $0.value.path == "Sources"})?.value else { return } |
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.
In Xcode 9 groups are created with paths by default, unless they are added via "New Group without Folder". So name
property is not stored in project xml and then is not decoded.
But before Xcode 9 when creating folder with File-New-Group menu (instead of dragging folder into the project) only name
property will be set and path
will be nil.
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.
Thanks for the clarification. Makes sense to me! 👍
README.md
Outdated
guard var sourcesGroup = project.pbxproj.objects.groups.first(where: {$0.value.name == "Sources"})?.value else { return } | ||
let homeGroup = PBXGroup(reference: "xxx", children: [], sourceTree: .group, path: "Home") | ||
guard var sourcesGroup = project.pbxproj.objects.groups.first(where: {$0.value.name == "Sources" || $0.value.path == "Sources"})?.value else { return } | ||
let homeGroup = PBXGroup(reference: project.pbxproj.generateUUID(for: PBXGroup.self), children: [], sourceTree: .group, path: "Home") |
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.
I've spent some time searching for a way to generate references until found this method.
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.
Yeah we introduced it in the version 2.0 but we forgot to update the readme. The function is generateReference
instead of generateUUID
and it should be used like this:
project.pbxproj.generateReference(PBXGroup.self, "home")
The second argument must be a string that uniquely identifies the object. In this case we can just use "home".
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.
Yeah, looks like I was using 1.7.0 version
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.
Unfortunately it means that readme examples are completely out of date. I would suggest to keep section with examples for 1.x version and with 2.x
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.
Thank you very much @ilyapuchka
README.md
Outdated
homeGroup.children.append(homeViewController.reference) | ||
pbxproj.objects.addObject(homeViewController) |
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.
Without this file will be not properly added and build file will point to a dangling reference.
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.
Good catch!
README.md
Outdated
``` | ||
|
||
#### Add `HomeViewController.swift` file to `MyApp` target | ||
|
||
```swift | ||
let homeViewController = PBXFileReference(reference: "xxx", sourceTree: .group, path: "HomeViewController.swift") | ||
let homeViewController = PBXFileReference(reference: project.pbxproj.generateUUID(for: PBXFileReference.self), sourceTree: .group, name: "HomeViewController.swift", path: "HomeViewController.swift") |
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.
Name and path of the file may be different, i.e. when file is added with absolute path which is not in a group's folder
README.md
Outdated
@@ -165,14 +165,15 @@ project.pbxproj.objects.addObject(homeGroup) | |||
|
|||
```swift | |||
let homeGroup = PBXGroup(reference: "xxx", children: [], sourceTree: .group, path: "Home") | |||
let homeViewController = PBXFileReference(reference: "xxx", sourceTree: .group, path: "HomeViewController.swift") | |||
let homeViewController = PBXFileReference(reference: project.pbxproj.generateUUID(for: PBXFileReference.self), sourceTree: .group, name: "HomeViewController.swift", path: "HomeViewController.swift") |
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.
Same comment regarding the generateUUID
README.md
Outdated
``` | ||
|
||
#### Add `HomeViewController.swift` file to `MyApp` target | ||
|
||
```swift | ||
let homeViewController = PBXFileReference(reference: "xxx", sourceTree: .group, path: "HomeViewController.swift") | ||
let homeViewController = PBXFileReference(reference: project.pbxproj.generateUUID(for: PBXFileReference.self), sourceTree: .group, name: "HomeViewController.swift", path: "HomeViewController.swift") |
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.
Same comment regarding the reference generation
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.
Great job @ilyapuchka. Just a few comments and it should be ready to be merged.
Congrats on merging your first pull request! We here at xcode.swift are proud of you! Join our slack channel to talk to other contributors. |
This change is