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

Add extension of UIlabel for adding line spacing with the method of n… #438

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

osama10
Copy link

@osama10 osama10 commented Jul 11, 2017

I have added the extension of UILabel for adding linespacing between line of UILabel , it takes CGFloat as input and add that spacing to the UILabel

Checklist

  • New Extension
  • New Test
  • Changed more than one extension, but all changes are related
  • Trivial change (doesn't require changelog)

@EZSwiftExtensionsBot
Copy link

EZSwiftExtensionsBot commented Jul 11, 2017

1 Error
🚫 Please rebase to get rid of the merge commits in this PR
2 Warnings
⚠️ EZSwiftExtensionsTests/UILabelTests.swift#L56: treating a forced downcast to ‘NSMutableParagraphStyle’ as optional will never produce ‘nil’
paragraphStyle = value as! NSMutableParagraphStyle
⚠️ EZSwiftExtensionsTests/UILabelTests.swift#L56: treating a forced downcast to ‘NSMutableParagraphStyle’ as optional will never produce ‘nil’
paragraphStyle = value as! NSMutableParagraphStyle
3 Messages
📖 Executed 202 tests, with 0 failures (0 unexpected) in 7.126 (7.382) seconds
📖 Executed 187 tests, with 0 failures (0 unexpected) in 9.344 (9.549) seconds
📖 Executed 123 tests, with 0 failures (0 unexpected) in 4.724 (4.832) seconds

Generated by 🚫 Danger

@@ -65,6 +65,19 @@ extension UILabel {
self.text = _text
}, completion: nil)
}

// Set lineSpacing for UILabel
public func setLineSpacing(lineSpacing: CGFloat) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to write a unit test for this ?

@Khalian
Copy link
Collaborator

Khalian commented Jul 11, 2017

Could you also add a changelog entry for this. ?

@osama10
Copy link
Author

osama10 commented Jul 11, 2017 via email

@Khalian
Copy link
Collaborator

Khalian commented Jul 11, 2017

@osama10 Sure thing.

The changelog entry is a piece of text in the CHANGELOG.md file. Here is a sample entry

