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

Assigning rows to RadioSection & Row protocol equatibility #14

Merged
merged 6 commits into from
Apr 10, 2018
Merged

Assigning rows to RadioSection & Row protocol equatibility #14

merged 6 commits into from
Apr 10, 2018

Conversation

z3bi
Copy link
Contributor

@z3bi z3bi commented Apr 7, 2018

fixes issue when dynamically assigning rows in RadioSection, also fixes equatable compliance of Row protocol

}

/// Returns true iff `lhs` and `rhs` have equal titles and subtitles.
func ==(lhs: Row, rhs: Row) -> Bool {

Choose a reason for hiding this comment

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

Explicit Top Level ACL Violation: Top-level declarations should specify Access Control Level keywords explicitly. (explicit_top_level_acl)
Operator Function Whitespace Violation: Operators should be surrounded by a single whitespace when defining them. (operator_whitespace)

Copy link
Owner

Choose a reason for hiding this comment

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

This causes a build error. Can you explain a little bit more about why this change is needed?

Copy link
Contributor Author

@z3bi z3bi Apr 8, 2018

Choose a reason for hiding this comment

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

You need a to declare the == function as top level in order to compare two different Row items. It looks like to resolve the build error we must also have the non-top level declaration.

@@ -49,7 +49,7 @@ open class RadioSection: Section {
return options
}
set {
options = rows as? [OptionRowCompatible] ?? options
options = newValue as? [OptionRowCompatible] ?? options
Copy link
Owner

Choose a reason for hiding this comment

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

Nice catch, thank you!

}

/// Returns true iff `lhs` and `rhs` have equal titles and subtitles.
func ==(lhs: Row, rhs: Row) -> Bool {
Copy link
Owner

Choose a reason for hiding this comment

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

This causes a build error. Can you explain a little bit more about why this change is needed?

@codecov
Copy link

codecov bot commented Apr 8, 2018

Codecov Report

Merging #14 into develop will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff            @@
##           develop      #14   +/-   ##
========================================
  Coverage    89.32%   89.32%           
========================================
  Files           14       14           
  Lines          309      309           
========================================
  Hits           276      276           
  Misses          33       33
Flag Coverage Δ
#ios 89.32% <0%> (ø) ⬆️
Impacted Files Coverage Δ
Source/Protocol/Row.swift 100% <ø> (ø) ⬆️
Source/Model/RadioSection.swift 90.69% <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 94ada80...64b0922. Read the comment docs.


/// Returns true iff `lhs` and `rhs` have equal titles and subtitles.
public func == (lhs: Row, rhs: Row) -> Bool {
return lhs.title == rhs.title && lhs.subtitle == rhs.subtitle
Copy link
Owner

Choose a reason for hiding this comment

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

I just realised why you'd like to add this. Perhaps it's because the Row protocol doesn't conform to Equatable. By adding this global function, there'd be some cases like the following:

let a: Row = TapActionRow(title: "same title", action: nil)
let b: Row = SwitchRow(title: "same title", switchValue: false, action: nil)

print(a == b) // true, but they shouldn't be equal.

This makes me wonder if the Row extension providing a default == implementation was misleading in the first place.

Since all row classes (except TapActionRow) implement their own == implementation, this Row extension can probably be removed. Therefore TapActionRow should implement its own Equatable conformance.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well my reason for doing this was to add a slight bit more dynamism to the library, I used it to traverse the tableContents matching a Row item to get the indexPath, use that to get the cell, and then call customize() from the row item to that cell.

What might make it even better would be to simply declare the Row protocol as a class protocol. That would allow for identity checks which would be even better.

Copy link
Owner

Choose a reason for hiding this comment

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

I think this global == function would be better declared in your project's scope where you need it. Having the Row as a class protocol sounds like a good solution to me. 👍

/// Returns true iff `lhs` and `rhs` have equal titles and subtitles.
public static func == (lhs: Self, rhs: Self) -> Bool {
return lhs.title == rhs.title && lhs.subtitle == rhs.subtitle
}

Choose a reason for hiding this comment

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

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

}


extension Row {

Choose a reason for hiding this comment

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

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

/// A closure related to the action of the row.
var action: ((Row) -> Void)? { get }

Choose a reason for hiding this comment

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

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

/// The subtitle text of the row.
var subtitle: Subtitle? { get }

Choose a reason for hiding this comment

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

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

/// The title text of the row.
var title: String { get }

Choose a reason for hiding this comment

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

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

public protocol Row {

public protocol Row: class {

Choose a reason for hiding this comment

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

Trailing Whitespace Violation: Lines should not have trailing whitespace. (trailing_whitespace)

@bcylin bcylin merged commit 8829e44 into bcylin:develop Apr 10, 2018
@bcylin
Copy link
Owner

bcylin commented Apr 10, 2018

Thanks for your contribution to the project!

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.

3 participants