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

use switch-case in ConstraintInsetTarget and constraintOffsetTargetValue will be better? #528

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 8 additions & 7 deletions Source/ConstraintInsetTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,20 @@ extension ConstraintInsets: ConstraintInsetTarget {
extension ConstraintInsetTarget {

internal var constraintInsetTargetValue: ConstraintInsets {
if let amount = self as? ConstraintInsets {
switch self {
case let amount as ConstraintInsets:
return amount
} else if let amount = self as? Float {
case let amount as Float:
return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
} else if let amount = self as? Double {
case let amount as Double:
return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
} else if let amount = self as? CGFloat {
case let amount as CGFloat:
return ConstraintInsets(top: amount, left: amount, bottom: amount, right: amount)
} else if let amount = self as? Int {
case let amount as Int:
return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
} else if let amount = self as? UInt {
case let amount as UInt:
return ConstraintInsets(top: CGFloat(amount), left: CGFloat(amount), bottom: CGFloat(amount), right: CGFloat(amount))
} else {
default:
return ConstraintInsets(top: 0, left: 0, bottom: 0, right: 0)
}
}
Expand Down
13 changes: 7 additions & 6 deletions Source/ConstraintOffsetTarget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,18 @@ extension ConstraintOffsetTarget {

internal var constraintOffsetTargetValue: CGFloat {
let offset: CGFloat
if let amount = self as? Float {
switch self {
case let amount as Float:
offset = CGFloat(amount)
} else if let amount = self as? Double {
case let amount as Double:
offset = CGFloat(amount)
} else if let amount = self as? CGFloat {
case let amount as CGFloat:
offset = CGFloat(amount)
} else if let amount = self as? Int {
case let amount as Int:
offset = CGFloat(amount)
} else if let amount = self as? UInt {
case let amount as UInt:
offset = CGFloat(amount)
} else {
default:
offset = 0.0
}
return offset
Expand Down