Skip to content
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

Merged
merged 3 commits into from
Jan 12, 2018
Merged

Improved README examples #212

merged 3 commits into from
Jan 12, 2018

Conversation

ilyapuchka
Copy link
Contributor

@ilyapuchka ilyapuchka commented Jan 9, 2018

This change is Reviewable

Verified

This commit was signed with the committer’s verified signature.
Julesssss Jules
@welcome
Copy link

welcome bot commented Jan 9, 2018

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 }
Copy link
Contributor Author

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.

Copy link
Contributor

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")
Copy link
Contributor Author

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.

Copy link
Contributor

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".

Copy link
Contributor Author

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

Copy link
Contributor Author

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

Copy link
Contributor

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)
Copy link
Contributor Author

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.

Copy link
Contributor

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")
Copy link
Contributor Author

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")
Copy link
Contributor

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")
Copy link
Contributor

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

Copy link
Contributor

@pepicrft pepicrft left a 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.

Verified

This commit was signed with the committer’s verified signature.
Julesssss Jules

Verified

This commit was signed with the committer’s verified signature.
Julesssss Jules
@pepicrft pepicrft merged commit dd80e94 into tuist:master Jan 12, 2018
@welcome
Copy link

welcome bot commented Jan 12, 2018

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.

@ilyapuchka ilyapuchka deleted the patch-1 branch January 12, 2018 23:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants