Skip to content

Commit 927092c

Browse files
author
Alexey Naumov
committed
Replace svg urls with jpg version
1 parent 26ab125 commit 927092c

19 files changed

+102
-82
lines changed

CountriesSwiftUI.xcodeproj/project.pbxproj

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
522A537B2844DCAC002A3CE7 /* SVGView in Frameworks */ = {isa = PBXBuildFile; productRef = 522A537A2844DCAC002A3CE7 /* SVGView */; };
1110
52333A932654463B0034072B /* UIOpenURLContext_Init.m in Sources */ = {isa = PBXBuildFile; fileRef = 52333A922654463B0034072B /* UIOpenURLContext_Init.m */; };
1211
F60829712369CE0100DB292E /* RequestMocking.swift in Sources */ = {isa = PBXBuildFile; fileRef = F60829702369CE0100DB292E /* RequestMocking.swift */; };
1312
F60829732369CE5300DB292E /* MockedResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = F60829722369CE5300DB292E /* MockedResponse.swift */; };
@@ -46,7 +45,7 @@
4645
F661F2B8237738CE0014E142 /* RootViewModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = F661F2B7237738CE0014E142 /* RootViewModifier.swift */; };
4746
F661F2BC237757040014E142 /* ImageWebRepositoryTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F661F2BB237757040014E142 /* ImageWebRepositoryTests.swift */; };
4847
F661F2C5237772CE0014E142 /* ImagesInteractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F661F2C4237772CE0014E142 /* ImagesInteractorTests.swift */; };
49-
F661F2CA23777D440014E142 /* SVGImageViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F661F2C923777D440014E142 /* SVGImageViewTests.swift */; };
48+
F661F2CA23777D440014E142 /* ImageViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F661F2C923777D440014E142 /* ImageViewTests.swift */; };
5049
F661F2CC23783E360014E142 /* Helpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = F661F2CB23783E360014E142 /* Helpers.swift */; };
5150
F6621FE9244B3DE100DC583F /* MockedDBRepositories.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6621FE7244B324200DC583F /* MockedDBRepositories.swift */; };
5251
F66EDB6823F1599F00A01B9F /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = F66EDB6A23F1599F00A01B9F /* Localizable.strings */; };
@@ -81,7 +80,7 @@
8180
F6B883252456326D00EA4067 /* HelpersTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6B883242456326D00EA4067 /* HelpersTests.swift */; };
8281
F6BDB91623636865003E69F2 /* DetailRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6BDB91523636865003E69F2 /* DetailRow.swift */; };
8382
F6BDB91823637C5F003E69F2 /* ActivityIndicatorView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6BDB91723637C5F003E69F2 /* ActivityIndicatorView.swift */; };
84-
F6BDB91A236382E7003E69F2 /* SVGImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6BDB919236382E7003E69F2 /* SVGImageView.swift */; };
83+
F6BDB91A236382E7003E69F2 /* ImageView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6BDB919236382E7003E69F2 /* ImageView.swift */; };
8584
F6C1F9D723CE3034005A98C8 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6C1F9D623CE3034005A98C8 /* SearchBar.swift */; };
8685
F6E7ACE223F5D1EC00AB48AB /* EnvironmentOverrides in Frameworks */ = {isa = PBXBuildFile; productRef = F6E7ACE123F5D1EC00AB48AB /* EnvironmentOverrides */; };
8786
F6E7ACE523F83BEB00AB48AB /* ContentViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F6E7ACE423F83BEB00AB48AB /* ContentViewTests.swift */; };
@@ -145,7 +144,7 @@
145144
F661F2B7237738CE0014E142 /* RootViewModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RootViewModifier.swift; sourceTree = "<group>"; };
146145
F661F2BB237757040014E142 /* ImageWebRepositoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageWebRepositoryTests.swift; sourceTree = "<group>"; };
147146
F661F2C4237772CE0014E142 /* ImagesInteractorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagesInteractorTests.swift; sourceTree = "<group>"; };
148-
F661F2C923777D440014E142 /* SVGImageViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SVGImageViewTests.swift; sourceTree = "<group>"; };
147+
F661F2C923777D440014E142 /* ImageViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageViewTests.swift; sourceTree = "<group>"; };
149148
F661F2CB23783E360014E142 /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
150149
F6621FE7244B324200DC583F /* MockedDBRepositories.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockedDBRepositories.swift; sourceTree = "<group>"; };
151150
F66EDB6723F1599800A01B9F /* en */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = en; path = en.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
@@ -186,7 +185,7 @@
186185
F6B883242456326D00EA4067 /* HelpersTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelpersTests.swift; sourceTree = "<group>"; };
187186
F6BDB91523636865003E69F2 /* DetailRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailRow.swift; sourceTree = "<group>"; };
188187
F6BDB91723637C5F003E69F2 /* ActivityIndicatorView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActivityIndicatorView.swift; sourceTree = "<group>"; };
189-
F6BDB919236382E7003E69F2 /* SVGImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SVGImageView.swift; sourceTree = "<group>"; };
188+
F6BDB919236382E7003E69F2 /* ImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageView.swift; sourceTree = "<group>"; };
190189
F6C1F9D623CE3034005A98C8 /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = "<group>"; };
191190
F6E7ACE423F83BEB00AB48AB /* ContentViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentViewTests.swift; sourceTree = "<group>"; };
192191
F6F003AE236A290E00AAC7C6 /* WebRepositoryTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WebRepositoryTests.swift; sourceTree = "<group>"; };
@@ -202,7 +201,6 @@
202201
isa = PBXFrameworksBuildPhase;
203202
buildActionMask = 2147483647;
204203
files = (
205-
522A537B2844DCAC002A3CE7 /* SVGView in Frameworks */,
206204
F6E7ACE223F5D1EC00AB48AB /* EnvironmentOverrides in Frameworks */,
207205
);
208206
runOnlyForDeploymentPostprocessing = 0;
@@ -239,7 +237,7 @@
239237
F6500B4923C8F2AC0086FD70 /* DeepLinkUITests.swift */,
240238
F60CC50A236C622C007E84B2 /* ModalDetailsViewTests.swift */,
241239
F67451F4243A4CC200A4B498 /* RootViewAppearanceTests.swift */,
242-
F661F2C923777D440014E142 /* SVGImageViewTests.swift */,
240+
F661F2C923777D440014E142 /* ImageViewTests.swift */,
243241
F6F606A723CF25EC00F36F5D /* SearchBarTests.swift */,
244242
F60CC508236C6084007E84B2 /* ViewPreviewsTests.swift */,
245243
);
@@ -272,7 +270,7 @@
272270
F6BDB91523636865003E69F2 /* DetailRow.swift */,
273271
F6218DB523634D4100917938 /* ErrorView.swift */,
274272
F6BDB91723637C5F003E69F2 /* ActivityIndicatorView.swift */,
275-
F6BDB919236382E7003E69F2 /* SVGImageView.swift */,
273+
F6BDB919236382E7003E69F2 /* ImageView.swift */,
276274
F6C1F9D623CE3034005A98C8 /* SearchBar.swift */,
277275
);
278276
path = Components;
@@ -515,7 +513,6 @@
515513
name = CountriesSwiftUI;
516514
packageProductDependencies = (
517515
F6E7ACE123F5D1EC00AB48AB /* EnvironmentOverrides */,
518-
522A537A2844DCAC002A3CE7 /* SVGView */,
519516
);
520517
productName = CountriesSwiftUI;
521518
productReference = F64495E12360D66400C9BB1F /* CountriesSwiftUI.app */;
@@ -577,7 +574,6 @@
577574
packageReferences = (
578575
F6B6212223B52AE600CD00C7 /* XCRemoteSwiftPackageReference "ViewInspector" */,
579576
F6E7ACE023F5D1EC00AB48AB /* XCRemoteSwiftPackageReference "EnvironmentOverrides" */,
580-
522A53792844DCAC002A3CE7 /* XCRemoteSwiftPackageReference "SVGView" */,
581577
);
582578
productRefGroup = F64495E22360D66400C9BB1F /* Products */;
583579
projectDirPath = "";
@@ -671,7 +667,7 @@
671667
F64496082360DFB700C9BB1F /* Models.swift in Sources */,
672668
F64496032360D8EB00C9BB1F /* Loadable.swift in Sources */,
673669
F661F2B8237738CE0014E142 /* RootViewModifier.swift in Sources */,
674-
F6BDB91A236382E7003E69F2 /* SVGImageView.swift in Sources */,
670+
F6BDB91A236382E7003E69F2 /* ImageView.swift in Sources */,
675671
F661F2B6237734FA0014E142 /* AppEnvironment.swift in Sources */,
676672
F68B530A2376EE8C00D6337C /* ImageWebRepository.swift in Sources */,
677673
F644960E2360EF6C00C9BB1F /* WebRepository.swift in Sources */,
@@ -715,7 +711,7 @@
715711
F6621FE9244B3DE100DC583F /* MockedDBRepositories.swift in Sources */,
716712
F68B5308237441AD00D6337C /* Mock.swift in Sources */,
717713
F67B3B22244C5B8700DA7FA6 /* CoreDataStackTests.swift in Sources */,
718-
F661F2CA23777D440014E142 /* SVGImageViewTests.swift in Sources */,
714+
F661F2CA23777D440014E142 /* ImageViewTests.swift in Sources */,
719715
F6F606A823CF25EC00F36F5D /* SearchBarTests.swift in Sources */,
720716
F6B8832324561DDB00EA4067 /* UserPermissionsInteractorTests.swift in Sources */,
721717
F6B883252456326D00EA4067 /* HelpersTests.swift in Sources */,
@@ -1010,14 +1006,6 @@
10101006
/* End XCConfigurationList section */
10111007

