-
Notifications
You must be signed in to change notification settings - Fork 2
How combine two functions as the one in AccessibilityIdentifier #5
Copy link
Copy link
Open
Labels
Code Designbetter architecture to discussbetter architecture to discuss
Description
😤
Here is two extensions PrettyRawRepresentable+helpers.swift and RawRepresentable+helpers.swift which are support different situation on enum.
But the most unacceptable thing is that their API is almost the same
enum WayOne: String, PrettyRawRepresentable {
case theWay
}
enum WayTwo: String {
case theWay
}
wayOneView >>> WayOne.theWay
wayTwoView >>> WayTwo.theWay
// wayOneView.accessibilityIdentifier == "WayOne_theWay"
// called in PrettyRawRepresentable+helpers.swift
let element_1: XCUIElement = WayOne.theWay.element
// wayTwoView.accessibilityIdentifier == "theWay"
// called in RawRepresentable+helpers.swift
let element_2: XCUIElement = WayTwo.theWay.elementcurrent
public protocol PrettyRawRepresentable: RawRepresentable where RawValue == String {
var prettyRawValue: RawValue { get }
}
public extension PrettyRawRepresentable {
var prettyRawValue: String {
let paths = String(reflecting: self).split(separator: ".").dropFirst()
if String(paths.last ?? "") != rawValue {
return rawValue
}
return paths.joined(separator: "_")
}
}
infix operator >>>
public func >>> <T: RawRepresentable>(lhs: UIAccessibilityIdentification?, rhs: T) where T.RawValue == String {
lhs?.accessibilityIdentifier = rhs.rawValue
}
public func >>> <T: PrettyRawRepresentable>(lhs: UIAccessibilityIdentification?, rhs: T) {
lhs?.accessibilityIdentifier = rhs.prettyRawValue
}wants the design
only use one function
public protocol PrettyRawRepresentable: RawRepresentable where RawValue == String {
var rawValue: RawValue { get }
}
public extension PrettyRawRepresentable {
var rawValue: String {
// how todo
}
}
infix operator >>>
public func >>> <T: RawRepresentable>(lhs: UIAccessibilityIdentification?, rhs: T) where T.RawValue == String {
lhs?.accessibilityIdentifier = rhs.rawValue
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Code Designbetter architecture to discussbetter architecture to discuss