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

Added UIView, NSView and CGRect extensions #38

Merged
merged 10 commits into from Jan 13, 2017
Merged

Conversation

Sweeper777
Copy link
Collaborator

I added some things that make dealing with positions and sizes easier. e.g. you can easily change a view's position by setting its x and y properties.

Copy link
Owner

@tbaranes tbaranes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I let you a few comments about the README, otherwise that's a cool add 👍

let rect = CGRect(x: 10, y: 20, width: 30, height: 40)
let widerRect = rect.with(width: 100)
let tallerRect = rect.with(height: 100)
let rectAtAnotherPosition = rect.with(x: 100).with(y: 200)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment // result printed once changed for each of them?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "result printed once changed"? I didn't have any print statements.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example:
let widerRect = rect.with(width: 100) // x: 10, y: 20, width: 130, height: 140

aView.width -= 10 // make the view narrower
aView.height -= 10 // make the view shorter
```

It will iterate on all the subviews of the view, and use the text / placeholder as key in `NSLocalizedString`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That comment must be below Automates your localizables and above the new section.

@@ -1090,6 +1108,14 @@ mySwitch.toggle()
aView.convertLocalizables()
```

**Change the frame of the view easily**
```swift
aView.x += 100 // move to right
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a var aView: UIView to make the example more concrete?

@@ -1221,6 +1247,14 @@ view.addGestureRecognizer(blockTapGesture)
aView.convertLocalizables()
```

**Change the frame of the view easily**
```swift
aView.x += 100 // move to right
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a var aView: NSView to make the example more concrete?

aView.width -= 10 // make the view narrower
aView.height -= 10 // make the view shorter
```

It will iterate on all the subviews of the view, and use the text / placeholder as key in `NSLocalizedString`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here: that comment is for the above section / example

public func with(x: CGFloat) -> CGRect
public func with(y: CGFloat) -> CGRect
public func with(width: CGFloat) -> CGRect
public func with(height: CGFloat) -> CGRect
Copy link
Owner

@tbaranes tbaranes Jan 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think to add func with(origin: CGPoint) -> CGRect and func with(size: CGSize) -> CGRect, can it be useful? 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's a good idea! I didn't think of that.

@tbaranes
Copy link
Owner

Also, can you add some tests? It's straight forward, should never fail, but we are never careful enough!

@Sweeper777
Copy link
Collaborator Author

Ok. I forgot about them!

@Sweeper777
Copy link
Collaborator Author

I have added everything (hopefully)! Can this merge?

Copy link
Owner

@tbaranes tbaranes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a last request changes: can you duplicate the UIViewExtensionsTests for macOS as well?

@Sweeper777
Copy link
Collaborator Author

Done!

Copy link
Owner

@tbaranes tbaranes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! Feel free to merge it once travis is green 🎉
Thanks for that PR!

@tbaranes
Copy link
Owner

tbaranes commented Jan 12, 2017

There's a few SwiftLint violations which is making travis failing.
Since it's only due to x, and y being too short, you can exclude that case by adding the following lines in to .swiftlint.yml:

variable_name:
  min_length: 2
  excluded: 
   - x
   - y

By the way, I suggest you ton install it, it's a nice linter and you will have the warnings / errors directly in xcode when building 😬

@Sweeper777
Copy link
Collaborator Author

Is .swiftlint.yml a file I have to create? I can't find it in the repo.

@tbaranes
Copy link
Owner

The configuration file for the core is there: ./SwiftyUtils/.swiftlint.yml
For the example, it's there (no need to change this one, just for your information): ./SwiftyUtils Example/.swiftlint.yml

@tbaranes
Copy link
Owner

I went ahead and fix it (+ bump a few others warnings due to the latest release) in #39
That was a work I have to do since a few time, so...

You will just have to rebase your PR once I merged the other, then, everything should be ok.

@Sweeper777
Copy link
Collaborator Author

Do you mean that once #39 is merged, I can press the bottom button there? Is that what rebase means?
screen shot 2017-01-12 at 1 10 54 pm

@tbaranes
Copy link
Owner

tbaranes commented Jan 12, 2017

We have to ensure first that travis is passing as expected (should be no issue there), but in order to test that, you have to rebase without merging, which means pull the lasts commits from master in your branch. Using Rebase and merge from github will directly merge the PR in master without waiting for travis.

If you are using a terminal:

git fetch origin            # Updates origin/master
git rebase origin/master    # Rebases current branch onto origin/master
git -f push                 # Force push to override git history (your commits must be the recent ones)

If you are using an application (tower, source tree...), they have generally an option build in to do it.

Let me know if you need more information!

@Sweeper777
Copy link
Collaborator Author

Ok, seems easy. I'll do that once I get back!

@Sweeper777
Copy link
Collaborator Author

It is telling me that git -f push has an unknown option -f. Should it be git push -f instead?

@tbaranes
Copy link
Owner

Yeah, should be that, my bad

@tbaranes
Copy link
Owner

tbaranes commented Jan 12, 2017

All good 👍 Feel free to merge that PR once travis is done.
Good job here, thanks again!

@tbaranes
Copy link
Owner

tbaranes commented Jan 12, 2017

Seems to be an issue left:

❌ /Users/travis/build/tbaranes/SwiftyUtils/SwiftyUtils/SwiftyUtils macOS Tests/NSViewExtensionsTest.swift:14:20: use of unresolved identifier 'NSView'

NSViewExtensionsTest.swift should target only macOS, seems to be currently iOS too

Just in case you don't know: you can click on "Details" (like in the below screenshot) to see the travis status (current build, success, failure... and details about what did fail)

screen shot 2017-01-12 at 18 07 19

@Sweeper777
Copy link
Collaborator Author

I think I fixed it. I built the target and ran the test. They all succeeded so it should be alright. Right?

@tbaranes
Copy link
Owner

Travis will tell us soon enough 😬
But yeah, if it passes in local, it should be ok for travis

@tbaranes
Copy link
Owner

@Sweeper777 Side note for the next time (I pushed directly in your branch this time):

  • Classes added in the Core must target tvOS and watchOS as well (same for the CoreTests)
  • When adding a new section in the README, you have to update the summary as well. Also, the README is sorted alphabetically

Otherwise 💯

@Sweeper777
Copy link
Collaborator Author

Is it normal for Travis to take so long? Is something wrong?

@tbaranes
Copy link
Owner

It can, that's depending how many build Travis is handling at the same time, and their structures status. Sometimes it's quite long...

@Sweeper777 Sweeper777 merged commit f230c0b into master Jan 13, 2017
@Sweeper777
Copy link
Collaborator Author

Oops! I was on my phone and I accidentally merged it! I'm so sorry! Travis seems to still fail saying that tests failed.

@tbaranes tbaranes deleted the uiview&cgrect branch January 13, 2017 07:01
@tbaranes
Copy link
Owner

The build failed of travis wasn't due to test but a timeout, it happened, the only solution in this case is to start again the build which has failed. I think you have the rights to do that since you are a contributor.

For the next time if there's really a test which has failed and a PR is accidentally merged, the good move is just to rollback to the last master commit before the merge, you can find the command line on SO.

For now, it's all good 👍

@Sweeper777
Copy link
Collaborator Author

Maybe update to 0.7.0 now?

@tbaranes
Copy link
Owner

👌Will do it this weekend or next week

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