10121008
/* Begin XCRemoteSwiftPackageReference section */
1013-
522A53792844DCAC002A3CE7 /* XCRemoteSwiftPackageReference "SVGView" */ = {
1014-
isa = XCRemoteSwiftPackageReference;
1015-
repositoryURL = "https://github.com/exyte/SVGView.git";
1016-
requirement = {
1017-
kind = upToNextMajorVersion;
1018-
minimumVersion = 1.0.0;
1019-
};
1020-
};
10211009
F6B6212223B52AE600CD00C7 /* XCRemoteSwiftPackageReference "ViewInspector" */ = {
10221010
isa = XCRemoteSwiftPackageReference;
10231011
repositoryURL = "https://github.com/nalexn/ViewInspector";
@@ -1037,11 +1025,6 @@
10371025
/* End XCRemoteSwiftPackageReference section */
10381026

10391027
/* Begin XCSwiftPackageProductDependency section */
1040-
522A537A2844DCAC002A3CE7 /* SVGView */ = {
1041-
isa = XCSwiftPackageProductDependency;
1042-
package = 522A53792844DCAC002A3CE7 /* XCRemoteSwiftPackageReference "SVGView" */;
1043-
productName = SVGView;
1044-
};
10451028
F6B6212323B52AE600CD00C7 /* ViewInspector */ = {
10461029
isa = XCSwiftPackageProductDependency;
10471030
package = F6B6212223B52AE600CD00C7 /* XCRemoteSwiftPackageReference "ViewInspector" */;

CountriesSwiftUI/Interactors/ImagesInteractor.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Foundation
1111
import SwiftUI
1212

1313
protocol ImagesInteractor {
14-
func load(image: LoadableSubject<Data>, url: URL?)
14+
func load(image: LoadableSubject<UIImage>, url: URL?)
1515
}
1616

1717
struct RealImagesInteractor: ImagesInteractor {
@@ -22,7 +22,7 @@ struct RealImagesInteractor: ImagesInteractor {
2222
self.webRepository = webRepository
2323
}
2424

25-
func load(image: LoadableSubject<Data>, url: URL?) {
25+
func load(image: LoadableSubject<UIImage>, url: URL?) {
2626
guard let url = url else {
2727
image.wrappedValue = .notRequested; return
2828
}
@@ -37,6 +37,6 @@ struct RealImagesInteractor: ImagesInteractor {
3737
}
3838

3939
struct StubImagesInteractor: ImagesInteractor {
40-
func load(image: LoadableSubject<Data>, url: URL?) {
40+
func load(image: LoadableSubject<UIImage>, url: URL?) {
4141
}
4242
}

CountriesSwiftUI/Models/MockedData.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import Foundation
1313
extension Country {
1414
static let mockedData: [Country] = [
1515
Country(name: "United States", translations: [:], population: 125000000,
16-
flag: URL(string: "https://flagcdn.com/us.svg"), alpha3Code: "USA"),
16+
flag: URL(string: "https://flagcdn.com/w640/us.jpg"), alpha3Code: "USA"),
1717
Country(name: "Georgia", translations: [:], population: 2340000, flag: nil, alpha3Code: "GEO"),
1818
Country(name: "Canada", translations: [:], population: 57600000, flag: nil, alpha3Code: "CAN")
1919
]

CountriesSwiftUI/Models/Models.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,35 @@ struct Country: Codable, Equatable {
1616
let alpha3Code: Code
1717

1818
typealias Code = String
19+
20+
enum CodingKeys: String, CodingKey {
21+
case name
22+
case translations
23+
case population
24+
case flag = "alpha2Code"
25+
case alpha3Code
26+
}
27+
28+
init(name: String, translations: [String: String?], population: Int, flag: URL?, alpha3Code: Code) {
29+
self.name = name
30+
self.translations = translations
31+
self.population = population
32+
self.flag = flag
33+
self.alpha3Code = alpha3Code
34+
}
35+
36+
init(from decoder: Decoder) throws {
37+
let values = try decoder.container(keyedBy: CodingKeys.self)
38+
name = try values.decode(String.self, forKey: .name)
39+
translations = try values.decode([String: String?].self, forKey: .translations)
40+
population = try values.decode(Int.self, forKey: .population)
41+
if let alpha2orFlagURL = try? values.decode(Code.self, forKey: .flag) {
42+
let urlString = alpha2orFlagURL.count == 2 ?
43+
"https://flagcdn.com/w640/\(alpha2orFlagURL.lowercased()).jpg" : alpha2orFlagURL
44+
flag = URL(string: urlString)
45+
} else { flag = nil }
46+
alpha3Code = try values.decode(Code.self, forKey: .alpha3Code)
47+
}
1948
}
2049

2150
extension Country {

CountriesSwiftUI/Repositories/ImageWebRepository.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import Combine
1010
import UIKit
1111

1212
protocol ImageWebRepository: WebRepository {
13-
func load(imageURL: URL) -> AnyPublisher<Data, Error>
13+
func load(imageURL: URL) -> AnyPublisher<UIImage, Error>
1414
}
1515

1616
struct RealImageWebRepository: ImageWebRepository {
@@ -24,17 +24,24 @@ struct RealImageWebRepository: ImageWebRepository {
2424
self.baseURL = baseURL
2525
}
2626

27-
func load(imageURL: URL) -> AnyPublisher<Data, Error> {
27+
func load(imageURL: URL) -> AnyPublisher<UIImage, Error> {
2828
return download(rawImageURL: imageURL)
2929
.subscribe(on: bgQueue)
3030
.receive(on: DispatchQueue.main)
3131
.extractUnderlyingError()
3232
.eraseToAnyPublisher()
3333
}
3434

35-
private func download(rawImageURL: URL) -> AnyPublisher<Data, Error> {
35+
private func download(rawImageURL: URL) -> AnyPublisher<UIImage, Error> {
3636
let urlRequest = URLRequest(url: rawImageURL)
3737
return session.dataTaskPublisher(for: urlRequest)
3838
.requestData()
39+
.tryMap { data -> UIImage in
40+
guard let image = UIImage(data: data) else {
41+
throw APIError.imageDeserialization
42+
}
43+
return image
44+
}
45+
.eraseToAnyPublisher()
3946
}
4047
}

CountriesSwiftUI/UI/Components/SVGImageView.swift renamed to CountriesSwiftUI/UI/Components/ImageView.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// SVGImageView.swift
2+
// ImageView.swift
33
// CountriesSwiftUI
44
//
55
// Created by Alexey Naumov on 25.10.2019.
@@ -8,16 +8,15 @@
88

99
import SwiftUI
1010
import Combine
11-
import SVGView
1211

13-
struct SVGImageView: View {
12+
struct ImageView: View {
1413

1514
let imageURL: URL
1615
@Environment(\.injected) var injected: DIContainer
17-
@State private var image: Loadable<Data>
16+
@State private var image: Loadable<UIImage>
1817
let inspection = Inspection<Self>()
1918

20-
init(imageURL: URL, image: Loadable<Data> = .notRequested) {
19+
init(imageURL: URL, image: Loadable<UIImage> = .notRequested) {
2120
self.imageURL = imageURL
2221
self._image = .init(initialValue: image)
2322
}
@@ -43,7 +42,7 @@ struct SVGImageView: View {
4342

4443
// MARK: - Side Effects
4544

46-
private extension SVGImageView {
45+
private extension ImageView {
4746
func loadImage() {
4847
injected.interactors.imagesInteractor
4948
.load(image: $image, url: imageURL)
@@ -52,7 +51,7 @@ private extension SVGImageView {
5251

5352
// MARK: - Content
5453

55-
private extension SVGImageView {
54+
private extension ImageView {
5655
var notRequestedView: some View {
5756
Text("").onAppear {
5857
self.loadImage()
@@ -70,20 +69,20 @@ private extension SVGImageView {
7069
.padding()
7170
}
7271

73-
func loadedView(_ image: Data) -> some View {
74-
SVGView(data: image)
75-
.scaleEffect(0.2, anchor: .topLeading)
76-
.frame(width: 200, height: 140, alignment: .center)
72+
func loadedView(_ uiImage: UIImage) -> some View {
73+
Image(uiImage: uiImage)
74+
.resizable()
75+
.aspectRatio(contentMode: .fit)
7776
}
7877
}
7978

8079
#if DEBUG
81-
struct SVGImageView_Previews: PreviewProvider {
80+
struct ImageView_Previews: PreviewProvider {
8281
static var previews: some View {
8382
VStack {
84-
SVGImageView(imageURL: URL(string: "https://flagcdn.com/us.svg")!)
85-
SVGImageView(imageURL: URL(string: "https://flagcdn.com/al.svg")!)
86-
SVGImageView(imageURL: URL(string: "https://flagcdn.com/ru.svg")!)
83+
ImageView(imageURL: URL(string: "https://flagcdn.com/w640/us.jpg")!)
84+
ImageView(imageURL: URL(string: "https://flagcdn.com/w640/al.jpg")!)
85+
ImageView(imageURL: URL(string: "https://flagcdn.com/w640/ru.jpg")!)
8786
}
8887
}
8988
}

CountriesSwiftUI/UI/Screens/CountryDetails.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ private extension CountryDetails {
110110
func flagView(url: URL) -> some View {
111111
HStack {
112112
Spacer()
113-
SVGImageView(imageURL: url)
114-
// .frame(width: 120, height: 80)
113+
ImageView(imageURL: url)
114+
.frame(width: 120, height: 80)
115115
.onTapGesture {
116116
self.showCountryDetailsSheet()
117117
}

CountriesSwiftUI/UI/Screens/ModalDetailsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct ModalDetailsView: View {
2020
country.flag.map { url in
2121
HStack {
2222
Spacer()
23-
SVGImageView(imageURL: url)
23+
ImageView(imageURL: url)
2424
.frame(width: 300, height: 200)
2525
Spacer()
2626
}

CountriesSwiftUI/Utilities/APICall.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ enum APIError: Swift.Error {
1919
case invalidURL
2020
case httpCode(HTTPCode)
2121
case unexpectedResponse
22+
case imageDeserialization
2223
}
2324

2425
extension APIError: LocalizedError {
@@ -27,6 +28,7 @@ extension APIError: LocalizedError {
2728
case .invalidURL: return "Invalid URL"
2829
case let .httpCode(code): return "Unexpected HTTP code: \(code)"
2930
case .unexpectedResponse: return "Unexpected response from the server"
31+
case .imageDeserialization: return "Cannot deserialize image from Data"
3032
}
3133
}
3234
}

0 commit comments

Comments
 (0)