Skip to content

Commit

Permalink
Merge pull request #22 from dahun-lee-daji/iOS/feature/17/Persistence
Browse files Browse the repository at this point in the history
iOS/feature/17/persistence
  • Loading branch information
dahun-lee-daji committed Apr 28, 2021
2 parents fb70cc2 + 2becbfa commit 7fa457a
Show file tree
Hide file tree
Showing 18 changed files with 496 additions and 19 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 33 additions & 0 deletions SideDishApp/SideDishApp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
1E1DBAD9262DDDFC0050FE6C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1E1DBAD7262DDDFC0050FE6C /* Main.storyboard */; };
1E1DBADB262DDDFD0050FE6C /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 1E1DBADA262DDDFD0050FE6C /* Assets.xcassets */; };
1E1DBADE262DDDFD0050FE6C /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 1E1DBADC262DDDFD0050FE6C /* LaunchScreen.storyboard */; };
1E5053C82636F504005615F5 /* DishesEntity+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E5053C72636F504005615F5 /* DishesEntity+CoreDataProperties.swift */; };
1E5053C92636F504005615F5 /* DishesEntity+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1E5053C52636F504005615F5 /* DishesEntity+CoreDataClass.swift */; };
1ECD5F62262F256000DC56C0 /* Endpoint.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECD5F61262F256000DC56C0 /* Endpoint.swift */; };
1ECD5F66262F2E1E00DC56C0 /* NetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECD5F65262F2E1E00DC56C0 /* NetworkManager.swift */; };
1ECD5F6A262F3B6500DC56C0 /* DishNetworkManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECD5F69262F3B6500DC56C0 /* DishNetworkManager.swift */; };
Expand All @@ -21,6 +23,9 @@
1ECD5F73262F405100DC56C0 /* MenuListViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECD5F72262F405100DC56C0 /* MenuListViewModel.swift */; };
1ECF2E812632A70F006982BE /* LoadingView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 1ECF2E802632A70F006982BE /* LoadingView.xib */; };
1ECF2E842632A862006982BE /* LoadingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECF2E832632A862006982BE /* LoadingView.swift */; };
1ECF2EBC2635D6FD006982BE /* MenuRepository.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECF2EBB2635D6FD006982BE /* MenuRepository.swift */; };
1ECF2EC02635DE65006982BE /* CoreData.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 1ECF2EBE2635DE65006982BE /* CoreData.xcdatamodeld */; };
1ECF2EC32635E2EC006982BE /* CoreDataMenuResponseStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1ECF2EC22635E2EC006982BE /* CoreDataMenuResponseStorage.swift */; };
B0911E6F262EA29200D5EBEC /* DishCardCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0911E6E262EA29200D5EBEC /* DishCardCell.swift */; };
B04466292636911D00DAD616 /* DishCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = B04466272636911D00DAD616 /* DishCell.swift */; };
B044662A2636911D00DAD616 /* DishCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = B04466282636911D00DAD616 /* DishCell.xib */; };
Expand All @@ -39,6 +44,8 @@
1E1DBADA262DDDFD0050FE6C /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
1E1DBADD262DDDFD0050FE6C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
1E1DBADF262DDDFD0050FE6C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; name = Info.plist; path = ../Info.plist; sourceTree = "<group>"; };
1E5053C52636F504005615F5 /* DishesEntity+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "DishesEntity+CoreDataClass.swift"; path = "/Users/ohking/Desktop/masters_codesquad/sidedish/SideDishApp/SideDishApp/Data/Persistence/DishesEntity+CoreDataClass.swift"; sourceTree = "<absolute>"; };
1E5053C72636F504005615F5 /* DishesEntity+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "DishesEntity+CoreDataProperties.swift"; path = "/Users/ohking/Desktop/masters_codesquad/sidedish/SideDishApp/SideDishApp/Data/Persistence/DishesEntity+CoreDataProperties.swift"; sourceTree = "<absolute>"; };
1ECD5F61262F256000DC56C0 /* Endpoint.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = "<group>"; };
1ECD5F65262F2E1E00DC56C0 /* NetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkManager.swift; sourceTree = "<group>"; };
1ECD5F69262F3B6500DC56C0 /* DishNetworkManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DishNetworkManager.swift; sourceTree = "<group>"; };
Expand All @@ -47,6 +54,9 @@
1ECD5F72262F405100DC56C0 /* MenuListViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuListViewModel.swift; sourceTree = "<group>"; };
1ECF2E802632A70F006982BE /* LoadingView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = LoadingView.xib; sourceTree = "<group>"; };
1ECF2E832632A862006982BE /* LoadingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoadingView.swift; sourceTree = "<group>"; };
1ECF2EBB2635D6FD006982BE /* MenuRepository.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuRepository.swift; sourceTree = "<group>"; };
1ECF2EBF2635DE65006982BE /* CoreData.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = CoreData.xcdatamodel; sourceTree = "<group>"; };
1ECF2EC22635E2EC006982BE /* CoreDataMenuResponseStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoreDataMenuResponseStorage.swift; sourceTree = "<group>"; };
4942C5A177086C5C99933038 /* Pods-SideDishApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SideDishApp.debug.xcconfig"; path = "Target Support Files/Pods-SideDishApp/Pods-SideDishApp.debug.xcconfig"; sourceTree = "<group>"; };
605A37FD869863C7E023EE85 /* Pods-SideDishApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SideDishApp.release.xcconfig"; path = "Target Support Files/Pods-SideDishApp/Pods-SideDishApp.release.xcconfig"; sourceTree = "<group>"; };
96A87B12151B0D006007CD63 /* Pods_SideDishApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_SideDishApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -111,6 +121,10 @@
1E1DBAE6262DDE040050FE6C /* Persistence */ = {
isa = PBXGroup;
children = (
1E5053C52636F504005615F5 /* DishesEntity+CoreDataClass.swift */,
1E5053C72636F504005615F5 /* DishesEntity+CoreDataProperties.swift */,
1ECF2EBE2635DE65006982BE /* CoreData.xcdatamodeld */,
1ECF2EC22635E2EC006982BE /* CoreDataMenuResponseStorage.swift */,
);
path = Persistence;
sourceTree = "<group>";
Expand Down Expand Up @@ -156,6 +170,7 @@
1E1DBAEB262DDE4B0050FE6C /* Repository */ = {
isa = PBXGroup;
children = (
1ECF2EBB2635D6FD006982BE /* MenuRepository.swift */,
);
path = Repository;
sourceTree = "<group>";
Expand Down Expand Up @@ -370,17 +385,22 @@
files = (
1ECD5F6D262F3C1700DC56C0 /* Dish.swift in Sources */,
B0911EA026316B9A00D5EBEC /* String+Extension.swift in Sources */,
1ECF2EC02635DE65006982BE /* CoreData.xcdatamodeld in Sources */,
1ECF2EBC2635D6FD006982BE /* MenuRepository.swift in Sources */,
1E1DBAD6262DDDFC0050FE6C /* ViewController.swift in Sources */,
1ECD5F70262F3F1C00DC56C0 /* MenuListUseCase.swift in Sources */,
1ECD5F6A262F3B6500DC56C0 /* DishNetworkManager.swift in Sources */,
1E5053C82636F504005615F5 /* DishesEntity+CoreDataProperties.swift in Sources */,
B04466292636911D00DAD616 /* DishCell.swift in Sources */,
1E1DBAD2262DDDFC0050FE6C /* AppDelegate.swift in Sources */,
1ECF2EC32635E2EC006982BE /* CoreDataMenuResponseStorage.swift in Sources */,
1ECD5F66262F2E1E00DC56C0 /* NetworkManager.swift in Sources */,
1ECD5F62262F256000DC56C0 /* Endpoint.swift in Sources */,
B0911EA42631AF3400D5EBEC /* DiffableProvider.swift in Sources */,
B0911EA82632B7A100D5EBEC /* DishCollectionViewDelegate.swift in Sources */,
1E1DBAD4262DDDFC0050FE6C /* SceneDelegate.swift in Sources */,
1ECF2E842632A862006982BE /* LoadingView.swift in Sources */,
1E5053C92636F504005615F5 /* DishesEntity+CoreDataClass.swift in Sources */,
1ECD5F73262F405100DC56C0 /* MenuListViewModel.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -583,6 +603,19 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCVersionGroup section */
1ECF2EBE2635DE65006982BE /* CoreData.xcdatamodeld */ = {
isa = XCVersionGroup;
children = (
1ECF2EBF2635DE65006982BE /* CoreData.xcdatamodel */,
);
currentVersion = 1ECF2EBF2635DE65006982BE /* CoreData.xcdatamodel */;
path = CoreData.xcdatamodeld;
sourceTree = "<group>";
versionGroupType = wrapper.xcdatamodel;
};
/* End XCVersionGroup section */
};
rootObject = 1E1DBAC6262DDDFC0050FE6C /* Project object */;
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<key>SideDishApp.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
<integer>2</integer>
</dict>
</dict>
</dict>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,105 @@
startingLineNumber = "36"
endingLineNumber = "36"
landmarkName = "setLoadingView()"
<<<<<<< HEAD
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "4F83E090-7FC5-43DA-AE9C-A04C07969516"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SideDishApp/Data/Network/NetworkManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "22"
endingLineNumber = "22"
landmarkName = "get(url:completion:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "9C7CE4A8-E875-4643-AFE7-42E505C743F8"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SideDishApp/Data/Network/NetworkManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "35"
endingLineNumber = "35"
landmarkName = "get(url:completion:)"
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "7419D406-B14F-429B-AF44-B38479ECF28F"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SideDishApp/Data/Network/NetworkManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "25"
endingLineNumber = "25"
landmarkName = "get(url:completion:)"
landmarkType = "7">
<Locations>
<Location
uuid = "7419D406-B14F-429B-AF44-B38479ECF28F - 446506456e93e6b6"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "SideDishApp.NetworkManager.get&lt;A where A: Swift.Decodable&gt;(url: Swift.Optional&lt;Foundation.URL&gt;, completion: (Swift.Result&lt;Foundation.Data, SideDishApp.NetworkError&gt;) -&gt; ()) -&gt; Combine.AnyPublisher&lt;A, SideDishApp.NetworkError&gt;"
moduleName = "SideDishApp"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/ohking/Desktop/masters_codesquad/sidedish/SideDishApp/SideDishApp/Data/Network/NetworkManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "25"
endingLineNumber = "25"
offsetFromSymbolStart = "1232">
</Location>
<Location
uuid = "7419D406-B14F-429B-AF44-B38479ECF28F - b556638f71ad593"
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
symbolName = "closure #2 (Foundation.Data, __C.NSURLResponse) -&gt; Combine.AnyPublisher&lt;A, SideDishApp.NetworkError&gt; in SideDishApp.NetworkManager.get&lt;A where A: Swift.Decodable&gt;(url: Swift.Optional&lt;Foundation.URL&gt;, completion: (Swift.Result&lt;Foundation.Data, SideDishApp.NetworkError&gt;) -&gt; ()) -&gt; Combine.AnyPublisher&lt;A, SideDishApp.NetworkError&gt;"
moduleName = "SideDishApp"
usesParentBreakpointCondition = "Yes"
urlString = "file:///Users/ohking/Desktop/masters_codesquad/sidedish/SideDishApp/SideDishApp/Data/Network/NetworkManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "26"
endingLineNumber = "26"
offsetFromSymbolStart = "727">
</Location>
</Locations>
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
uuid = "382E92C7-C346-4A37-9FBC-406221A498C7"
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "SideDishApp/Data/Network/NetworkManager.swift"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "27"
endingLineNumber = "27"
landmarkName = "get(url:completion:)"
=======
>>>>>>> Dev-iOS
landmarkType = "7">
</BreakpointContent>
</BreakpointProxy>
Expand Down
1 change: 1 addition & 0 deletions SideDishApp/SideDishApp/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//

import UIKit
import CoreData

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
Expand Down
10 changes: 6 additions & 4 deletions SideDishApp/SideDishApp/Data/Network/DishNetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation
import Combine

protocol DishNetworkManageable {
func getDishes(path: String) -> AnyPublisher<[Dishes], NetworkError>
func getDishes(path: String, completion: @escaping (Result<Data, NetworkError>) -> Void) -> AnyPublisher<[Dishes], NetworkError>
}

class DishNetworkManager: DishNetworkManageable {
Expand All @@ -24,9 +24,11 @@ class DishNetworkManager: DishNetworkManageable {
self.init(networkManager: networkManager)
}

func getDishes(path: String) -> AnyPublisher<[Dishes], NetworkError> {
func getDishes(path: String, completion: @escaping (Result<Data, NetworkError>) -> Void) -> AnyPublisher<[Dishes], NetworkError> {
let url = Endpoint.get(path: path).url

return networkManager.get(url: url)

return networkManager.get(url: url) { data in
completion(data)
}
}
}
14 changes: 9 additions & 5 deletions SideDishApp/SideDishApp/Data/Network/NetworkManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,34 @@ import Foundation
import Combine

protocol NetworkManageable {
func get<T>(url: URL?) -> AnyPublisher<T, NetworkError> where T: Decodable
func get<T>(url: URL?, completion: @escaping (Result<Data, NetworkError>) -> Void) -> AnyPublisher<T, NetworkError> where T: Decodable
}

class NetworkManager: NetworkManageable {

func get<T>(url: URL?) -> AnyPublisher<T, NetworkError> where T: Decodable {
func get<T>(url: URL?, completion: @escaping (Result<Data, NetworkError>) -> Void) -> AnyPublisher<T, NetworkError> where T: Decodable {
guard let myUrl = url else {

return Fail(error: NetworkError.urlError).eraseToAnyPublisher()
}

return URLSession.shared.dataTaskPublisher(for: myUrl)
.mapError { _ in NetworkError.networkConnection }

.flatMap { data, response -> AnyPublisher<T, NetworkError> in

guard let httpResponse = response as? HTTPURLResponse else {
return Fail(error: NetworkError.responseNil).eraseToAnyPublisher()
}

guard 200..<300 ~= httpResponse.statusCode else {
return Fail(error: NetworkError.unknown).eraseToAnyPublisher()
}
return Just(data)

completion(.success(data))
let decodeData = Just(data)
.decode(type: T.self, decoder: JSONDecoder())
.mapError { _ in NetworkError.parsing }.eraseToAnyPublisher()
return decodeData
}.eraseToAnyPublisher()
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="17709" systemVersion="20C69" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="DishesEntity" representedClassName="DishesEntity" syncable="YES">
<attribute name="category" optional="YES" attributeType="String"/>
<attribute name="dishes" optional="YES" attributeType="Transformable" valueTransformerName="" customClassName="[Dish]"/>
<attribute name="name" optional="YES" attributeType="String"/>
</entity>
<elements>
<element name="DishesEntity" positionX="252.40869140625" positionY="76.66534423828125" width="128" height="74"/>
</elements>
</model>
Loading

0 comments on commit 7fa457a

Please sign in to comment.