{"id":1487,"url":"https://github.com/evgenyneu/moa","last_synced_at":"2025-04-05T17:07:35.738Z","repository":{"id":32141776,"uuid":"35714564","full_name":"evgenyneu/moa","owner":"evgenyneu","description":"An image download extension of the image view written in Swift for iOS, tvOS and macOS. ","archived":false,"fork":false,"pushed_at":"2022-01-09T22:06:09.000Z","size":10187,"stargazers_count":333,"open_issues_count":10,"forks_count":42,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-03-29T16:07:15.565Z","etag":null,"topics":["image","swift","uiimageview"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"aiogram/aiogram","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/evgenyneu.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-16T07:39:29.000Z","updated_at":"2024-10-29T16:19:58.000Z","dependencies_parsed_at":"2022-06-26T17:44:32.788Z","dependency_job_id":null,"html_url":"https://github.com/evgenyneu/moa","commit_stats":null,"previous_names":[],"tags_count":45,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2Fmoa","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2Fmoa/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2Fmoa/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/evgenyneu%2Fmoa/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/evgenyneu","download_url":"https://codeload.github.com/evgenyneu/moa/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247369952,"owners_count":20927928,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image","swift","uiimageview"],"created_at":"2024-01-05T20:15:47.599Z","updated_at":"2025-04-05T17:07:35.700Z","avatar_url":"https://github.com/evgenyneu.png","language":"Swift","funding_links":[],"categories":["Media","Libs","UI","Images [🔝](#readme)"],"sub_categories":["Image","Images","Other free courses"],"readme":"# Moa, an image downloader written in Swift for iOS, tvOS and macOS\n\n[![Carthage compatible](https://img.shields.io/badge/Carthage-compatible-4BC51D.svg?style=flat)](https://github.com/Carthage/Carthage)\n[![CocoaPods Version](https://img.shields.io/cocoapods/v/moa.svg?style=flat)](http://cocoadocs.org/docsets/moa)\n[![Swift Package Manager compatible](https://img.shields.io/badge/Swift%20Package%20Manager-compatible-brightgreen.svg)](https://github.com/apple/swift-package-manager)\n[![License](https://img.shields.io/cocoapods/l/moa.svg?style=flat)](http://cocoadocs.org/docsets/moa)\n[![Platform](https://img.shields.io/cocoapods/p/moa.svg?style=flat)](http://cocoadocs.org/docsets/moa)\n\nMoa 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.\n\n```Swift\nimageView.moa.url = \"https://bit.ly/moa_image\"\n```\n\n* Images are downloaded asynchronously.\n* Uses URLSession for networking and caching.\n* Allows to configure cache size and policy.\n* Can be used without an image view.\n* Provides closure properties for image manipulation and error handling.\n* Includes unit testing mode for faking network responses.\n* Contains logging capabilities for debugging network problems.\n\n\u003cimg src='https://raw.githubusercontent.com/evgenyneu/moa/master/Graphics/Hunting_Moa.jpg' alt='Moa hunting' width='400'\u003e\n\n\u003e \"Lost, like the Moa is lost\" - Maori proverb\n\n*'Hunting Moa' drawing by Joseph Smit (1836-1929). File source: [Wikimedia Commons](http://commons.wikimedia.org/wiki/File:Hunting_Moa.jpg).*\n\n\n\n## Setup\n\nThere are multiple ways you can add Moa to your Xcode project.\n\n#### Add source (iOS 7+)\n\nSimply add [MoaDistrib.swift](https://github.com/evgenyneu/moa/blob/master/Distrib/MoaDistrib.swift) file into your Xcode project.\n\n#### Setup with Carthage (iOS 8+)\n\nAlternatively, add `github \"evgenyneu/moa\" ~\u003e 12.0` to your Cartfile and run `carthage update`.\n\n#### Setup with CocoaPods (iOS 8+)\n\nIf you are using CocoaPods add this text to your Podfile and run `pod install`.\n\n```\nuse_frameworks!\ntarget 'Your target name'\npod 'moa', '~\u003e 12.0'\n```\n\n#### Setup with Swift Package Manager\n\n* In Xcode 11+ select *File \u003e Packages \u003e Add Package Dependency...*.\n* Enter this project's URL: https://github.com/evgenyneu/moa.git\n\n\n### Legacy Swift versions\n\nSetup a [previous version](https://github.com/evgenyneu/moa/wiki/Legacy-Swift-versions) of the library if you use an older version of Swift.\n\n\n## Usage\n\n1. Add `import moa` to your source code (unless you used the file setup method).\n\n1. 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.\n\n1. Set `moa.url` property of the image view to start asynchronous image download. The image will be automatically displayed when download is finished.\n\n```Swift\nimageView.moa.url = \"https://bit.ly/moa_image\"\n```\n\n## Loading images from insecure HTTP hosts\n\nIf your image URLs are not *https* you will need to [add an exception](http://evgenii.com/blog/loading-data-from-non-secure-hosts-in-ios9-with-nsurlsession/) to the **Info.plist** file. This will allow the App Transport Security to load the images from insecure HTTP hosts.\n\n## Canceling download\n\nOngoing image download for the image view is automatically canceled when:\n\n1. Image view is deallocated.\n2. New image download is started: `imageView.moa.url = ...`.\n\nCall `imageView.moa.cancel()` to manually cancel the download.\n\n\n## Supply an error image\n\nYou can supply an error image that will be used if an error occurs during image download.\n\n```Swift\nimageView.moa.errorImage = UIImage(named: \"ImageNotFound.jpg\")\nimageView.moa.url = \"https://bit.ly/moa_image\"\n```\n\nAlternatively, one can supply a global error image that will be used for all failed image downloads.\n\n```Swift\nMoa.errorImage = UIImage(named: \"ImageNotFound.jpg\")\n```\n\n## Show a placeholder image\n\nHere 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.\n\n```Swift\nimageView.image = placeholderImage\nimageView.moa.url = \"https://bit.ly/moa_image\"\n```\n\n## Advanced features\n\n\n### Supplying completion closure\n\nAssign a closure that will be called when image is received.\n\n```Swift\nimageView.moa.onSuccess = { image in\n  return image\n}\n\nimageView.moa.url = \"https://bit.ly/moa_image\"\n```\n\n* The closure will be called after download finishes and before the image is assigned to the image view.\n* This is a good place to manipulate the image before it is shown.\n* 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.\n* The closure as called in the *main queue*. Use `onSuccessAsync` property instead if you need to do time consuming operations.\n* When `errorImage` is supplied and an error occurs the success closures are called.\n\n\n### Supplying error closure\n\n```Swift\nimageView.moa.onError = { error, response in\n  // Handle error\n}\n\nimageView.moa.url = \"https://bit.ly/moa_image\"\n```\n\n* The closure is called in the *main queue* if image download fails. Use `onErrorAsync` property instead if you need to do time consuming operations.\n* See the \"logging\" section if you need to find out the type of the error.\n\n### Download an image without an image view\n\nAn instance of `Moa` class can also be used without an image view. A strong reference to `Moa` instance needs to be kept.\n\n```Swift\nlet moa = Moa()\nmoa.onSuccess = { image in\n  // image is loaded\n  return image\n}\nmoa.url = \"https://bit.ly/moa_image\"\n```\n\n### Clearing HTTP session\n\nThe following method calls `finishTasksAndInvalidate` on the current URLSession object. A new session object will be created for future image downloads.\n\n```Swift\nMoaHttpSession.clearSession()\n```\n\nYou may never need to call this method in your app. I needed to call it periodically to workaround a strange [URLSession bug](http://stackoverflow.com/questions/32493339/sending-400-http-requests-result-in-the-request-timed-out-errors-with-nsurlse) which you may not encounter.\n\n## Image caching\n\nUse the `Moa.settings.cache` to change caching settings. For more information please refer to the [moa image caching manual](https://github.com/evgenyneu/moa/wiki/Moa-image-caching).\n\n```Swift\n// By default images are cached according to their response HTTP headers.\nMoa.settings.cache.requestCachePolicy = .useProtocolCachePolicy\n\n// Always cache images locally regardless of their response HTTP headers\nMoa.settings.cache.requestCachePolicy = .returnCacheDataElseLoad\n\n// Change the name of the cache directory. Useful for sharing cache with the rest of the app.\nMoa.settings.cache.diskPath = \"MyAppSharedCache\"\n```\n\n## Settings\n\nUse `Moa.settings` property to change moa image download settings.\n\n```Swift\n\n// Set the maximum number of simultaneous image downloads. Default: 4.\nMoa.settings.maximumSimultaneousDownloads = 5\n\n// Change timeout for image requests. Default: 10.\nMoa.settings.requestTimeoutSeconds = 20\n```\n\n## Logging\n\nYou 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](https://github.com/evgenyneu/moa/wiki/Logging-with-Moa) for more information.\n\n```Swift\n// Log to console\nMoa.logger = MoaConsoleLogger\n\n// Load an image\nimageView.moa.url = \"https://bit.ly/moa_image\"\n\n// Attempt to load a missing image\nimageView.moa.url = \"https://bit.ly/moa_image_missing.jpg\"\n```\n\n\u003cimg src='https://raw.githubusercontent.com/evgenyneu/moa/master/Graphics/screenshots/logging_to_console_moa_swift_2.png' alt='Logging to console with moa' width='541'\u003e\n\n\n\n\n## Unit testing\n\nSometimes 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](https://github.com/evgenyneu/moa/wiki/Unit-testing-with-Moa) for more information.\n\n```Swift\n// Autorespond with the given image to all image requests\nMoaSimulator.autorespondWithImage(\"www.site.com\", image: UIImage(named: \"35px.jpg\")!)\n```\n\n## Demo app\n\nThe demo iOS app shows how to load images in a collection view with Moa.\n\n\u003cimg src='https://raw.githubusercontent.com/evgenyneu/moa/master/Graphics/demo_app_screenshot.png'\nalt='Moa image downloader demo iOS app' width='250'\u003e\n\n\n\n## Alternative solutions\n\nHere is the list of other image download libraries for Swift.\n\n* [cbot/Vincent](https://github.com/cbot/Vincent)\n* [daltoniam/Skeets](https://github.com/daltoniam/Skeets)\n* [Haneke/HanekeSwift](https://github.com/Haneke/HanekeSwift)\n* [hirohisa/ImageLoaderSwift](https://github.com/hirohisa/ImageLoaderSwift)\n* [natelyman/SwiftImageLoader](https://github.com/natelyman/SwiftImageLoader)\n* [onevcat/Kingfisher](https://github.com/onevcat/Kingfisher)\n* [zalando/MapleBacon](https://github.com/zalando/MapleBacon)\n\n## Credits\n\n* Demo app includes other drawings by Joseph Smit. Source: [Wikimedia Commons](http://commons.wikimedia.org/w/index.php?title=Category:Joseph_Smit\u0026fileuntil=FuligulaNationiSmit.jpg#mw-category-media).\n\n* macOS support is added by [phimage](https://github.com/phimage).\n\n\n## License\n\nMoa is released under the [MIT License](LICENSE).\n\n## Feedback is welcome\n\nIf you notice any issue, got stuck or just want to chat feel free to create an issue. I will be happy to help you.\n\n## •ᴥ•\n\nThis project is dedicated to [the moa](https://en.wikipedia.org/wiki/Moa), species of flightless birds that lived in New Zealand and became extinct in 15th century.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgenyneu%2Fmoa","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fevgenyneu%2Fmoa","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fevgenyneu%2Fmoa/lists"}