Date
init?(httpDateString: String)` in [PR] by Vic-L

The format is ExtensionClass methodAdded in [[PR]] (URL to pull request) by Author

public func setLineSpacing(lineSpacing: CGFloat) {
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.lineSpacing = 1.0
paragraphStyle.lineHeightMultiple = lineSpacing
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is confusing. Does this mean your spacing = 1.0 * lineHeight = lineSpacing. If so, you could just call the method arg as lineHeightMultiple.

paragraphStyle.lineHeightMultiple = lineSpacing
paragraphStyle.alignment = self.textAlignment

let attrString = NSMutableAttributedString(string: self.text!)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This could actually live as its own var. Otherwise its unnecessary allocation of the attr string per call.

paragraphStyle.alignment = self.textAlignment

let attrString = NSMutableAttributedString(string: self.text!)
attrString.addAttribute(NSFontAttributeName, value: self.font, range: NSMakeRange(0, attrString.length))
Copy link
Collaborator

Choose a reason for hiding this comment

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

NSMakeRange is repeated, you can abstract that away as a single call.

CHANGELOG.md Outdated
@@ -54,6 +54,9 @@ All notable changes to this project will be documented in this file.
- `validateEmail()` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/429) by *Vic-L*
- `validateDigits()` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/429) by *Vic-L*

12. **UILabelExtensions**
- `setLineSpacing(lineSpacing : CGFloat)` in [[PR]](https://github.com/goktugyil/EZSwiftExtensions/pull/438) by *osama10*
Copy link
Collaborator

Choose a reason for hiding this comment

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

Erm not under v1.10. Under unreleased. V 1.10 is already released as a pod.

@codecov-io
Copy link

codecov-io commented Jul 13, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@88919e2). Click here to learn what that means.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #438   +/-   ##
=========================================
  Coverage          ?   41.93%           
=========================================
  Files             ?       50           
  Lines             ?     2258           
  Branches          ?        0           
=========================================
  Hits              ?      947           
  Misses            ?     1311           
  Partials          ?        0
Impacted Files Coverage Δ
Sources/UILabelExtensions.swift 36.84% <0%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 88919e2...e736d02. Read the comment docs.

CHANGELOG.md Outdated
@@ -2,7 +2,8 @@
All notable changes to this project will be documented in this file.

## Unreleased

**UILabelExtensions**
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor : With a number (in this case 1).

Copy link
Author

Choose a reason for hiding this comment

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

So do I need removed this spacing ??

Copy link
Collaborator

Choose a reason for hiding this comment

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

have a 1 prior to that. Like a numbering thing. But that is really cosmetic, I would suggest taking a look at writing unit tests for the same.

@osama10
Copy link
Author

osama10 commented Jul 13, 2017 via email

@Khalian
Copy link
Collaborator

Khalian commented Jul 13, 2017

"I am new to swift development and don't know yet about writing unit test yet ... what should I do"

In order to write unit tests you would have to edit the unit test file, in your case https://github.com/goktugyil/EZSwiftExtensions/blob/master/EZSwiftExtensionsTests/UILabelTests.swift and run that against travis ci build (you can locally test the change on xcode by running the test target we wrote).

"is it necessary to write unit test for ensuring the acceptance of my contributionOn"

A unit test is a contract that gives reasonable confidence on the veracity of your changes. It also provides documentation in the form of self explanatary code, and also what said extension is meant to achieve. Unless its impossible to achieve writing a unit tests (an example would be UIDevice tests were write based mocks are blocked by swifts runtime), we should have unit tests.

@osama10
Copy link
Author

osama10 commented Aug 6, 2017

@Khalian It's not possible to write the unit test of my extension as it gives the line spacing between the lines of label and can on be witnessed visually.

@osama10
Copy link
Author

osama10 commented Aug 6, 2017

so what should i do now to get my contribution accepted. @Khalian

@Khalian
Copy link
Collaborator

Khalian commented Aug 6, 2017

  1. You can write a unit test by expecting the mutable state of self.attributedText attribute to contain that line spacing delta. That would verify that the paragraph style is modified (or newly created, this is not really my domain of expertise)

The purpose of the test is to make the method not brittle to change.

"so what should i do now to get my contribution accepted. @Khalian"

  1. There are a bunch of comments I posted.

@lfarah
Copy link
Collaborator

lfarah commented Aug 6, 2017

Hey @osama10, take a look at this

@osama10
Copy link
Author

osama10 commented Aug 25, 2017

@Khalian i have added the test . Now what should i do ??

label.setLineSpacing(lineSpacing: 1.5)

label.attributedText?.enumerateAttribute(NSParagraphStyleAttributeName , in: NSMakeRange(0, (label.attributedText?.length)!), options: [.longestEffectiveRangeNotRequired]) { value, range, isStop in

Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick : too many empty lines here are there that do not serve a purpose.

@Khalian
Copy link
Collaborator

Khalian commented Aug 25, 2017

I have quite a few comments across the files. Can you take a look at those?

@@ -7,6 +7,8 @@
//

#if os(iOS) || os(tvOS)
<<<<<<< HEAD
Copy link
Collaborator

Choose a reason for hiding this comment

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

You have unresolved merge commits here.

@@ -22,34 +24,67 @@ class UILabelTests: XCTestCase {
XCTAssertEqual(label2.font.pointSize, 20)
XCTAssertEqual(label.font.pointSize, 17)
}
>>>>>>> 638c47200b16776d978dc4598237109396915878
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks like an unresolved merge, please collapse your commits into one idempotent change.

I cannot even begin to tell you how much I despise non fast forward merges. Rebase your changes and replay them on top of the current HEAD commit.


let label = UILabel(x: 0, y: 0, w: 200, h: 50)
Copy link
Collaborator

@Khalian Khalian Aug 30, 2017

Choose a reason for hiding this comment

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

Are there any changes in these parts? Please make the code change idempotent to only the changes you are making. This looks like an indentation change which is unnecessary. The code already was properly indented.

Another important part of making this change idempotent is to ensure it appears as one single commit in the PR. I do not want to manually merge 12 commits with a couple of merge commits in it.

@osama10
Copy link
Author

osama10 commented Aug 30, 2017

@Khalian Can you please tell me what is the issue with my commit

@Khalian
Copy link
Collaborator

Khalian commented Aug 30, 2017

@osama10

  1. You have 16 of them right now instead of one idempotent change (i.e. one single commit). Moreover your commit is messing up with parts of the code that it should not.

  2. You are doing non fast forward merges, which is making the whole commit structure worse. Rebase and replay mainline on your branch, and then squash your commits to one idempotent change.

  3. You haven't actually addressed any of my comments sans the unit tests.

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

6 participants