An image download extension of the image view written in Swift for iOS, tvOS and macOS.

Overview

Moa, an image downloader written in Swift for iOS, tvOS and macOS

Carthage compatible CocoaPods Version Swift Package Manager compatible License Platform

Moa is an image download library written in Swift. It allows to download and show an image in an image view by setting its moa.url property.

imageView.moa.url = "https://bit.ly/moa_image"
  • Images are downloaded asynchronously.
  • Uses URLSession for networking and caching.
  • Allows to configure cache size and policy.
  • Can be used without an image view.
  • Provides closure properties for image manipulation and error handling.
  • Includes unit testing mode for faking network responses.
  • Contains logging capabilities for debugging network problems.

Moa hunting

"Lost, like the Moa is lost" - Maori proverb

'Hunting Moa' drawing by Joseph Smit (1836-1929). File source: Wikimedia Commons.

Setup

There are multiple ways you can add Moa to your Xcode project.

Add source (iOS 7+)

Simply add MoaDistrib.swift file into your Xcode project.

Setup with Carthage (iOS 8+)

Alternatively, add github "evgenyneu/moa" ~> 12.0 to your Cartfile and run carthage update.

Setup with CocoaPods (iOS 8+)

If you are using CocoaPods add this text to your Podfile and run pod install.

use_frameworks!
target 'Your target name'
pod 'moa', '~> 12.0'

Setup with Swift Package Manager

Legacy Swift versions

Setup a previous version of the library if you use an older version of Swift.

Usage

  1. Add import moa to your source code (unless you used the file setup method).

  2. Drag an Image View to your view in the storyboard. Create an outlet property for this image view in your view controller. Alternatively, instead of using the storyboard you can create a UIImageView object in code.

  3. Set moa.url property of the image view to start asynchronous image download. The image will be automatically displayed when download is finished.

imageView.moa.url = "https://bit.ly/moa_image"

Loading images from insecure HTTP hosts

If your image URLs are not https you will need to add an exception to the Info.plist file. This will allow the App Transport Security to load the images from insecure HTTP hosts.

Canceling download

Ongoing image download for the image view is automatically canceled when:

  1. Image view is deallocated.
  2. New image download is started: imageView.moa.url = ....

Call imageView.moa.cancel() to manually cancel the download.

Supply an error image

You can supply an error image that will be used if an error occurs during image download.

imageView.moa.errorImage = UIImage(named: "ImageNotFound.jpg")
imageView.moa.url = "https://bit.ly/moa_image"

Alternatively, one can supply a global error image that will be used for all failed image downloads.

Moa.errorImage = UIImage(named: "ImageNotFound.jpg")

Show a placeholder image

Here is how to show a placeholder image in the image view. The placeholder will be replaced by the image from the network when it arrives.

imageView.image = placeholderImage
imageView.moa.url = "https://bit.ly/moa_image"

Advanced features

Supplying completion closure

Assign a closure that will be called when image is received.

imageView.moa.onSuccess = { image in
  return image
}

imageView.moa.url = "https://bit.ly/moa_image"
  • The closure will be called after download finishes and before the image is assigned to the image view.
  • This is a good place to manipulate the image before it is shown.
  • The closure returns an image that will be shown in the image view. Return nil if you do not want the image to be shown.
  • The closure as called in the main queue. Use onSuccessAsync property instead if you need to do time consuming operations.
  • When errorImage is supplied and an error occurs the success closures are called.

Supplying error closure

imageView.moa.onError = { error, response in
  // Handle error
}

imageView.moa.url = "https://bit.ly/moa_image"
  • The closure is called in the main queue if image download fails. Use onErrorAsync property instead if you need to do time consuming operations.
  • See the "logging" section if you need to find out the type of the error.

Download an image without an image view

An instance of Moa class can also be used without an image view. A strong reference to Moa instance needs to be kept.

let moa = Moa()
moa.onSuccess = { image in
  // image is loaded
  return image
}
moa.url = "https://bit.ly/moa_image"

Clearing HTTP session

The following method calls finishTasksAndInvalidate on the current URLSession object. A new session object will be created for future image downloads.

MoaHttpSession.clearSession()

You may never need to call this method in your app. I needed to call it periodically to workaround a strange URLSession bug which you may not encounter.

Image caching

Use the Moa.settings.cache to change caching settings. For more information please refer to the moa image caching manual.

// By default images are cached according to their response HTTP headers.
Moa.settings.cache.requestCachePolicy = .useProtocolCachePolicy

