Browse Source

Merge pull request #2224 from onevcat/doc/view-extension

Update doc for view extension methods
Wei Wang 1 year ago
parent
commit
3fa972af8e

+ 2 - 2
Sources/Documentation.docc/Documentation.md

@@ -39,9 +39,9 @@ downloading again.
 
 ### Loading Images in Simple Way
 
-- <doc:UsingViewExtensions>
-- ``KingfisherManager``
+- ``KingfisherCompatible``
 - ``KingfisherWrapper``
+- ``KingfisherManager``
 - ``Source``
 
 ### Loading Options

+ 0 - 11
Sources/Documentation.docc/UsingViewExtensions.md

@@ -1,11 +0,0 @@
-# Using View Extensions
-
-<!--@START_MENU_TOKEN@-->Summary<!--@END_MENU_TOKEN@-->
-
-## Overview
-
-<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->
-
-### Section header
-
-<!--@START_MENU_TOKEN@-->Text<!--@END_MENU_TOKEN@-->

+ 12 - 0
Sources/General/Kingfisher.swift

@@ -64,6 +64,18 @@ public struct KingfisherWrapper<Base> {
 
 /// Represents an object type that is compatible with Kingfisher. You can use ``kf`` property to get a
 /// value in the namespace of Kingfisher.
+///
+/// In Kingfisher, most of related classes that contains an image (such as `UIImage`, `UIButton`, `NSImageView` and
+/// more) conform to this protocol, and provides the helper methods for setting an image easily. You can access the `kf`
+/// property and call its `setImage` method with a certain URL:
+///
+/// ```swift
+/// let imageView: UIImageView
+/// let url = URL(string: "https://example.com/image.jpg")
+/// imageView.kf.setImage(with: url)
+/// ```
+///
+/// For more about basic usage of Kingfisher, check the <doc:CommonTasks> documentation.
 public protocol KingfisherCompatible: AnyObject { }
 
 /// Represents a value type that is compatible with Kingfisher. You can use ``kf`` property to get a

+ 7 - 3
Tests/KingfisherTests/ImageExtensionTests.swift

@@ -331,9 +331,13 @@ class ImageExtensionTests: XCTestCase {
 
     func testDownsamplingWithEdgeCaseSize() {
 
-        // Zero size would fail downsampling.
-        let nilImage = KingfisherWrapper<KFCrossPlatformImage>.downsampledImage(data: testImageData, to: .zero, scale: 1)
-        XCTAssertNil(nilImage)
+        // Zero size would fail downsampling before iOS 17.4.
+        let result = KingfisherWrapper<KFCrossPlatformImage>.downsampledImage(data: testImageData, to: .zero, scale: 1)
+        if #available(iOS 17.4, macOS 14.4, tvOS 17.4, *) {
+            XCTAssertEqual(result?.size, CGSize(width: 64, height: 64))
+        } else {
+            XCTAssertNil(result)
+        }
 
         let largerSize = CGSize(width: 100, height: 100)
         let largerImage = KingfisherWrapper<KFCrossPlatformImage>.downsampledImage(data: testImageData, to: largerSize, scale: 1)