Git Product home page Git Product logo

moa's Introduction

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.

moa's People

Contributors

evgenyneu avatar phimage avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

moa's Issues

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

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
}

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!

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.

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.

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

** 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)

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..:(

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.

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

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

Request to bump iOS deployment target for Xcode 14.X build

Hi,

FreeOTP iOS https://github.com/freeotp/freeotp-ios fails to build moa as a dependency with Xcode 14.3

ld: file not found: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/arc/libarclite_iphoneos.a
clang: error: linker command failed with exit code 1 (use -v to see invocation)

/Users/justinstephenson/github/freeotp-ios/Carthage/Checkouts/moa/moa.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET' is set to 8.0, but the range of supported deployment target versions is 11.0 to 16.4.99. (in target 'moa' from project 'moa')

Please refer to https://developer.apple.com/forums/thread/728021

[QUESTION] Manually invalidating cache

Is there any way (I've dug a little in the repository) to invalidate (flush) the both memory and disk cache from Moa to force re-download all the following requests even if they were already cached?

Thank you!

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.