Hi, I'm Alex (short for Alexander).
- Blog: kean.blog
- Built Nuke, Pulse, and other popular frameworks and tools
- Developed the initial CreateAPI version which is now maintained by @cookpad
Contacts
- Mastodon: @[email protected]
Image loading system
Home Page: https://kean.blog/nuke
License: MIT License
Hi, I'm Alex (short for Alexander).
Contacts
I'm trying to wrap the Nuke functionality in my own UIImageView subclass. Due to ImageLoadingViewExtensions.swift
, I am unable to override the the func nk_imageTask(task: ImageTask, didFinishWithResponse response: ImageResponse, options: ImageViewLoadingOptions?)
where I want to place some custom logic.
Is there any way this can be changed to allow me to do that?
Let's say I have a table view with 1000 cells where each cell downloads one image in willDisplayCell
:
cell.image.nk_setImageWith(...)
and each row cancels image in didEndDisplayingCell
:
cell.image.nk_cancelLoading()
It works pretty well except the case when I scroll very fast (as fast as I can).
Why do I say nk_cancelLoading
not working "thoroughly"?
So for the not-working case, I guess somehow, the network requests still jammed in the lower level? Or why would it take so long to show the images. If previous image requests are all cancelled without blocking current requests, the images should shown within one or two seconds as usual.
Based on #46
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>arm64</string>
</array>
More info https://forums.developer.apple.com/message/85053, Alamofire/Alamofire#916
I get a crash when running my app, which uses Nuke, on iOS 8. The app crashes immediately, before any of my code is executed.
dyld: Symbol not found: _NSURLSessionTaskPriorityDefault
Referenced from: /Users/[...]/Build/Products/Debug-iphonesimulator/Nuke.framework/Nuke
Expected in: /Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 8.2.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation
in /Users/[...]/Build/Products/Debug-iphonesimulator/Nuke.framework/Nuke
Looks like building Nuke through Carthage using Xcode 7 fails. Here's the error:
*** Building scheme "Nuke" in Nuke.xcodeproj
** BUILD FAILED **
The following build commands failed:
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(1 failure)
<unknown>:0: error: no such file or directory: '/Users/marlowcharite/Developer/iOS/projects/gryphon media/dopehood/Carthage/Checkouts/Nuke/Nuke/Source/Core/ImageTaskQueue.swift'
A shell task failed with exit code 65:
** BUILD FAILED **
The following build commands failed:
CompileSwiftSources normal x86_64 com.apple.xcode.tools.swift.compiler
(1 failure)
Trying to get Nuke via Carthage v0.14.0 and the following error is produced:
$ carthage update --platform iOS
*** Fetching Nuke
*** Checking out Nuke at "3.0.0"
*** xcodebuild output can be found in /var/folders/dn/4s21l4h54h701_822vq5m3_m0000gn/T/carthage-xcodebuild.krTNud.log
*** Building scheme "Nuke iOS" in Nuke.xcworkspace
** BUILD FAILED **
The following build commands failed:
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageProcessor.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageDecoder.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageManager.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageDiskCache.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageLoader.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageDataLoader.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/Nuke.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(9 failures)
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:61: error: missing argument for parameter 'selector' in call
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected expression in list of expressions
/Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift:59:78: error: expected ',' separator
A shell task failed with exit code 65:
** BUILD FAILED **
The following build commands failed:
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageProcessor.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageMemoryCache.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageDecoder.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageManager.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageDiskCache.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageLoader.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/ImageDataLoader.swift
CompileSwift normal arm64 /Users/test/Carthage/Checkouts/Nuke/Sources/Nuke.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler
(9 failures)
AFNetworking is required by other pods. So it would be nice to keep this function as well.
One of the advantages of SDWebImage (an objective-c alternative) is that it has support for the webp image format.
It would be a great addition to support this in nuke.
Investigate when priorities might be useful
Investigate NSURLSessionTask priority and HTTP/2 priorities
Investigate how Carthage manages dependencies and add Carthage support to Nuke/GIF and Nuke/Alamofire subspecs
Hi, can you help me put some placeholder image before the image is downloaded?
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '/Users/accel_imac/Library/Developer/CoreSimulator/Devices/6631CF6C-F944-454E-B3F7-FD6AB2A672AC/data/Containers/Data/Application/2E85B42A-8B80-4386-A68F-B788AB572CF4/Library/Caches/org.cocoapods.demo.Nuke-Example/com.github.kean.nuke-image-cache: An -observeValueForKeyPath:ofObject:change:context: message was received but not handled.
Key path: fractionCompleted
Observed object: <NSProgress: 0x7fc3fbd1c6e0> : Parent: 0x0 / Fraction completed: 1.0000 / Completed: 31038 of 31038
Change: {
kind = 1;
new = 1;
}
Context: 0x0'
*** First throw call stack:
(
0 CoreFoundation 0x00000001005a5f65 exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010223adeb objc_exception_throw + 48
2 CoreFoundation 0x00000001005a5e9d +[NSException raise:format:] + 205
3 Foundation 0x0000000100a09e0a -[NSObject(NSKeyValueObserving) observeValueForKeyPath:ofObject:change:context:] + 73
4 Foundation 0x0000000100936b30 NSKeyValueNotifyObserver + 347
5 Foundation 0x0000000100935d5b NSKeyValueDidChange + 466
6 Foundation 0x000000010093a560 -[NSObject(NSKeyValueObserverNotification) didChangeValueForKey:] + 118
7 CoreFoundation 0x00000001004d4ad2 __53-[__NSArrayM enumerateObjectsWithOptions:usingBlock:]_block_invoke + 114
8 CoreFoundation 0x00000001004d424f -[__NSArrayM enumerateObjectsWithOptions:usingBlock:] + 335
9 Foundation 0x0000000100b2dd34 -[NSProgress _setValueForKeys:settingBlock:] + 722
10 Foundation 0x0000000100b2e41e -[NSProgress setCompletedUnitCount:] + 138
11 Alamofire 0x00000001002b2db0 TFCC9Alamofire7Request16DataTaskDelegate10URLSessionfS1_FTCSo12NSURLSession8dataTaskCSo20NSURLSessionDataTask14didReceiveDataCSo6NSData_T + 1360
12 Alamofire 0x000000010028ea1a TFCC9Alamofire7Manager15SessionDelegate10URLSessionfS1_FTCSo12NSURLSession8dataTaskCSo20NSURLSessionDataTask14didReceiveDataCSo6NSData_T + 586
13 Alamofire 0x000000010028eac4 TToFCC9Alamofire7Manager15SessionDelegate10URLSessionfS1_FTCSo12NSURLSession8dataTaskCSo20NSURLSessionDataTask14didReceiveDataCSo6NSData_T + 100
14 CFNetwork 0x0000000102d85f6d __67-[NSURLSession delegate_dataTask:didReceiveData:completionHandler:]_block_invoke220 + 38
15 Foundation 0x0000000100a16873 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 7
16 Foundation 0x00000001009525d5 -[NSBlockOperation main] + 101
17 Foundation 0x0000000100935556 -[__NSOperationInternal _start:] + 646
18 Foundation 0x0000000100935167 __NSOQSchedule_f + 194
19 libdispatch.dylib 0x0000000103a7c49b _dispatch_client_callout + 8
20 libdispatch.dylib 0x0000000103a62988 _dispatch_queue_drain + 2215
21 libdispatch.dylib 0x0000000103a61ea9 _dispatch_queue_invoke + 601
22 libdispatch.dylib 0x0000000103a64af2 _dispatch_root_queue_drain + 1420
23 libdispatch.dylib 0x0000000103a64561 _dispatch_worker_thread3 + 111
24 libsystem_pthread.dylib 0x0000000103dc4a9d _pthread_wqthread + 729
25 libsystem_pthread.dylib 0x0000000103dc23dd start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Nuke already has a bunch of units tests but needs some more
use_frameworks!
platform :ios, "8.0"
pod "Nuke"
pod "Nuke-Alamofire-Plugin"
pud????? "Nuke-AnimatedImage-Plugin"
Also can you have clear instructions on installing it, i have errors, unable to find framework..
i just followed the instruction.. i just tried your framework on your sample project, by doing pod try "Nuke"..
thanks..!
Xcode Version: 7
github "kean/Nuke"
$ carthage update --platform iOS
xcodebuild: error: The workspace named "Nuke" does not contain a scheme named "Nuke Demo". The "-list" option can be used to find the names of the schemes in the workspace.
I've tested this in a fresh project and still am getting the same results! Cocoapods seems to work OK - ideally would want to stay clear of this route though
I believe this might be happening due to something similar to: Carthage/Carthage#586
public enum PHImageRequestOptionsResizeMode : Int {
case None // no resize
case Fast // use targetSize as a hint for optimal decoding when the source image is a compressed format (i.e. subsampling), the delivered image may be larger than targetSize
case Exact // same as above but also guarantees the delivered image is exactly targetSize (must be set when a normalizedCropRect is specified)
}
Investigate whether it's possible to take advantage of fast scaling by a certain scale factors.
Investigate NSURLSessionDownloadTask and optional public func URLSession(session: NSURLSession, dataTask: NSURLSessionDataTask, didBecomeDownloadTask downloadTask: NSURLSessionDownloadTask)
I'm having trouble getting Nuke to detect images that's been updated on the server - the cached image is used instead. It seems like Nuke doesn't check if the file has been updated on the server by default? Is there a way to force this functionality?
Hi.. i have tried your awesome Framework, its probably better than haneke i think, but i have the same problem with haneke.. The cache seems on memory level only and its like a volatile cache..
Can you provide some snippet of how to save cache files to disk like an NSData.
Seems confuse with this codes:
let dataLoader: ImageDataLoading = <#dataLoader#>
let decoder: ImageDecoding = <#decoder#>
let cache: ImageMemoryCaching = <#cache#>
let configuration = ImageManagerConfiguration(dataLoader: dataLoader, decoder: decoder, cache: cache)
ImageManager.shared = ImageManager(configuration: configuration)
thanks!
I believe that carthage support for this will help you get more users. A lot of devs, like me, have a project that does not allow for the use of cocoapods.
nk_setImageWithURL is not working with tvOS UIImageView. The only method that actually shows up on it is the nk_targetSize(). I think it has to do with the where clause on the extension, but am not sure.
Add essential documentation only where it's really necessary
Summary:
ImageDiskCaching
protocol and use it in ImageLoader
classMotivation:
NSURLCache might not be enough for some users, especially performance-wise. Nuke should provide an easy way to integrate custom on-disk caching libraries (like DFCache).
I've found the same issue that SDWebImage had. When trying to show image like that http://7xngft.com2.z0.glb.qiniucdn.com/thn.jpg I've got an error message:
: CGBitmapContextCreate: unsupported parameter combination: set CGBITMAP_CONTEXT_LOG_ERRORS environmental variable to see the details
After setting CGBITMAP_CONTEXT_LOG_ERRORS environment variable, I got more detailed info:
:
CGBitmapContextCreate: unsupported parameter combination:
16 integer bits/component;
64 bits/pixel;
RGB color space model; kCGImageAlphaLast;
1760 bytes/row.
Valid parameters for RGB color space model are:
16 bits per pixel, 5 bits per component, kCGImageAlphaNoneSkipFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaNoneSkipLast
32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedFirst
32 bits per pixel, 8 bits per component, kCGImageAlphaPremultipliedLast
64 bits per pixel, 16 bits per component, kCGImageAlphaPremultipliedLast
64 bits per pixel, 16 bits per component, kCGImageAlphaNoneSkipLast
128 bits per pixel, 32 bits per component, kCGImageAlphaNoneSkipLast |kCGBitmapFloatComponents
128 bits per pixel, 32 bits per component, kCGImageAlphaPremultipliedLast |kCGBitmapFloatComponents
See Quartz 2D Programming Guide (available online) for more information.
Environment: iOS 9.0 simulator, Xcode 7.1.
With the following command:
./xctool -workspace <workspace> -scheme <scheme> -sdk iphonesimulator test
I am getting this:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 Nuke.Nuke 0x004126ac _TFC4Nuke16ImageMemoryCacheCfMS0_FT_S0_ + 588
1 Nuke.Nuke 0x003e557a _TIFV4Nuke25ImageManagerConfigurationcFMS0_FT10dataLoaderPS_16ImageDataLoading_7decoderPS_13ImageDecoding_5cacheGSqPS_18ImageMemoryCaching___S0_A1_ + 42
2 Nuke.Nuke 0x003f1bd4 globalinit_33_26AEE105B8E103C743A4428E83DD33A7_func0 + 100
3 libdispatch.dylib 0x032656fd _dispatch_client_callout + 14
4 libdispatch.dylib 0x032514d5 dispatch_once_f + 83
5 libswiftCore.dylib 0x02e26fda swift_once + 42
6 Nuke.Nuke 0x003f1c64 _TZFC4Nuke12ImageManager6sharedfMS0_FT_PS_13ImageManaging_ + 68
7 Nuke.Nuke 0x0040c27d _TF4Nuke21startPreheatingImagesFGSaVS_12ImageRequest_T_ + 29
Inside Xcode I was able to reproduce the crash very few times, while on Xctool always crashes. On Xcode the breakpoint hit here:
Real quick one here: looks as though targetSize can only be used to scale images down, is that correct?
I'm getting an error after submitting a tvos app to app store: Invalid Executable - The executable 'Lumbar.app/Frameworks/Nuke.framework/Nuke' does not contain bitcode.
Based on this issue (Carthage/Carthage#535), it seems that Nuke would need to enable bit code.
As discussed @kean, ideally, one would be able to flag a ImageRequest
to not be decoded. So after downloading the image, the corresponding blob of NSData
would be kept inside the NSURLCache
, but the decoding and posterior caching inside the NSCache
would be bypassed.
Investigate when it might be useful
Investigate NSURLSessionTask pause
I am trying to update the cached image for specific request when updating an image. My images are hosted on S3 and when the user updates their profile picture, there are 3 sizes that are uploaded to s3 and then I want to update the cache for these. This is the code that I am using
let request = ImageRequest(URL: url)
let cachedResponse = ImageCachedResponse(image: image, userInfo: nil)
ImageManager.shared.setResponse(cachedResponse, forRequest: request)
This appears to update it, but when I quit the app and reload it, the old image is appearing. I have verified that the image is updated on s3 when you hit the url.
Any thoughts? Am I just going about this wrong?
Investigate how memory management works on watchOS
NSProgress is an abomination
I download the images in the table view cells via Nuke as:
imageView.nk_setImageWith(imageURL)
the images are in red when the Simulator has Color Blended Layers
checked. How to make them green? (It will help the scrolling performance.)
PS. Earlier I use HanekeSwift, these images are in green by default. But with Nuke, they become all red.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.