Skip to content

Commit

Permalink
fix: added public access control
Browse files Browse the repository at this point in the history
  • Loading branch information
Louis Fournier committed Jul 7, 2018
1 parent 853c994 commit 2e830ca
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions ASAPImage/ASAPImageLoader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@

import UIKit

enum ASAPError: Error {
public enum ASAPError: Error {
case cantBuildImageFromData
}

class ASAPImageLoader: NSObject {
public class ASAPImageLoader: NSObject {

static let shared = ASAPImageLoader()
public static let shared = ASAPImageLoader()

private var taskAttributes: [Int:(data: Data, callback: (Result<UIImage>) -> Void)] = [:]
private var urlSession: URLSession? = nil
Expand All @@ -25,7 +25,7 @@ class ASAPImageLoader: NSObject {
}

@discardableResult
func load(imageAt url: URL, completion: @escaping (Result<UIImage>) -> Void) -> CancellationToken {
public func load(imageAt url: URL, completion: @escaping (Result<UIImage>) -> Void) -> CancellationToken {
let task = urlSession!.dataTask(with: url)
taskAttributes[task.taskIdentifier] = (Data(), completion)
task.resume()
Expand All @@ -34,7 +34,7 @@ class ASAPImageLoader: NSObject {
}

extension ASAPImageLoader: URLSessionTaskDelegate {
func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
public func urlSession(_ session: URLSession, task: URLSessionTask, didCompleteWithError error: Error?) {
if let error = error {
taskAttributes[task.taskIdentifier]?.callback(.failure(error))
} else if let data = taskAttributes[task.taskIdentifier]?.data, let image = UIImage(data: data) {
Expand All @@ -47,7 +47,7 @@ extension ASAPImageLoader: URLSessionTaskDelegate {
}

extension ASAPImageLoader: URLSessionDataDelegate {
func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive response: URLResponse, completionHandler: @escaping (URLSession.ResponseDisposition) -> Void) {
guard let response = response as? HTTPURLResponse
, 200 == response.statusCode
, let mimeType = response.mimeType
Expand All @@ -58,7 +58,7 @@ extension ASAPImageLoader: URLSessionDataDelegate {
completionHandler(.allow)
}

func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
public func urlSession(_ session: URLSession, dataTask: URLSessionDataTask, didReceive data: Data) {
taskAttributes[dataTask.taskIdentifier]?.data.append(data)
}
}
8 changes: 4 additions & 4 deletions ASAPImage/ASAPImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@

import UIKit

class ASAPImageView: UIImageView {
public class ASAPImageView: UIImageView {

private var token: CancellationToken?

override var image: UIImage? {
override public var image: UIImage? {
willSet {
token?.cancel()
token = nil
}
}

func load(imageAt url: URL, completion: ((Result<Void>) -> Void)? = nil) {
public func load(imageAt url: URL, completion: ((Result<Void>) -> Void)? = nil) {
token?.cancel()
token = ASAPImageLoader.shared.load(imageAt: url) { [weak self] result in
self?.token = nil
Expand All @@ -35,7 +35,7 @@ class ASAPImageView: UIImageView {
}
}

func cancel() {
public func cancel() {
token?.cancel()
token = nil
}
Expand Down
4 changes: 2 additions & 2 deletions ASAPImage/Async/CancellationToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@

import Foundation

class CancellationToken {
public class CancellationToken {
private weak var task: URLSessionDataTask?

init(with task: URLSessionDataTask) {
self.task = task
}

func cancel() {
public func cancel() {
task?.cancel()
}
}
2 changes: 1 addition & 1 deletion ASAPImage/Async/Result.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

enum Result<Value> {
public enum Result<Value> {
case success(Value)
case failure(Error)
}

0 comments on commit 2e830ca

Please sign in to comment.