Skip to content

Commit

Permalink
Add visionOS Support (#469)
Browse files Browse the repository at this point in the history
* visionOS support.

* Fix os warnings.

* Package.resolved v1.

* Update visionOS scheme.

* Update formatting.
  • Loading branch information
jshier authored Sep 13, 2023
1 parent 9d73feb commit 9080799
Show file tree
Hide file tree
Showing 26 changed files with 711 additions and 140 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ jobs:
name: "Test Old iOS"
runs-on: firebreak
env:
DEVELOPER_DIR: "/Applications/Xcode_14.3.app/Contents/Developer"
DEVELOPER_DIR: "/Applications/Xcode_14.3.1.app/Contents/Developer"
timeout-minutes: 10
strategy:
fail-fast: false
Expand Down Expand Up @@ -157,10 +157,10 @@ jobs:
name: "iOS 17.0"
testPlan: "iOS"
scheme: "AlamofireImage iOS"
# - destination: "OS=1.0,name=Apple Vision Pro"
# name: "visionOS 1.0"
# testPlan: "visionOS"
# scheme: "Alamofire visionOS"
- destination: "OS=1.0,name=Apple Vision Pro"
name: "visionOS 1.0"
testPlan: "visionOS"
scheme: "AlamofireImage visionOS"
steps:
- uses: actions/checkout@v3
- name: Install Firewalk
Expand All @@ -173,7 +173,7 @@ jobs:
name: Test Old tvOS
runs-on: firebreak
env:
DEVELOPER_DIR: /Applications/Xcode_14.3.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.3.1.app/Contents/Developer
timeout-minutes: 10
strategy:
fail-fast: false
Expand Down Expand Up @@ -203,7 +203,7 @@ jobs:
name: Test watchOS
runs-on: firebreak
env:
DEVELOPER_DIR: /Applications/Xcode_14.3.app/Contents/Developer
DEVELOPER_DIR: /Applications/Xcode_14.3.1.app/Contents/Developer
timeout-minutes: 10
strategy:
fail-fast: false
Expand Down
1 change: 0 additions & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

# format options

--closingparen same-line
--commas inline
--comments indent
--decimalgrouping 3,5
Expand Down
2 changes: 1 addition & 1 deletion AlamofireImage.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ Pod::Spec.new do |s|
s.tvos.deployment_target = '10.0'
s.watchos.deployment_target = '3.0'

s.dependency 'Alamofire', '~> 5.7'
s.dependency 'Alamofire', '~> 5.8'
end
592 changes: 534 additions & 58 deletions AlamofireImage.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1500"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "316A6C3B2A83DC1900311D98"
BuildableName = "AlamofireImage.framework"
BlueprintName = "AlamofireImage visionOS"
ReferencedContainer = "container:AlamofireImage.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:Tests/Test Plans/visionOS.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "316A6C3B2A83DC1900311D98"
BuildableName = "AlamofireImage.framework"
BlueprintName = "AlamofireImage visionOS"
ReferencedContainer = "container:AlamofireImage.xcodeproj">
</BuildableReference>
</MacroExpansion>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Alamofire/Alamofire" ~> 5.7
github "Alamofire/Alamofire" ~> 5.8
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "Alamofire/Alamofire" "5.7.1"
github "Alamofire/Alamofire" "5.8.0"
2 changes: 1 addition & 1 deletion Example/Source/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import Foundation
import UIKit

@UIApplicationMain
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
#if swift(>=4.2)
Expand Down
18 changes: 9 additions & 9 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"object": {
"pins": [
"object" : {
"pins" : [
{
"package": "Alamofire",
"repositoryURL": "https://github.com/Alamofire/Alamofire.git",
"state": {
"branch": null,
"revision" : "bc268c28fb170f494de9e9927c371b8342979ece",
"version" : "5.7.1"
"package" : "Alamofire",
"repositoryURL" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"branch" : null,
"revision" : "b2fa556e4e48cbf06cf8c63def138c98f4b811fa",
"version" : "5.8.0"
}
}
]
},
"version": 1
"version" : 1
}
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let package = Package(name: "AlamofireImage",
.watchOS(.v4)],
products: [.library(name: "AlamofireImage", targets: ["AlamofireImage"])],
dependencies: [.package(url: "https://github.com/Alamofire/Alamofire.git",
from: "5.7.0")],
from: "5.8.0")],
targets: [.target(name: "AlamofireImage",
dependencies: ["Alamofire"],
path: "Source",
Expand Down
21 changes: 10 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ AlamofireImage is an image component library for Alamofire.
- [x] Authentication with URLCredential
- [x] UIImageView Async Remote Downloads with Placeholders
- [x] UIImageView Filters and Transitions
- [x] Comprehensive Test Coverage
- [x] Comprehensive Test Coverage
- [x] [Complete Documentation](https://alamofire.github.io/AlamofireImage/)

## Requirements

- iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+
- Xcode 11+
- Swift 5.1+
- iOS 10.0+ / macOS 10.12+ / tvOS 10.0+ / watchOS 3.0+ / vision OS 1.0+
- Xcode 13+
- Swift 5.5+

## Migration Guides

Expand All @@ -36,14 +36,14 @@ AlamofireImage is an image component library for Alamofire.

## Dependencies

- [Alamofire 5.1+](https://github.com/Alamofire/Alamofire)
- [Alamofire 5.8+](https://github.com/Alamofire/Alamofire)

## Communication

- If you need to **find or understand an API**, check [our documentation](https://alamofire.github.io/AlamofireImage/).
- If you need **help with an AlamofireImage feature**, use [our forum on swift.org](https://forums.swift.org/c/related-projects/alamofire).
- If you'd like to **discuss AlamofireImage best practices**, use [our forum on swift.org](https://forums.swift.org/c/related-projects/alamofire).
- If you'd like to **discuss a feature request**, use [our forum on swift.org](https://forums.swift.org/c/related-projects/alamofire).
- If you'd like to **discuss a feature request**, use [our forum on swift.org](https://forums.swift.org/c/related-projects/alamofire).
- If you **found a bug**, open an issue and follow the guide. The more detail the better!
- If you **want to contribute**, submit a pull request.

Expand Down Expand Up @@ -97,19 +97,19 @@ $ git submodule add https://github.com/Alamofire/AlamofireImage.git

- Open the new `AlamofireImage` folder, and drag the `AlamofireImage.xcodeproj` into the Project Navigator of your application's Xcode project.

> It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.
> It should appear nested underneath your application's blue project icon. Whether it is above or below all the other Xcode groups does not matter.
- Select the `AlamofireImage.xcodeproj` in the Project Navigator and verify the deployment target matches that of your application target.
- Next, select your application project in the Project Navigator (blue project icon) to navigate to the target configuration window and select the application target under the "Targets" heading in the sidebar.
- In the tab bar at the top of that window, open the "General" panel.
- Click on the `+` button under the "Embedded Binaries" section.
- You will see two different `AlamofireImage.xcodeproj` folders each with two different versions of the `AlamofireImage.framework` nested inside a `Products` folder.

> It does not matter which `Products` folder you choose from, but it does matter whether you choose the top or bottom `AlamofireImage.framework`.
> It does not matter which `Products` folder you choose from, but it does matter whether you choose the top or bottom `AlamofireImage.framework`.
- Select the top `AlamofireImage.framework` for iOS and the bottom one for OS X.

> You can verify which one you selected by inspecting the build log for your project. The build target for `AlamofireImage` will be listed as either `AlamofireImage iOS`, `AlamofireImage macOS`, `AlamofireImage tvOS` or `AlamofireImage watchOS`.
> You can verify which one you selected by inspecting the build log for your project. The build target for `AlamofireImage` will be listed as either `AlamofireImage iOS`, `AlamofireImage macOS`, `AlamofireImage tvOS` or `AlamofireImage watchOS`.
- And that's it!

Expand Down Expand Up @@ -140,7 +140,6 @@ AF.request("https://httpbin.org/image/png").responseImage { response in

The AlamofireImage response image serializers support a wide range of image types including:


- `image/png`
- `image/jpeg`
- `image/tiff`
Expand Down Expand Up @@ -434,7 +433,7 @@ Determining the ideal the in-memory and on-disk capacity limits of the `URLCache

> If you do not use image filters, it is advised to set the memory capacity of the `URLCache` to zero. Otherwise, you will be storing the original image data in both the URLCache's in-memory store as well as the AlamofireImage in-memory store.
#### Duplicate Downloads
#### Duplicate Downloads

Sometimes application logic can end up attempting to download an image more than once before the initial download request is complete. Most often, this results in the image being downloaded more than once. AlamofireImage handles this case elegantly by merging the duplicate downloads. The image will only be downloaded once, yet both completion handlers will be called.

Expand Down
2 changes: 1 addition & 1 deletion Source/Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import Foundation

#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || (swift(>=5.9) && os(visionOS))
import UIKit
public typealias Image = UIImage
#elseif os(macOS)
Expand Down
6 changes: 3 additions & 3 deletions Source/ImageCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import Alamofire
import Foundation

#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || (swift(>=5.9) && os(visionOS))
import UIKit
#elseif os(macOS)
import Cocoa
Expand Down Expand Up @@ -81,7 +81,7 @@ open class AutoPurgingImageCache: ImageRequestCache {
lastAccessDate = Date()

totalBytes = {
#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || (swift(>=5.9) && os(visionOS))
let size = CGSize(width: image.size.width * image.scale, height: image.size.height * image.scale)
#elseif os(macOS)
let size = CGSize(width: image.size.width, height: image.size.height)
Expand Down Expand Up @@ -148,7 +148,7 @@ open class AutoPurgingImageCache: ImageRequestCache {
return DispatchQueue(label: name, attributes: .concurrent)
}()

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || (swift(>=5.9) && os(visionOS))
let notification = UIApplication.didReceiveMemoryWarningNotification

NotificationCenter.default.addObserver(self,
Expand Down
2 changes: 1 addition & 1 deletion Source/ImageDownloader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import Alamofire
import Foundation

#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || (swift(>=5.9) && os(visionOS))
import UIKit
#elseif os(macOS)
import Cocoa
Expand Down
6 changes: 3 additions & 3 deletions Source/ImageFilter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

import Foundation

#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || (swift(>=5.9) && os(visionOS))
import UIKit
#elseif os(macOS)
import Cocoa
Expand Down Expand Up @@ -150,7 +150,7 @@ public struct DynamicCompositeImageFilter: CompositeImageFilter {
}
}

#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || (swift(>=5.9) && os(visionOS))

// MARK: - Single Pass Image Filters (iOS, tvOS and watchOS only) -

Expand Down Expand Up @@ -284,7 +284,7 @@ public struct CircleFilter: ImageFilter {

// MARK: -

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || (swift(>=5.9) && os(visionOS))

/// The `CoreImageFilter` protocol defines `parameters`, `filterName` properties used by CoreImage.
public protocol CoreImageFilter: ImageFilter {
Expand Down
12 changes: 7 additions & 5 deletions Source/Request+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import Alamofire
import Foundation

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || (swift(>=5.9) && os(visionOS))
import UIKit
#elseif os(watchOS)
import UIKit
Expand Down Expand Up @@ -63,7 +63,7 @@ public final class ImageResponseSerializer: ResponseSerializer {
"image/x-xbitmap"
]

#if os(macOS) || os(iOS) // No WebP support on tvOS or watchOS.
#if os(macOS) || os(iOS) || (swift(>=5.9) && os(visionOS)) // No WebP support on tvOS or watchOS.
if #available(macOS 11, iOS 14, *) {
contentTypes.insert("image/webp")
}
Expand Down Expand Up @@ -125,7 +125,7 @@ public final class ImageResponseSerializer: ResponseSerializer {
throw AFError.responseSerializationFailed(reason: .inputDataNilOrZeroLength)
}

#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || (swift(>=5.9) && os(visionOS))
guard let image = UIImage.af.threadSafeImage(with: data, scale: imageScale) else {
throw AFIError.imageSerializationFailed
}
Expand Down Expand Up @@ -176,17 +176,19 @@ extension DataRequest {
public class var imageScale: CGFloat {
#if os(iOS) || os(tvOS)
return UIScreen.main.scale
#elseif swift(>=5.9) && os(visionOS)
return 2
#elseif os(watchOS)
return WKInterfaceDevice.current().screenScale
#elseif os(macOS)
return 1.0
return 1
#endif
}
}

// MARK: - iOS, tvOS, and watchOS

#if os(iOS) || os(tvOS) || os(watchOS)
#if os(iOS) || os(tvOS) || os(watchOS) || (swift(>=5.9) && os(visionOS))

extension DataRequest {
/// Adds a response handler to be called once the request has finished.
Expand Down
2 changes: 1 addition & 1 deletion Source/UIButton+AlamofireImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import Alamofire
import Foundation

#if os(iOS) || os(tvOS)
#if os(iOS) || os(tvOS) || (swift(>=5.9) && os(visionOS))

import UIKit

Expand Down
Loading

0 comments on commit 9080799

Please sign in to comment.