Skip to content

Commit c7d75f8

Browse files
vani2laqiguy
andauthored
Add session delegate to initializer (#44)
* Add session delegate to initializer * Change method signature for data * update podfile.lock * Update github action for tests * update for min iOS 13 - remove URLSession extension - remove AsyncAwaitHelper - remove ProgressWrapper - remove AsyncAwaitHelper tests * update macos runner version --------- Co-authored-by: Aleksei Tiurnin <[email protected]>
1 parent 4fd175b commit c7d75f8

File tree

16 files changed

+45
-318
lines changed

16 files changed

+45
-318
lines changed

.github/workflows/tests.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ on:
1414
jobs:
1515
test:
1616
name: Run tests
17-
runs-on: macos-12
17+
runs-on: macos-13
1818
steps:
1919
- name: Checkout
2020
uses: actions/checkout@v2
2121
- name: Change Xcode
22-
run: sudo xcode-select -s /Applications/Xcode_13.4.1.app
22+
run: sudo xcode-select -s /Applications/Xcode_15.0.1.app
2323
- name: Build and test
24-
run: swift test --enable-code-coverage --disable-automatic-resolution
24+
run: swift test --enable-code-coverage --disable-automatic-resolution

Apexy.podspec

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
Pod::Spec.new do |s|
22
s.name = "Apexy"
3-
s.version = "1.7.3"
3+
s.version = "1.7.4"
44
s.summary = "HTTP transport library"
55
s.homepage = "https://github.com/RedMadRobot/apexy-ios"
66
s.license = { :type => "MIT"}
77
s.author = { "Alexander Ignatiev" => "[email protected]" }
88
s.source = { :git => "https://github.com/RedMadRobot/apexy-ios.git", :tag => "#{s.version}" }
99

10-
s.ios.deployment_target = "11.0"
11-
s.tvos.deployment_target = "11.0"
12-
s.osx.deployment_target = "10.13"
13-
s.watchos.deployment_target = "4.0"
10+
s.ios.deployment_target = "13.0"
11+
s.tvos.deployment_target = "13.0"
12+
s.osx.deployment_target = "10.15"
13+
s.watchos.deployment_target = "6.0"
1414

1515
s.swift_version = "5.3"
1616

1717
s.subspec 'Core' do |sp|
18-
sp.source_files = "Sources/Apexy/*.swift"
18+
sp.source_files = "Sources/Apexy/**/*.swift"
1919
end
2020

2121
s.subspec 'Alamofire' do |sp|
2222
sp.source_files = "Sources/ApexyAlamofire/*.swift"
2323
sp.dependency "Apexy/Core"
24-
sp.dependency "Alamofire", '~>5.0'
24+
sp.dependency "Alamofire", '~>5.6'
2525
end
2626

2727
s.subspec 'URLSession' do |sp|

Example/Example.xcodeproj/project.pbxproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 51;
6+
objectVersion = 54;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -791,7 +791,7 @@
791791
CODE_SIGN_STYLE = Automatic;
792792
DEVELOPMENT_TEAM = 42LRQS6X44;
793793
INFOPLIST_FILE = "Example/Supporting Files/Info.plist";
794-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
794+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
795795
LD_RUNPATH_SEARCH_PATHS = (
796796
"$(inherited)",
797797
"@executable_path/Frameworks",
@@ -812,7 +812,7 @@
812812
CODE_SIGN_STYLE = Automatic;
813813
DEVELOPMENT_TEAM = 42LRQS6X44;
814814
INFOPLIST_FILE = "Example/Supporting Files/Info.plist";
815-
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
815+
IPHONEOS_DEPLOYMENT_TARGET = 13.0;
816816
LD_RUNPATH_SEARCH_PATHS = (
817817
"$(inherited)",
818818
"@executable_path/Frameworks",

Example/Example/Sources/Business Logic/Service/BookService.swift

+2-13
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,18 @@ import ExampleAPI
1212
typealias Book = ExampleAPI.Book
1313

1414
protocol BookService {
15-
16-
@discardableResult
17-
func fetchBooks(completion: @escaping (Result<[Book], Error>) -> Void) -> Progress
18-
19-
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
2015
func fetchBooks() async throws -> [Book]
2116
}
2217

2318

2419
final class BookServiceImpl: BookService {
2520

26-
let apiClient: Client
21+
let apiClient: ConcurrencyClient
2722

28-
init(apiClient: Client) {
23+
init(apiClient: ConcurrencyClient) {
2924
self.apiClient = apiClient
3025
}
3126

32-
func fetchBooks(completion: @escaping (Result<[Book], Error>) -> Void) -> Progress {
33-
let endpoint = BookListEndpoint()
34-
return apiClient.request(endpoint, completionHandler: completion)
35-
}
36-
37-
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
3827
func fetchBooks() async throws -> [Book] {
3928
let endpoint = BookListEndpoint()
4029
return try await apiClient.request(endpoint)

Example/Example/Sources/Business Logic/Service/FileService.swift

+3-25
Original file line numberDiff line numberDiff line change
@@ -10,46 +10,24 @@ import Apexy
1010
import ExampleAPI
1111

1212
protocol FileService {
13-
14-
@discardableResult
15-
func upload(file: URL, completion: @escaping (Result<Void, Error>) -> Void) -> Progress
16-
17-
@discardableResult
18-
func upload(stream: InputStream, size: Int, completion: @escaping (Result<Void, Error>) -> Void) -> Progress
19-
20-
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
2113
func upload(file: URL) async throws
22-
23-
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
2414
func upload(stream: InputStream, size: Int) async throws
2515
}
2616

2717

2818
final class FileServiceImpl: FileService {
2919

30-
let apiClient: Client
20+
let apiClient: ConcurrencyClient
3121

32-
init(apiClient: Client) {
22+
init(apiClient: ConcurrencyClient) {
3323
self.apiClient = apiClient
3424
}
35-
36-
func upload(file: URL, completion: @escaping (Result<Void, Error>) -> Void) -> Progress {
37-
let endpoint = FileUploadEndpoint(fileURL: file)
38-
return apiClient.upload(endpoint, completionHandler: completion)
39-
}
40-
41-
func upload(stream: InputStream, size: Int, completion: @escaping (Result<Void, Error>) -> Void) -> Progress {
42-
let endpoint = StreamUploadEndpoint(stream: stream, size: size)
43-
return apiClient.upload(endpoint, completionHandler: completion)
44-
}
45-
46-
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
25+
4726
func upload(file: URL) async throws {
4827
let endpoint = FileUploadEndpoint(fileURL: file)
4928
return try await apiClient.upload(endpoint)
5029
}
5130

52-
@available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *)
5331
func upload(stream: InputStream, size: Int) async throws {
5432
let endpoint = StreamUploadEndpoint(stream: stream, size: size)
5533
return try await apiClient.upload(endpoint)

Example/Example/Sources/Business Logic/ServiceLayer.swift

+6-8
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@ final class ServiceLayer {
1515

1616
static let shared = ServiceLayer()
1717

18-
private(set) lazy var apiClient: Client = {
19-
return AlamofireClient(
20-
baseURL: URL(string: "https://library.mock-object.redmadserver.com/api/v1/")!,
21-
configuration: .ephemeral,
22-
responseObserver: { [weak self] request, response, data, error in
23-
self?.validateSession(responseError: error)
24-
})
25-
}()
18+
private(set) lazy var apiClient: ConcurrencyClient = AlamofireClient(
19+
baseURL: URL(string: "https://library.mock-object.redmadserver.com/api/v1/")!,
20+
configuration: .ephemeral,
21+
responseObserver: { [weak self] request, response, data, error in
22+
self?.validateSession(responseError: error)
23+
})
2624

2725
private(set) lazy var bookService: BookService = BookServiceImpl(apiClient: apiClient)
2826

Example/Example/Sources/Presentation/ViewController.swift

+1-58
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ class ViewController: UIViewController {
3030
@IBAction private func performRequest() {
3131
activityView.isHidden = false
3232

33-
guard #available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) else { performLegacyRequest(); return }
34-
3533
task = Task {
3634
do {
3735
let books = try await bookService.fetchBooks()
@@ -43,25 +41,9 @@ class ViewController: UIViewController {
4341
}
4442
}
4543

46-
private func performLegacyRequest() {
47-
progress = bookService.fetchBooks() { [weak self] result in
48-
guard let self = self else { return }
49-
self.activityView.isHidden = true
50-
switch result {
51-
case .success(let books):
52-
self.show(books: books)
53-
case .failure(let error):
54-
self.show(error: error)
55-
}
56-
}
57-
}
58-
59-
6044
@IBAction private func upload() {
6145
guard let file = Bundle.main.url(forResource: "Info", withExtension: "plist") else { return }
6246
activityView.isHidden = false
63-
64-
guard #available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) else { legacyUpload(with: file); return }
6547

6648
task = Task {
6749
do {
@@ -73,27 +55,12 @@ class ViewController: UIViewController {
7355
activityView.isHidden = true
7456
}
7557
}
76-
77-
private func legacyUpload(with file: URL) {
78-
progress = fileService.upload(file: file) { [weak self] result in
79-
guard let self = self else { return }
80-
self.activityView.isHidden = true
81-
switch result {
82-
case .success:
83-
self.showOKUpload()
84-
case .failure(let error):
85-
self.show(error: error)
86-
}
87-
}
88-
}
89-
58+
9059
@IBAction private func uploadStream() {
9160
let streamer = Streamer()
9261
self.streamer = streamer
9362
activityView.isHidden = false
9463

95-
guard #available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) else { legacyUploadStream(with: streamer); return }
96-
9764
streamer.run()
9865

9966
task = Task {
@@ -106,30 +73,6 @@ class ViewController: UIViewController {
10673
}
10774
}
10875

109-
private func legacyUploadStream(with streamer: Streamer) {
110-
progress = fileService.upload(
111-
stream: streamer.boundStreams.input,
112-
size: streamer.totalDataSize) { [weak self] result in
113-
guard let self = self else { return }
114-
self.activityView.isHidden = true
115-
switch result {
116-
case .success:
117-
self.showOKUpload()
118-
case .failure(let error):
119-
self.show(error: error)
120-
self.streamer = nil
121-
}
122-
}
123-
streamer.run()
124-
125-
observation = progress?.observe(\.fractionCompleted, options: [.new]) { [weak self] (progress, value) in
126-
DispatchQueue.main.async {
127-
let percent = (value.newValue ?? 0) * 100
128-
self?.resultLabel.text = "Progress: \(String(format: "%.0f", percent))%"
129-
}
130-
}
131-
}
132-
13376
@IBAction private func cancel() {
13477
if #available(macOS 10.15, iOS 13, watchOS 6, tvOS 13, *) {
13578
(task as? Task<Void, Never>)?.cancel()

Example/Podfile.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
PODS:
2-
- Alamofire (5.4.1)
3-
- Apexy (1.7.2):
4-
- Apexy/Alamofire (= 1.7.2)
5-
- Apexy/Alamofire (1.7.2):
6-
- Alamofire (~> 5.0)
2+
- Alamofire (5.8.1)
3+
- Apexy (1.7.4):
4+
- Apexy/Alamofire (= 1.7.4)
5+
- Apexy/Alamofire (1.7.4):
6+
- Alamofire (~> 5.6)
77
- Apexy/Core
8-
- Apexy/Core (1.7.2)
8+
- Apexy/Core (1.7.4)
99

1010
DEPENDENCIES:
1111
- Apexy (from `../`)
@@ -19,8 +19,8 @@ EXTERNAL SOURCES:
1919
:path: "../"
2020

2121
SPEC CHECKSUMS:
22-
Alamofire: 2291f7d21ca607c491dd17642e5d40fdcda0e65c
23-
Apexy: 984a2c615adf4b5af3432859d768a7a3dec51907
22+
Alamofire: 3ca42e259043ee0dc5c0cdd76c4bc568b8e42af7
23+
Apexy: a3218097135e746fd7c9215da167521f9275df23
2424

2525
PODFILE CHECKSUM: f86a90e7590ccb3aa7caeceaf315abe256650c66
2626

Package.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import PackageDescription
66
let package = Package(
77
name: "Apexy",
88
platforms: [
9-
.macOS(.v10_13),
10-
.iOS(.v11),
11-
.tvOS(.v11),
12-
.watchOS(.v4)
9+
.macOS(.v10_15),
10+
.iOS(.v13),
11+
.tvOS(.v13),
12+
.watchOS(.v6)
1313
],
1414
products: [
1515
.library(name: "Apexy", targets: ["ApexyURLSession"]),

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ Split the network layer into folders:
284284

285285
## Requirements
286286

287-
- iOS 11.0+ / macOS 10.13+ / tvOS 11.0+ / watchOS 4.0+
287+
- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+
288288
- Xcode 12+
289289
- Swift 5.3+
290290

README.ru.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public struct FileUploadEndpoint: UploadEndpoint {
285285

286286
## Требования
287287

288-
- iOS 11.0+ / macOS 10.13+ / tvOS 11.0+ / watchOS 4.0+
288+
- iOS 13.0+ / macOS 10.15+ / tvOS 13.0+ / watchOS 6.0+
289289
- Xcode 12+
290290
- Swift 5.3+
291291

Sources/ApexyURLSession/Helpers/AsyncAwaitHelper.swift

-24
This file was deleted.

0 commit comments

Comments
 (0)