// Always cache images locally regardless of their response HTTP headers
Moa.settings.cache.requestCachePolicy = .returnCacheDataElseLoad

// Change the name of the cache directory. Useful for sharing cache with the rest of the app.
Moa.settings.cache.diskPath = "MyAppSharedCache"

Settings

Use Moa.settings property to change moa image download settings.

// Set the maximum number of simultaneous image downloads. Default: 4.
Moa.settings.maximumSimultaneousDownloads = 5

// Change timeout for image requests. Default: 10.
Moa.settings.requestTimeoutSeconds = 20

Logging

You can use the moa logger to see how/when the images are loaded or debug a network problem. One can use a pre-made MoaConsoleLogger function to see the log messages in the Xcode console or write a custom logger. See the logging manual for more information.

// Log to console
Moa.logger = MoaConsoleLogger

// Load an image
imageView.moa.url = "https://bit.ly/moa_image"

// Attempt to load a missing image
imageView.moa.url = "https://bit.ly/moa_image_missing.jpg"

Logging to console with moa

Unit testing

Sometimes it is useful to prevent code from making real HTTP requests. Moa includes MoaSimulator class for testing image downloads and faking network responses. See unit test manual for more information.

// Autorespond with the given image to all image requests
MoaSimulator.autorespondWithImage("www.site.com", image: UIImage(named: "35px.jpg")!)

Demo app

The demo iOS app shows how to load images in a collection view with Moa.

Moa image downloader demo iOS app

Alternative solutions

Here is the list of other image download libraries for Swift.

Credits

License

Moa is released under the MIT License.

Feedback is welcome

If you notice any issue, got stuck or just want to chat feel free to create an issue. I will be happy to help you.

•ᴥ•

This project is dedicated to the moa, species of flightless birds that lived in New Zealand and became extinct in 15th century.

