Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions Content Generator.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
F021B70B2A37CB1500993847 /* View+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F021B70A2A37CB1500993847 /* View+Extensions.swift */; };
F021B70D2A37CB4400993847 /* DependencyContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F021B70C2A37CB4400993847 /* DependencyContainer.swift */; };
F021B7132A37CD2100993847 /* ContentInjector.swift in Sources */ = {isa = PBXBuildFile; fileRef = F021B7122A37CD2100993847 /* ContentInjector.swift */; };
F021B7152A37CD3E00993847 /* Dependency.swift in Sources */ = {isa = PBXBuildFile; fileRef = F021B7142A37CD3E00993847 /* Dependency.swift */; };
F021B7172A37D1A100993847 /* FeaturesContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F021B7162A37D1A100993847 /* FeaturesContainer.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -71,7 +70,6 @@
F021B70A2A37CB1500993847 /* View+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+Extensions.swift"; sourceTree = "<group>"; };
F021B70C2A37CB4400993847 /* DependencyContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DependencyContainer.swift; sourceTree = "<group>"; };
F021B7122A37CD2100993847 /* ContentInjector.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentInjector.swift; sourceTree = "<group>"; };
F021B7142A37CD3E00993847 /* Dependency.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Dependency.swift; sourceTree = "<group>"; };
F021B7162A37D1A100993847 /* FeaturesContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FeaturesContainer.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -307,7 +305,6 @@
F021B70E2A37CBB700993847 /* Injectors */ = {
isa = PBXGroup;
children = (
F021B7142A37CD3E00993847 /* Dependency.swift */,
F021B70C2A37CB4400993847 /* DependencyContainer.swift */,
F021B7162A37D1A100993847 /* FeaturesContainer.swift */,
F021B70F2A37CBC300993847 /* FeatureInjectors */,
Expand Down Expand Up @@ -467,7 +464,6 @@
F021B70B2A37CB1500993847 /* View+Extensions.swift in Sources */,
F021B6F22A37C72400993847 /* FetchContentsUseCase.swift in Sources */,
F021B6BA2A37C54C00993847 /* Content_GeneratorApp.swift in Sources */,
F021B7152A37CD3E00993847 /* Dependency.swift in Sources */,
F021B6F72A37C7B600993847 /* ContentModel.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -637,7 +633,7 @@
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 17.6;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.3;
Expand Down Expand Up @@ -675,7 +671,7 @@
"INFOPLIST_KEY_UIStatusBarStyle[sdk=iphonesimulator*]" = UIStatusBarStyleDefault;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
IPHONEOS_DEPLOYMENT_TARGET = 16.4;
IPHONEOS_DEPLOYMENT_TARGET = 17.6;
LD_RUNPATH_SEARCH_PATHS = "@executable_path/Frameworks";
"LD_RUNPATH_SEARCH_PATHS[sdk=macosx*]" = "@executable_path/../Frameworks";
MACOSX_DEPLOYMENT_TARGET = 13.3;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
protocol ContentRepository {
func fetchContents() -> [ContentEntity]
func fetchContents() async throws -> [ContentEntity]
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
protocol FetchContentsUseCase {
func call() -> [ContentEntity]
func call() async throws -> [ContentEntity]
}

struct FetchContentsUseCaseImpl: FetchContentsUseCase {

var repository: ContentRepository

func call() -> [ContentEntity] {
repository.fetchContents()
func call() async throws -> [ContentEntity] {
try await repository.fetchContents()
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
struct ContentRemoteDatasource: ContentDatasource {
func fetchContents() -> [ContentModel] {
func fetchContents() async throws -> [ContentModel] {

try await Task.sleep(nanoseconds: 1_000_000_000)

return [
ContentModel(theme: "Teste 1", url: "Url 1", level: "Level 1"),
ContentModel(theme: "Teste 2", url: "Url 2", level: "Level 2"),
ContentModel(theme: "Teste 3", url: "Url 3", level: "Level 3"),
ContentModel(theme: "Teste 4", url: "Url 4", level: "Level 4"),
ContentModel(theme: "Teste 5", url: "Url 5", level: "Level 5")
ContentModel(theme: "Test 1", url: "Url 1", level: "Level 1"),
ContentModel(theme: "Test 2", url: "Url 2", level: "Level 2"),
ContentModel(theme: "Test 3", url: "Url 3", level: "Level 3"),
ContentModel(theme: "Test 4", url: "Url 4", level: "Level 4"),
ContentModel(theme: "Test 5", url: "Url 5", level: "Level 5")
]
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
protocol ContentDatasource {
func fetchContents() -> [ContentModel]
func fetchContents() async throws -> [ContentModel]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
struct ContentRepositoryImpl: ContentRepository {
var datasource: ContentDatasource
actor ContentRepositoryImpl: ContentRepository {
private let datasource: ContentDatasource

func fetchContents() -> [ContentEntity] {
let contents: [ContentModel] = datasource.fetchContents()
init(datasource: ContentDatasource) {
self.datasource = datasource
}

func fetchContents() async throws -> [ContentEntity] {
let contents: [ContentModel] = try await datasource.fetchContents()
return contents.map({ ContentMapper.toEntity(from: $0) })
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
struct ContentViewModel {
import Foundation

@MainActor
class ContentViewModel: ObservableObject {

@Published var contents: [ContentEntity] = []

private var _fetchContentsUseCase: FetchContentsUseCase

init(_ fetchContentsUseCase: FetchContentsUseCase) {
self._fetchContentsUseCase = fetchContentsUseCase
}

func fetchContents() -> [ContentEntity] {
return _fetchContentsUseCase.call()
func fetchContents() async throws {
do {
let data = try await _fetchContentsUseCase.call()
self.contents = data
} catch {
throw error
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,31 @@ import SwiftUI
struct ContentView: View {

// MARK: Properties
@Dependency(\.features.contentFeature.contentViewModel) var viewModel

@State var contents: [ContentEntity] = []
@StateObject private var viewModel: ContentViewModel

init() {
let viewModel = DependencyContainer().features.contentFeature.contentViewModel
_viewModel = StateObject(wrappedValue: viewModel)
}

// MARK: - Body
var body: some View {
HStack {
List {
ForEach(contents, id: \.url) { content in
ForEach(viewModel.contents, id: \.url) { content in
Text(content.theme)
.foregroundStyle(Color.blue)
}
}
}
.task {
contents = viewModel.fetchContents()
.task(priority: .background) {
do {
try await viewModel.fetchContents()
} catch {
// Get the error
print(error)
}
}
}
}
Expand Down
21 changes: 0 additions & 21 deletions Content Generator/Injectors/Dependency.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ContentInjector {
}()

// ViewModel
@MainActor
lazy var contentViewModel: ContentViewModel = {
ContentViewModel(fetchContentsUseCase)
}()
Expand Down