Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
0xWDG committed Jul 22, 2024
0 parents commit 555f0aa
Show file tree
Hide file tree
Showing 13 changed files with 813 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/build-documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# .github/workflows/build-documentation.yml

name: build-documentation

on:
# Run on push to main branch
push:
branches:
- main

# Dispatch if triggered using Github (website)
workflow_dispatch:

jobs:
Build-documentation:
runs-on: macos-latest
steps:
- name: Build documentation
uses: 0xWDG/build-documentation@main
20 changes: 20 additions & 0 deletions .github/workflows/build-multiplatform.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# .github/workflows/build-multiplatform.yml

name: Build-Packages

on:
# Run on pull_request
pull_request:

# Dispatch if triggered using Github (website)
workflow_dispatch:

jobs:
Build-Packages:
runs-on: macos-latest
steps:
- name: Build Swift Packages
uses: 0xWDG/build-swift@main
with:
# watchOS is unsupported
watchOS: false
16 changes: 16 additions & 0 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Run Swiftlint
on:
push:
pull_request:
workflow_dispatch:

jobs:
swiftlint:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3

- name: SwiftLint
run: |
brew install swiftlint
swiftlint --reporter github-actions-logging --strict
23 changes: 23 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Run tests on Linux and macOS
on:
push:
workflow_dispatch:

jobs:
test_linux:
if: true
runs-on: ubuntu-latest
continue-on-error: true
steps:
- uses: actions/checkout@v3

- name: Swift test
run: swift test

test_macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3

- name: Swift test
run: swift test
63 changes: 63 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
## User settings
xcuserdata/

## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9)
*.xcscmblueprint
*.xccheckout

## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4)
build/
DerivedData/
*.moved-aside
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3

## Obj-C/Swift specific
*.hmap

## App packaging
*.ipa
*.dSYM.zip
*.dSYM

## Playgrounds
timeline.xctimeline
playground.xcworkspace

### Swift Package Manager
Packages/
Package.pins
Package.resolved
# *.xcodeproj
#
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
# hence it is not needed unless you have added a package configuration file to your project
.swiftpm
.build/

### CocoaPods
Pods/
*.xcworkspace

### Carthage
Carthage/Checkouts
Carthage/Build/

### Accio dependency management
Dependencies/
.accio/

### fastlane
fastlane/report.xml
fastlane/Preview.html
fastlane/screenshots/**/*.png
fastlane/test_output

### Code Injection
iOSInjectionProject/
4 changes: 4 additions & 0 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 1
builder:
configs:
- documentation_targets: [CachedAsyncImage]
16 changes: 16 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
excluded:
- "*resource_bundle_accessor*" # SwiftPM Generated
- ".build/*"

opt_in_rules:
- missing_docs
- empty_count
- empty_string
- toggle_bool
- unused_optional_binding
- valid_ibinspectable
- modifier_order
- first_where
- fatal_error_message
- force_unwrapping

21 changes: 21 additions & 0 deletions LICENCE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Wesley de Groot, email@WesleydeGroot.nl

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
29 changes: 29 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// swift-tools-version: 5.8.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "Inspect",
platforms: [
.iOS(.v15),
.macOS(.v12),
.tvOS(.v14),
.macCatalyst(.v15)
],
products: [
// Products define the executables and libraries a package produces, making them visible to other packages.
.library(
name: "Inspect",
targets: ["Inspect"]),

Check failure on line 18 in Package.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Collection literals should not have trailing commas (trailing_comma)

Check failure on line 18 in Package.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Collection literals should not have trailing commas (trailing_comma)
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.target(
name: "Inspect"),
.testTarget(
name: "InspectTests",
dependencies: ["Inspect"]),

Check failure on line 27 in Package.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Collection literals should not have trailing commas (trailing_comma)

Check failure on line 27 in Package.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Collection literals should not have trailing commas (trailing_comma)
]
)
93 changes: 93 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# CachedAsyncImage

CachedAsyncImage is a Swift Package for asynchronously loading images from the web and caching them.

[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FCachedAsyncImage%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/0xWDG/CachedAsyncImage)
[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2F0xWDG%2FCachedAsyncImage%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/0xWDG/CachedAsyncImage)
[![Swift Package Manager](https://img.shields.io/badge/SPM-compatible-brightgreen.svg)](https://swift.org/package-manager)
![License](https://img.shields.io/github/license/0xWDG/CachedAsyncImage)

## Requirements

- Swift 5.9+ (Xcode 15+)
- iOS 13+, macOS 10.15+

## Installation (Pakage.swift)

```swift
dependencies: [
.package(url: "https://github.com/0xWDG/CachedAsyncImage.git", .branch("main")),
],
targets: [
.target(name: "MyTarget", dependencies: [
.product(name: "CachedAsyncImage", package: "CachedAsyncImage"),
]),
]
```

## Installation (Xcode)

1. In Xcode, open your project and navigate to **File****Swift Packages****Add Package Dependency...**
2. Paste the repository URL (`https://github.com/0xWDG/CachedAsyncImage`) and click **Next**.
3. Click **Finish**.

## Usage

`CachedAsyncImage` has the exact same API and behavior as `AsyncImage`, so you just have to change this:

```swift
AsyncImage(url: logoURL)
```

to this:

```swift
CachedAsyncImage(url: logoURL)
```

example:

```swift
import SwiftUI
import CachedAsyncImage

struct ContentView: View {
var body: some View {
VStack {
CachedAsyncImage(
url: URL(
string: "https://wesleydegroot.nl/assets/avatar/avatar.webp"
)
) { image in
image
.resizable()
.frame(width: 250, height: 250)
} placeholder: {
ProgressView()
}
}
.padding()
}
}
```

In addition to `AsyncImage` initializers, you have the possibilities to specify the cache you want to use (by default `URLCache.shared` is used), and to use `URLRequest` instead of `URL`:

```swift
CachedAsyncImage(urlRequest: logoURLRequest, urlCache: .imageCache)
```

```swift
// URLCache+imageCache.swift

extension URLCache {

static let imageCache = URLCache(memoryCapacity: 512_000_000, diskCapacity: 10_000_000_000)
}
```

Remember when setting the cache the response (in this case our image) must be no larger than about 5% of the disk cache (See [this discussion](https://developer.apple.com/documentation/foundation/nsurlsessiondatadelegate/1411612-urlsession#discussion)).

## Contact

We can get in touch via [Twitter/X](https://twitter.com/0xWDG), [Discord](https://discordapp.com/users/918438083861573692), [Mastodon](https://iosdev.space/@0xWDG), [Email](mailto:email+oss@wesleydegroot.nl), [Website](https://wesleydegroot.nl).
Loading

0 comments on commit 555f0aa

Please sign in to comment.