Skip to content

Commit

Permalink
refactor: Code structure optimization.
Browse files Browse the repository at this point in the history
  • Loading branch information
liam-i committed Mar 12, 2024
1 parent f808916 commit eee1ba0
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
18 changes: 9 additions & 9 deletions Example/Applications/ApplicationDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class ApplicationDetailViewController: UITableViewController {
imageName = "header_podcasts"
}

if let imageName = imageName {
if let imageName {
let image = UIImage(named: imageName)
let imageView = UIImageView(image: image)
imageView.isUserInteractionEnabled = true
Expand All @@ -172,7 +172,7 @@ class ApplicationDetailViewController: UITableViewController {
imageView.addGestureRecognizer(tapGesture)

var frame = view.bounds
if let image = image {
if let image {
frame.size.height = image.size.height
}
let headerView = UIView(frame: frame)
Expand Down Expand Up @@ -293,8 +293,8 @@ extension ApplicationDetailViewController: BlankSlateDataSource, BlankSlateDeleg
return nil
}

if let font = font { attributes[.font] = font }
if let textColor = textColor { attributes[.foregroundColor] = textColor }
if let font { attributes[.font] = font }
if let textColor { attributes[.foregroundColor] = textColor }
return NSAttributedString(string: text, attributes: attributes)
}

Expand Down Expand Up @@ -407,10 +407,10 @@ extension ApplicationDetailViewController: BlankSlateDataSource, BlankSlateDeleg
return nil
}

if let font = font {
if let font {
attributes[.font] = font
}
if let textColor = textColor {
if let textColor {
attributes[.foregroundColor] = textColor
}
attributes[.paragraphStyle] = paragraph
Expand Down Expand Up @@ -485,8 +485,8 @@ extension ApplicationDetailViewController: BlankSlateDataSource, BlankSlateDeleg
}

var attributes: [NSAttributedString.Key: Any] = [:]
if let font = font { attributes[.font] = font }
if let textColor = textColor { attributes[.foregroundColor] = textColor }
if let font { attributes[.font] = font }
if let textColor { attributes[.foregroundColor] = textColor }
return NSAttributedString(string: text, attributes: attributes)
}

Expand Down Expand Up @@ -546,7 +546,7 @@ extension ApplicationDetailViewController: BlankSlateDataSource, BlankSlateDeleg
func offset(forBlankSlate scrollView: UIScrollView) -> CGPoint {
if application.type == .kickstarter {
var offset = UIApplication.shared.statusBarFrame.height
if let navigationController = navigationController {
if let navigationController {
offset += navigationController.navigationBar.frame.height
}
return CGPoint(x: 0, y: -offset)
Expand Down
2 changes: 1 addition & 1 deletion Example/Colors/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ struct Color: Equatable {
}

static func roundImage(for size: CGSize, with color: UIColor?) -> UIImage? {
guard let color = color else { return nil }
guard let color else { return nil }

let bounds = CGRect(origin: .zero, size: size)

Expand Down
2 changes: 1 addition & 1 deletion Example/Colors/SearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class SearchViewController: UIViewController {
self.searchController = searchController
searchResultsController.searchController = searchController
searchResultsController.searchResult = { [weak self](selectedColor) in
guard let `self` = self else { return }
guard let self else { return }
self.selectedColor = selectedColor
self.updateContent()
}
Expand Down
16 changes: 8 additions & 8 deletions Sources/Internal/Impl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ extension UIScrollView {
set {
objc_setAssociatedObject(self, &kBlankSlateStatusKey, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)

guard let newValue = newValue, newValue != .loading else {
guard let newValue, newValue != .loading else {
return reloadBlankSlateIfNeeded()
}

Expand All @@ -70,7 +70,7 @@ extension UIScrollView {
}

func reloadBlankSlateIfNeeded() {
guard let blankSlateDataSource = blankSlateDataSource else {
guard let blankSlateDataSource else {
dismissBlankSlateIfNeeded()
return
}
Expand Down Expand Up @@ -167,7 +167,7 @@ extension UIScrollView {

func dismissBlankSlateIfNeeded() {
var isBlankSlateVisible = false
if let blankSlateView = blankSlateView {
if let blankSlateView {
isBlankSlateVisible = true
blankSlateDelegate?.blankSlateWillDisappear(self) // Notifies that the empty dataset view will disappear

Expand Down Expand Up @@ -213,11 +213,11 @@ extension UIScrollView {
view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
view.isHidden = true
view.isTouchAllowed = { [weak self] in
guard let `self` = self, let blankSlateDelegate = blankSlateDelegate else { return true }
guard let self, let blankSlateDelegate = blankSlateDelegate else { return true }
return blankSlateDelegate.blankSlateShouldAllowTouch(self)
}
view.shouldRecognizeSimultaneously = { [weak self](other, of) in
guard let `self` = self, let blankSlateDelegate = blankSlateDelegate else { return false }
guard let self, let blankSlateDelegate = blankSlateDelegate else { return false }
if let scrollView = blankSlateDelegate as? UIScrollView, scrollView == self {
return false
}
Expand All @@ -228,13 +228,13 @@ extension UIScrollView {
return false
}
view.didTap = { [weak self] in
guard let `self` = self, let blankSlateDelegate = blankSlateDelegate else { return }
guard let self, let blankSlateDelegate = blankSlateDelegate else { return }
if let button = $0 as? UIButton {
return blankSlateDelegate.blankSlate(self, didTapButton: button)
}
blankSlateDelegate.blankSlate(self, didTapView: $0)
}
self.blankSlateView = view
blankSlateView = view
return view
}

Expand Down Expand Up @@ -281,7 +281,7 @@ private class WeakObject {
private(set) weak var value: AnyObject?

init?(_ value: AnyObject?) {
guard let value = value else { return nil }
guard let value else { return nil }
self.value = value
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/Internal/View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ extension BlankSlate {

let view = element.0
let layout = element.1
if let previous = previous { // Previous view
if let previous { // Previous view
constraints.append(view.topAnchor.constraint(equalTo: previous.0.bottomAnchor, constant: layout.edgeInsets.top))
} else { // First view
constraints.append(view.topAnchor.constraint(equalTo: contentView.topAnchor, constant: layout.edgeInsets.top))
Expand Down Expand Up @@ -245,7 +245,7 @@ extension BlankSlate {

// MARK: - UIGestureRecognizerDelegate
override func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if let isTouchAllowed = isTouchAllowed, isEqual(gestureRecognizer.view) {
if let isTouchAllowed, isEqual(gestureRecognizer.view) {
return isTouchAllowed()
}
return super.gestureRecognizerShouldBegin(gestureRecognizer)
Expand Down

0 comments on commit eee1ba0

Please sign in to comment.