Skip to content

Commit

Permalink
Apply if let shorthand syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-han committed Mar 6, 2024
1 parent 033bc24 commit df6057f
Show file tree
Hide file tree
Showing 16 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Sources/Nuke/Decoding/ImageDecoders+Default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ extension ImageDecoders {
defer { lock.unlock() }

func makeImage() -> PlatformImage? {
if let thumbnail = self.thumbnail {
if let thumbnail {
return makeThumbnail(data: data, options: thumbnail)
}
return ImageDecoders.Default._decode(data, scale: scale)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Internal/Graphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ struct ImageProcessingExtensions {
ctx.clip()
ctx.draw(cgImage, in: CGRect(origin: CGPoint.zero, size: cgImage.size))

if let border = border {
if let border {
ctx.setStrokeColor(border.color.cgColor)
ctx.addPath(path)
ctx.setLineWidth(border.width)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Internal/ImagePublisher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ private final class ImageSubscription<S>: Subscription where S: Subscriber, S: S
with: request,
queue: nil,
progress: { response, _, _ in
if let response = response {
if let response {
// Send progressively decoded image (if enabled and if any)
_ = subscriber.receive(response)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Internal/LinkedList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class LinkedList<Element> {

/// Adds a node to the end of the list.
func append(_ node: Node) {
if let last = last {
if let last {
last.next = node
node.previous = last
self.last = node
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Pipeline/ImagePipeline.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public final class ImagePipeline: @unchecked Sendable {
continuation.resume(throwing: CancellationError())
}
self.startImageTask(task, progress: { response, progress in
if let response = response {
if let response {
context?.previews?.yield(response)
} else {
context?.progress?.yield(progress)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Pipeline/ImagePipelineConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ extension ImagePipeline {
config.dataLoader = dataLoader

let dataCache = try? DataCache(name: name)
if let sizeLimit = sizeLimit {
if let sizeLimit {
dataCache?.sizeLimit = sizeLimit
}
config.dataCache = dataCache
Expand Down
6 changes: 3 additions & 3 deletions Sources/Nuke/Tasks/AsyncTask.swift
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ class AsyncTask<Value: Sendable, Error: Sendable>: AsyncTaskSubscriptionDelegate
}

inlineSubscription?.closure(event)
if let subscriptions = subscriptions {
if let subscriptions {
for subscription in subscriptions.values {
subscription.closure(event)
}
Expand Down Expand Up @@ -203,7 +203,7 @@ class AsyncTask<Value: Sendable, Error: Sendable>: AsyncTaskSubscriptionDelegate
// MARK: - Priority

private func updatePriority(suggestedPriority: TaskPriority?) {
if let suggestedPriority = suggestedPriority, suggestedPriority >= priority {
if let suggestedPriority, suggestedPriority >= priority {
// No need to recompute, won't go higher than that
priority = suggestedPriority
return
Expand All @@ -212,7 +212,7 @@ class AsyncTask<Value: Sendable, Error: Sendable>: AsyncTaskSubscriptionDelegate
var newPriority = inlineSubscription?.priority
// Same as subscriptions.map { $0?.priority }.max() but without allocating
// any memory for redundant arrays
if let subscriptions = subscriptions {
if let subscriptions {
for subscription in subscriptions.values {
if newPriority == nil {
newPriority = subscription.priority
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Tasks/TaskFetchDecodedImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ final class TaskFetchDecodedImage: ImagePipelineTask<ImageResponse> {
// Lazily creates decoding for task
private func getDecoder(for context: ImageDecodingContext) -> (any ImageDecoding)? {
// Return the existing processor in case it has already been created.
if let decoder = self.decoder {
if let decoder {
return decoder
}
let decoder = pipeline.delegate.imageDecoder(for: context, pipeline: pipeline)
Expand Down
4 changes: 2 additions & 2 deletions Sources/Nuke/Tasks/TaskFetchOriginalImageData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ final class TaskFetchOriginalImageData: ImagePipelineTask<(Data, URLResponse?)>
// Check if this is the first response.
if urlResponse == nil {
// See if the server confirmed that the resumable data can be used
if let resumableData = resumableData, ResumableData.isResumedResponse(response) {
if let resumableData, ResumableData.isResumedResponse(response) {
data = resumableData.data
resumedDataCount = Int64(resumableData.data.count)
signpost(self, "LoadImageData", .event, "Resumed with data \(Formatter.bytes(resumedDataCount))")
Expand Down Expand Up @@ -128,7 +128,7 @@ final class TaskFetchOriginalImageData: ImagePipelineTask<(Data, URLResponse?)>
}

private func dataTaskDidFinish(error: Swift.Error?) {
if let error = error {
if let error {
tryToSaveResumableData()
send(error: .dataLoadingFailed(error: error))
return
Expand Down
2 changes: 1 addition & 1 deletion Sources/Nuke/Tasks/TaskLoadData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class TaskLoadData: ImagePipelineTask<(Data, URLResponse?)> {
pipeline.cache.cachedData(for: request)
}
pipeline.queue.async {
if let data = data {
if let data {
self.send(value: (data, nil), isCompleted: true)
} else {
self.loadData()
Expand Down
4 changes: 2 additions & 2 deletions Sources/Nuke/Tasks/TaskLoadImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ final class TaskLoadImage: ImagePipelineTask<ImageResponse> {
pipeline.cache.cachedData(for: request)
}
pipeline.queue.async {
if let data = data {
if let data {
self.didReceiveCachedData(data)
} else {
self.fetchImage()
Expand Down Expand Up @@ -77,7 +77,7 @@ final class TaskLoadImage: ImagePipelineTask<ImageResponse> {
}

private func didDecodeCachedData(_ response: ImageResponse?) {
if let response = response {
if let response {
decompressImage(response, isCompleted: true, isFromDiskCache: true)
} else {
fetchImage()
Expand Down
2 changes: 1 addition & 1 deletion Sources/NukeExtensions/ImageViewExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ private final class ImageViewController {
}

task = pipeline.loadImage(with: request, queue: .main, progress: { [weak self] response, completedCount, totalCount in
if let response = response, options.isProgressiveRenderingEnabled {
if let response, options.isProgressiveRenderingEnabled {
self?.handle(partialImage: response)
}
progress?(response, completedCount, totalCount)
Expand Down
4 changes: 2 additions & 2 deletions Sources/NukeUI/FetchImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public final class FetchImage: ObservableObject, Identifiable {
if !processors.isEmpty && request.processors.isEmpty {
request.processors = processors
}
if let priority = self.priority {
if let priority {
request.priority = priority
}

Expand All @@ -133,7 +133,7 @@ public final class FetchImage: ObservableObject, Identifiable {
with: request,
progress: { [weak self] response, completed, total in
guard let self = self else { return }
if let response = response {
if let response {
withTransaction(self.transaction) {
self.handle(preview: response)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/NukeUI/LazyImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public struct LazyImage<Content: View>: View {

public var body: some View {
ZStack {
if let makeContent = makeContent {
if let makeContent {
makeContent(viewModel)
} else {
makeDefaultContent(for: viewModel)
Expand Down
16 changes: 8 additions & 8 deletions Sources/NukeUI/LazyImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public final class LazyImageView: _PlatformBaseView {
/// dynamically. `nil` by default.
public var priority: ImageRequest.Priority? {
didSet {
if let priority = self.priority {
if let priority {
imageTask?.priority = priority
}
}
Expand Down Expand Up @@ -266,10 +266,10 @@ public final class LazyImageView: _PlatformBaseView {
return
}

if let processors = self.processors, !processors.isEmpty, request.processors.isEmpty {
if let processors, !processors.isEmpty, request.processors.isEmpty {
request.processors = processors
}
if let priority = self.priority {
if let priority {
request.priority = priority
}

Expand All @@ -292,7 +292,7 @@ public final class LazyImageView: _PlatformBaseView {
progress: { [weak self] response, completed, total in
guard let self = self else { return }
let progress = ImageTask.Progress(completed: completed, total: total)
if let response = response {
if let response {
self.handle(preview: response)
self.onPreview?(response)
} else {
Expand Down Expand Up @@ -366,10 +366,10 @@ public final class LazyImageView: _PlatformBaseView {
}

private func setPlaceholderView(_ oldView: _PlatformBaseView?, _ newView: _PlatformBaseView?) {
if let oldView = oldView {
if let oldView {
oldView.removeFromSuperview()
}
if let newView = newView {
if let newView {
newView.isHidden = !imageView.isHidden
insertSubview(newView, at: 0)
setNeedsUpdateConstraints()
Expand Down Expand Up @@ -401,10 +401,10 @@ public final class LazyImageView: _PlatformBaseView {
}

private func setFailureView(_ oldView: _PlatformBaseView?, _ newView: _PlatformBaseView?) {
if let oldView = oldView {
if let oldView {
oldView.removeFromSuperview()
}
if let newView = newView {
if let newView {
newView.isHidden = true
insertSubview(newView, at: 0)
setNeedsUpdateConstraints()
Expand Down
2 changes: 1 addition & 1 deletion Tests/CombineExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension Subscriptions {
}

func start(_ closure: @escaping (AnySubscriber<Output, Failure>) -> Void) {
if let subscriber = subscriber {
if let subscriber {
closure(AnySubscriber(subscriber))
}
}
Expand Down

0 comments on commit df6057f

Please sign in to comment.