Comments
  • Some error after update to last version 5.0.0

    Some error after update to last version 5.0.0

    Hi

    I'm having same errors after install version 5.0

    File: MoaHttpSession.swift configuration.timeoutIntervalForRequest = Moa.settings.requestTimeoutSeconds configuration.timeoutIntervalForResource = Moa.settings.requestTimeoutSeconds configuration.httpMaximumConnectionsPerHost = Moa.settings.maximumSimultaneousDownloads configuration.requestCachePolicy = Moa.settings.cache.requestCachePolicy

    MoaHttpSession.swift:26:5: Function 'configuration' was used as a property; add () to call it

    File: MoaString.swift

    if ignoreCase { _ = options.insert(NSString.CompareOptions.caseInsensitive) }
    if ignoreDiacritic { _ = options.insert(NSString.CompareOptions.diacriticInsensitive) }
    

    'NSString.CompareOptions' has no member 'caseInsensitive' 'NSString.CompareOptions' has no member 'diacriticInsensitive'

    Best regards Davjd

    opened by yop289 5
  • Image flicker when table view reload called

    Image flicker when table view reload called

    Hi

    I m facing some issue when table view reload on swipe the screen flicker with white for 1 sec . Is there way to stop flicker the table view reload and image called form server

    opened by sumeet85 3
  • ** BUILD FAILED ** with Carthage, Xcode 7.3.1

    ** BUILD FAILED ** with Carthage, Xcode 7.3.1

    I am using Carthage. I got error while installing.

    MacBook-Pro:ios yuchen$ carthage update --platform iOS
    *** Fetching Alamofire
    *** Fetching SwiftyJSON
    *** Fetching Auk
    *** Fetching moa
    *** Checking out Alamofire at "3.4.2"
    *** Checking out SwiftyJSON at "2.3.3"
    *** Checking out Auk at "6.0.0"
    *** Checking out moa at "8.0.0"
    *** xcodebuild output can be found in /var/folders/1l/4rd_dg795n34hsrry55z09_m0000gn/T/carthage-xcodebuild.36neIV.log
    *** Building scheme "Alamofire iOS" in Alamofire.xcworkspace
    *** Building scheme "moa" in moa.xcodeproj
    ** BUILD FAILED **
    
    
    The following build commands failed:
        CompileSwift normal arm64
        CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
    (2 failures)
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Logger/MoaConsoleLogger.swift:12:30: warning: extraneous '_' in parameter: 'type' has no keyword argument name
    public func MoaConsoleLogger(_ type: MoaLogType, url: String, statusCode: Int?, error: Error?) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:51:4: error: unknown attribute 'discardableResult'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:52:31: warning: extraneous '_' in parameter: 'urlPart' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:69:4: error: unknown attribute 'discardableResult'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:70:43: warning: extraneous '_' in parameter: 'urlPart' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:89:4: error: unknown attribute 'discardableResult'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:90:43: warning: extraneous '_' in parameter: 'urlPart' has no keyword argument name
      public static func autorespondWithError(_ urlPart: String, error: Error? = nil,
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:103:37: warning: extraneous '_' in parameter: 'url' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:109:32: warning: extraneous '_' in parameter: 'url' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:156:32: warning: extraneous '_' in parameter: 'image' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:171:32: warning: extraneous '_' in parameter: 'error' has no keyword argument name
      public func respondWithError(_ error: Error? = nil, response: HTTPURLResponse? = nil) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttp.swift:10:17: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttp.swift:11:15: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttp.swift:9:30: warning: extraneous '_' in parameter: 'url' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttp.swift:23:17: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttp.swift:24:15: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImage.swift:11:17: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImage.swift:12:15: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImage.swift:10:30: warning: extraneous '_' in parameter: 'url' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImage.swift:22:29: warning: extraneous '_' in parameter: 'data' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImage.swift:57:37: warning: extraneous '_' in parameter: 'mimeType' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:27:49: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:28:15: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:27:22: warning: extraneous '_' in parameter: 'url' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:53:32: warning: extraneous '_' in parameter: 'image' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:66:32: warning: extraneous '_' in parameter: 'error' has no keyword argument name
      public func respondWithError(_ error: Error? = nil, response: HTTPURLResponse? = nil) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Utils/MoaTime.swift:5:23: warning: extraneous '_' in parameter: 'date' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:22:49: error: expected member name following '.'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:22:49: error: consecutive statements on a line must be separated by ';'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:22:49: error: 'default' label can only appear inside a 'switch' statement
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:78:1: error: expected '}' at end of brace statement
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:78:1: error: expected declaration
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImageDownloader.swift:22:49: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImageDownloader.swift:23:15: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImageDownloader.swift:22:22: warning: extraneous '_' in parameter: 'url' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImageDownloader.swift:39:35: error: boolean condition requires 'where' to separate it from variable binding
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/MoaImageDownloader.swift:5:49: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/MoaImageDownloader.swift:6:15: error: unknown attribute 'escaping'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/MoaImageDownloader.swift:5:22: warning: extraneous '_' in parameter: 'url' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Logger/MoaLoggerText.swift:20:27: warning: extraneous '_' in parameter: 'type' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:180:30: warning: extraneous '_' in parameter: 'url' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:205:35: warning: extraneous '_' in parameter: 'image' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:229:39: warning: extraneous '_' in parameter: 'image' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:248:33: warning: extraneous '_' in parameter: 'error' has no keyword argument name
      private func handleErrorAsync(_ error: Error?, response: HTTPURLResponse?, isSimulated: Bool) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Utils/MoaString.swift:8:24: warning: extraneous '_' in parameter: 'text' has no keyword argument name
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Logger/MoaConsoleLogger.swift:12:88: error: use of undeclared type 'Error'
    public func MoaConsoleLogger(_ type: MoaLogType, url: String, statusCode: Int?, error: Error?) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Logger/MoaLoggerText.swift:21:10: error: use of undeclared type 'Error'
      error: Error?) -> String {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:90:69: error: use of undeclared type 'Error'
      public static func autorespondWithError(_ urlPart: String, error: Error? = nil,
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:91:15: error: use of undeclared type 'HTTPURLResponse'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:140:37: error: use of undeclared type 'Error'
      var autorespondWithError: (error: Error?, response: HTTPURLResponse?)?
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:171:41: error: use of undeclared type 'Error'
      public func respondWithError(_ error: Error? = nil, response: HTTPURLResponse? = nil) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulator.swift:171:65: error: use of undeclared type 'HTTPURLResponse'
      public func respondWithError(_ error: Error? = nil, response: HTTPURLResponse? = nil) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:18:37: error: use of undeclared type 'Error'
      var autorespondWithError: (error: Error?, response: HTTPURLResponse?)?
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:66:41: error: use of undeclared type 'Error'
      public func respondWithError(_ error: Error? = nil, response: HTTPURLResponse? = nil) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:66:65: error: use of undeclared type 'HTTPURLResponse'
      public func respondWithError(_ error: Error? = nil, response: HTTPURLResponse? = nil) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttp.swift:11:59: error: use of undeclared type 'URLSessionDataTask'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttp.swift:24:59: error: use of undeclared type 'URLSessionDataTask'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttp.swift:13:24: error: use of unresolved identifier 'URL'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaError.swift:8:23: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImage.swift:12:59: error: use of undeclared type 'URLSessionDataTask'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImage.swift:22:37: error: use of undeclared type 'Data'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImage.swift:23:15: error: use of undeclared type 'HTTPURLResponse'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImage.swift:25:15: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:21:18: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Simulator/MoaSimulatedImageDownloader.swift:28:25: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/MoaImageDownloader.swift:6:25: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Utils/MoaTime.swift:5:31: error: use of undeclared type 'Date'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Utils/MoaTime.swift:6:25: error: use of unresolved identifier 'DateFormatter'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Utils/MoaTime.swift:7:20: error: use of unresolved identifier 'TimeZone'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Utils/MoaTime.swift:9:27: error: use of unresolved identifier 'Locale'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Utils/MoaTime.swift:18:20: error: use of unresolved identifier 'Date'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:5:38: error: use of undeclared type 'URLSession'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:7:23: error: use of undeclared type 'URLSession'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:7:23: error: use of undeclared type 'URLSession'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:7:23: error: use of undeclared type 'URLSession'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpSession.swift:21:45: error: use of undeclared type 'URLSession'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaError.swift:8:13: error: type 'MoaError' does not conform to protocol 'RawRepresentable'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaError.swift:55:21: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/MoaSettingsCache.swift:25:47: error: 'CachePolicy' is not a member type of 'NSURLRequest'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/MoaSettingsCache.swift:25:14: error: could not infer type for 'requestCachePolicy'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImageDownloader.swift:4:13: error: use of undeclared type 'URLSessionDataTask'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Logger/MoaLoggerCallback.swift:15:65: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Http/MoaHttpImageDownloader.swift:23:25: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:151:25: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:163:30: error: use of undeclared type 'Error'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:248:42: error: use of undeclared type 'Error'
      private func handleErrorAsync(_ error: Error?, response: HTTPURLResponse?, isSimulated: Bool) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:248:60: error: use of undeclared type 'HTTPURLResponse'
      private func handleErrorAsync(_ error: Error?, response: HTTPURLResponse?, isSimulated: Bool) {
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:216:7: error: use of unresolved identifier 'DispatchQueue'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Moa.swift:256:7: error: use of unresolved identifier 'DispatchQueue'
    /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/Moa/Utils/MoaString.swift:12:19: error: type 'NSString' has no member 'CompareOptions'
    A shell task (/usr/bin/xcrun xcodebuild -project /Users/yuchen/Projects/zjsk/liuliang/ios/Carthage/Checkouts/moa/moa.xcodeproj -scheme moa -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65:
    ** BUILD FAILED **
    
    
    The following build commands failed:
        CompileSwift normal arm64
        CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
    (2 failures)
    
    
    opened by kuyoonjo 3
  • Failure when downloading .gif in 3.0

    Failure when downloading .gif in 3.0

    ii -

    First off, great work :)

    Noticed you added .gif support to auk 2.1.5. Unable to download .gif files. Pointing my podfile directly to the master branch on Auk & moa.

    Here's an example link that we're trying to download: http://circaoldhouses.com/wp-content/uploads/2016/04/7700-Highway-207-Anderson-AL-35610-3.gif

    Here's the error code from the failure in moa:

    Error Domain=MoaError Code=3 "Response content type is not an image type. Content type needs to be  'image/jpeg', 'image/pjpeg' or 'image/png'" UserInfo={NSLocalizedDescription=Response content type is not an image type. Content type needs to be  'image/jpeg', 'image/pjpeg' or 'image/png'}
    

    What other information can I provide to be helpful?

    Michael

    opened by mafellows 3
  • Unable to have simultaneous downloads/load from cache

    Unable to have simultaneous downloads/load from cache

    I'm trying to load multiple images using the same instance of moa, but the first image gets canceled, this happens even if it's cached

    I'm not loading onto a image view because I'm using SwiftUI and this is they way I found to make it work

    let moa = Moa()
    moa.onSuccess = { image in
                let img = Image(nsImage: image)
                callback(img)
                return image
            }
            moa.url = url   
    

    I also have these settings

    Moa.settings.cache.memoryCapacityBytes = 500 * 1024 * 1024
            Moa.settings.cache.diskCapacityBytes = 10000 * 1024 * 1024
            Moa.settings.cache.diskPath = "ImageCache"
            Moa.settings.cache.requestCachePolicy = .returnCacheDataElseLoad
            Moa.settings.maximumSimultaneousDownloads = 10
            Moa.settings.requestTimeoutSeconds = 20
            Moa.logger = MoaConsoleLogger // test logger
    
    • Library setup method: file, Swift Package Manager.
    • Version of the library. Example: 12.0.
    • Xcode version. Example: 12.1.
    • OS version. Example: macOS 11.0.1.
    opened by PedroCavaleiro 2
  • What cache policy is the best for this situation ?

    What cache policy is the best for this situation ?

    Hi, What cache policy is the best to use to save images in cache so the user will be able to see them even if he is not have internet connection ? and When the image link has changed from the server, then load the new image over the cached image ?

    I tested the Moa.settings.cache.requestCachePolicy = .ReturnCacheDataElseLoad but it seems it doesn't do this thing I want.

    opened by johncodeos 2
  • Animate Image after downloading

    Animate Image after downloading

    Hey guys, is there any way to animate an image after it downloads. More like a subtle opacity change.

    How can I do that?

    Thanks for the amazing library!

    opened by Perjan 1
  • Image never loads

    Image never loads

    @evgenyneu your library does not work for me. Unfortunate.. My downloads are getting cancelled all the time. What should I do?

    Here is my code:

    let moa = Moa()
    moa.onSuccess = { image in // image is loaded mediaMessage.image = image DispatchQueue.main.async(execute: { self.tableView.reloadData() }) return image } moa.url = sendedImageURL Console output:

    [moa] 2017-05-06 07:15:51.210 GET https://** [moa] 2017-05-06 07:15:51.212 Cancelled https://**

    If setting breakpoint debugger does not wanna go inside closures at all... Image never gets loaded..:(

    opened by yarodevuci 0
  • moa.MoaError.notAnImageContentTypeInResponseHttpHeader

    moa.MoaError.notAnImageContentTypeInResponseHttpHeader

    Getting this error while trying to load certain images ( some work, other don't ) moa.MoaError.notAnImageContentTypeInResponseHttpHeader Library setup method: CocoaPods. Version of the library: 11.0.1 Xcode version: 11.1 OS version. Example: iOS 13.0

    opened by hajjarjoseph 8
  • determining if image was loaded from cache

    determining if image was loaded from cache

    Hello, great work, really appreciate simplicity of this lib, but I found myself in a situation when I would like to determine if image was really downloaded or loaded from a cache - for example to show or not to show an animation, is there a simple way to determine that (maybe using duration field in MoaImage)?

    desired example:

    profileImage.moa.onSuccessAsync = {  image in
        if !image.loadedFromCache {
            UIView.animate(withDuration: 0.3, animations: {
                self.profileImage.layer.opacity = 1.0
            })
        }
       return image
    }
    
    opened by rjuzaszek 5
  • Question about caching

    Question about caching

    Thanks for sharing this lib!

    Does this lib cache images by default? Or must I change some settings in Moa?

    This might not belong here but does Moa clear the cache once it get full?

    I am used to Kingfisher where most of the stuff is configured out of the box, cache clear, cache time etc

    opened by kiwo12345 13
  • etag caching not working as expected

    etag caching not working as expected

    I have detected a issue with the cache behavior. From the server in the image response header I get following cache related fields:

    Cache-Control: public, max-age=30
    Etag: 0x8D3968523DB2C1F
    Last-Modified: Fri, 17 Jun 2016 07:58:16 GMT
    

    If I scrolling the tableView up and down the images getting cached or newly requested with the request header fields:

    If-Modified-Since: Mon, 30 May 2016 10:28:33 GMT
    If-None-Match :0x8D3968523DB2C1F
    

    In that case the response status code is 304 and the images are loaded from the cache. So fare so good. But when the scrolling frequency is getting higher the images are sometimes loaded again and again without the If-Modified-Since and If-None-Match header fields set.

    I using the standard cache configuration.

    opened by ThomasGrunewald 3
Owner
Evgenii Neumerzhitckii
🐋🦔🐢🐝wow
Evgenii Neumerzhitckii
A simple UIImageView extension for using initials as a profile image, written in swift

InitialsImageView An easy, helpful UIImageView extension that generates letter initials as a placeholder for user profile images, with a randomized ba

Tom Bachant 215 Dec 17, 2022
This simple cordova plugin will download picture from an URL and save to IOS Photo Gallery.

Photo Viewer This plugin is intended to download a picture from an URL into IOS Photo library.. How to Install Cordova: cordova plugin add https://git

Alwin jose 1 Oct 23, 2021
Download and decode progressive JPEGs on iOS.

Concorde This is a framework for downloading and decoding progressive JPEGs easily on iOS and OS X. It uses libjpeg-turbo as underlying JPEG implement

Contentful Labs 1.4k Dec 26, 2022
Download manager

Features Download manager Running in the background Loading multiple files You can cancel, pause, resume, reload Example UML Class Diagram General sch

Beslan Tularov 59 Dec 12, 2022
AsyncImage before iOS 15. Lightweight, pure SwiftUI Image view, that displays an image downloaded from URL, with auxiliary views and local cache.

URLImage URLImage is a SwiftUI view that displays an image downloaded from provided URL. URLImage manages downloading remote image and caching it loca

Dmytro Anokhin 1k Jan 4, 2023
AYImageKit is a Swift Library for Async Image Downloading, Show Name's Initials and Can View image in Separate Screen.

AYImageKit AYImageKit is a Swift Library for Async Image Downloading. Features Async Image Downloading. Can Show Text Initials. Can have Custom Styles

Adnan Yousaf 11 Jan 10, 2022
SwiftColorArt is a demo application that includes Swift files with all classes and extension necessary to create a font color schema matching to an image

SwiftColorArt SwiftColorArt is a demo application that includes Swift files with all classes and extension necessary to create a font color schema mat

Jan Gregor Triebel 264 Jan 4, 2023
An NSFW image detector for Swift built as an extension on UIImage.

Swift_NSFW_Detector An NSFW image detector for Swift built as an extension on UIImage. If you've ever allowed users to share images you are probably w

Chris Brown 5 Nov 27, 2022
Backport of SwiftUI.AsyncImage to iOS 14, macOS 11, tvOS 14 and watchOS 7 and earlier.

SBPAsyncImage Backport of SwiftUI.AsyncImage to iOS 14, macOS 11, tvOS 14 and watchOS 7 and earlier. AsyncImage is a view that asynchronously loads an

Yutaro Muta 48 Dec 16, 2022
A better way to operate QR Code in Swift, support iOS, macOS, watchOS and tvOS.

EFQRCode is a lightweight, pure-Swift library for generating stylized QRCode images with watermark or icon, and for recognizing QRCode from images, in

EFPrefix 4.3k Jan 2, 2023
Siri Shortcuts extension for calculating NN-based image hash.

NNHash Siri Shortcuts extension for calculating NN-based image hash. Based on nhcalc.

Yi Xie 3 Aug 9, 2021
An extension that gives UIImageView the ability to focus on faces within an image.

FaceAware Sometimes the aspect ratios of images we need to work with don't quite fit within the confines of our UIImageViews. In most cases we can use

Beau Nouvelle 3k Jan 3, 2023
Async image downloader with Mem&Disk cached as a UIImageView extension

HBWebImage Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation HBWebIm

haoboxuxu 1 Oct 22, 2022
Twitter Image Pipeline is a robust and performant image loading and caching framework for iOS clients

Twitter Image Pipeline (a.k.a. TIP) Background The Twitter Image Pipeline is a streamlined framework for fetching and storing images in an application

Twitter 1.8k Dec 17, 2022
A lightweight and fast image loader for iOS written in Swift.

ImageLoader ImageLoader is an instrument for asynchronous image loading written in Swift. It is a lightweight and fast image loader for iOS. Features

Hirohisa Kawasaki 293 Nov 24, 2022
A ninepatch image render framework for iOS and MacOS

NinePatchKit NinePatch image parser and render framework for iOS & macOS Multilingual translation Chinese README Main Features parse png's binary data

Theo 14 Sep 30, 2022
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component ?? v2.0.0-alpha now open!

Muukii 2.8k Jan 3, 2023
📷 A composable image editor using Core Image and Metal.

Brightroom - Composable image editor - building your own UI Classic Image Editor PhotosCrop Face detection Masking component ?? v2.0.0-alpha now open!

Muukii 2.8k Jan 2, 2023
A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image.

QRDecode A complete Mac App: drag an image file to the top section and the bottom section will show you the text of any QRCodes in the image. QRDecode

David Phillip Oster 2 Oct 28, 2022