Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4차 세미나 과제 #8

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
89 changes: 89 additions & 0 deletions 32th-Sopt-Seminar/32th-Sopt-Seminar.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@
DF1841762A052D37001A466A /* MyPassView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841752A052D37001A466A /* MyPassView.swift */; };
DF1841792A052ED4001A466A /* BuyPassView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841782A052ED4001A466A /* BuyPassView.swift */; };
DF18417B2A052FFD001A466A /* UILabel+.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF18417A2A052FFD001A466A /* UILabel+.swift */; };
DF18417E2A062437001A466A /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = DF18417D2A062437001A466A /* Alamofire */; };
DF1841812A062548001A466A /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841802A062548001A466A /* Config.swift */; };
DF1841832A06257B001A466A /* NetworkResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841822A06257B001A466A /* NetworkResult.swift */; };
DF1841852A06282E001A466A /* SignUpService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841842A06282E001A466A /* SignUpService.swift */; };
DF1841872A0628F2001A466A /* ViewController_FourthSeminar.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841862A0628F2001A466A /* ViewController_FourthSeminar.swift */; };
DF1841892A062969001A466A /* SignUpResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841882A062969001A466A /* SignUpResponse.swift */; };
DF18418B2A0DF337001A466A /* Weathers.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF18418A2A0DF336001A466A /* Weathers.swift */; };
DF18418D2A0DF4F8001A466A /* CurrentWeatherService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF18418C2A0DF4F8001A466A /* CurrentWeatherService.swift */; };
DF18418F2A0E00AA001A466A /* ViewController_WeatherAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF18418E2A0E00AA001A466A /* ViewController_WeatherAPI.swift */; };
DF1841912A0E668B001A466A /* MovieInformation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841902A0E668B001A466A /* MovieInformation.swift */; };
DF1841932A0E6C08001A466A /* MovieInformationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841922A0E6C08001A466A /* MovieInformationService.swift */; };
DF1841952A0E6F30001A466A /* ViewController_TMDBAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841942A0E6F30001A466A /* ViewController_TMDBAPI.swift */; };
DF1841972A0E7A17001A466A /* MovieTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841962A0E7A17001A466A /* MovieTableViewCell.swift */; };
DF1841992A0E8026001A466A /* MovieDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF1841982A0E8026001A466A /* MovieDataModel.swift */; };
DF18419B2A0E831A001A466A /* ImageCacheManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF18419A2A0E831A001A466A /* ImageCacheManager.swift */; };
DF93B64029E133E400A1CBD0 /* FirstViewController_DelegatePattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF93B63F29E133E400A1CBD0 /* FirstViewController_DelegatePattern.swift */; };
DF93B64229E1344F00A1CBD0 /* SecondViewController_DelegatePattern.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF93B64129E1344F00A1CBD0 /* SecondViewController_DelegatePattern.swift */; };
DF93B64429E1386600A1CBD0 /* FirstViewController_Closure.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF93B64329E1386600A1CBD0 /* FirstViewController_Closure.swift */; };
Expand Down Expand Up @@ -85,6 +100,20 @@
DF1841752A052D37001A466A /* MyPassView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyPassView.swift; sourceTree = "<group>"; };
DF1841782A052ED4001A466A /* BuyPassView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BuyPassView.swift; sourceTree = "<group>"; };
DF18417A2A052FFD001A466A /* UILabel+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UILabel+.swift"; sourceTree = "<group>"; };
DF1841802A062548001A466A /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = "<group>"; };
DF1841822A06257B001A466A /* NetworkResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkResult.swift; sourceTree = "<group>"; };
DF1841842A06282E001A466A /* SignUpService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpService.swift; sourceTree = "<group>"; };
DF1841862A0628F2001A466A /* ViewController_FourthSeminar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController_FourthSeminar.swift; sourceTree = "<group>"; };
DF1841882A062969001A466A /* SignUpResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SignUpResponse.swift; sourceTree = "<group>"; };
DF18418A2A0DF336001A466A /* Weathers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Weathers.swift; sourceTree = "<group>"; };
DF18418C2A0DF4F8001A466A /* CurrentWeatherService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CurrentWeatherService.swift; sourceTree = "<group>"; };
DF18418E2A0E00AA001A466A /* ViewController_WeatherAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController_WeatherAPI.swift; sourceTree = "<group>"; };
DF1841902A0E668B001A466A /* MovieInformation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieInformation.swift; sourceTree = "<group>"; };
DF1841922A0E6C08001A466A /* MovieInformationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieInformationService.swift; sourceTree = "<group>"; };
DF1841942A0E6F30001A466A /* ViewController_TMDBAPI.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController_TMDBAPI.swift; sourceTree = "<group>"; };
DF1841962A0E7A17001A466A /* MovieTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieTableViewCell.swift; sourceTree = "<group>"; };
DF1841982A0E8026001A466A /* MovieDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieDataModel.swift; sourceTree = "<group>"; };
DF18419A2A0E831A001A466A /* ImageCacheManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageCacheManager.swift; sourceTree = "<group>"; };
DF93B63F29E133E400A1CBD0 /* FirstViewController_DelegatePattern.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController_DelegatePattern.swift; sourceTree = "<group>"; };
DF93B64129E1344F00A1CBD0 /* SecondViewController_DelegatePattern.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecondViewController_DelegatePattern.swift; sourceTree = "<group>"; };
DF93B64329E1386600A1CBD0 /* FirstViewController_Closure.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstViewController_Closure.swift; sourceTree = "<group>"; };
Expand All @@ -107,6 +136,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
DF18417E2A062437001A466A /* Alamofire in Frameworks */,
DF93B64B29E13ED200A1CBD0 /* SnapKit in Frameworks */,
DF93B64E29E141ED00A1CBD0 /* Then in Frameworks */,
);
Expand Down Expand Up @@ -297,6 +327,27 @@
path = Cell;
sourceTree = "<group>";
};
DF18417F2A062530001A466A /* Fourth-Seminar */ = {
isa = PBXGroup;
children = (
DF1841802A062548001A466A /* Config.swift */,
DF1841822A06257B001A466A /* NetworkResult.swift */,
DF1841842A06282E001A466A /* SignUpService.swift */,
DF1841862A0628F2001A466A /* ViewController_FourthSeminar.swift */,
DF1841882A062969001A466A /* SignUpResponse.swift */,
DF18418A2A0DF336001A466A /* Weathers.swift */,
DF18418C2A0DF4F8001A466A /* CurrentWeatherService.swift */,
DF18418E2A0E00AA001A466A /* ViewController_WeatherAPI.swift */,
DF1841902A0E668B001A466A /* MovieInformation.swift */,
DF1841922A0E6C08001A466A /* MovieInformationService.swift */,
DF1841942A0E6F30001A466A /* ViewController_TMDBAPI.swift */,
DF1841962A0E7A17001A466A /* MovieTableViewCell.swift */,
DF1841982A0E8026001A466A /* MovieDataModel.swift */,
DF18419A2A0E831A001A466A /* ImageCacheManager.swift */,
);
path = "Fourth-Seminar";
sourceTree = "<group>";
};
DF93B64729E13B7200A1CBD0 /* First-Seminar */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -346,6 +397,7 @@
DF93B64729E13B7200A1CBD0 /* First-Seminar */,
DF93B64829E13B9900A1CBD0 /* Second-Seminar */,
DF18411D29F3A942001A466A /* Third-Seminar */,
DF18417F2A062530001A466A /* Fourth-Seminar */,
);
path = "32th-Sopt-Seminar";
sourceTree = "<group>";
Expand All @@ -369,6 +421,7 @@
packageProductDependencies = (
DF93B64A29E13ED200A1CBD0 /* SnapKit */,
DF93B64D29E141ED00A1CBD0 /* Then */,
DF18417D2A062437001A466A /* Alamofire */,
);
productName = "32th-Sopt-First-Seminar";
productReference = DFA4A01529D8095100BFB46A /* 32th-Sopt-Seminar.app */;
Expand Down Expand Up @@ -401,6 +454,7 @@
packageReferences = (
DF93B64929E13ED200A1CBD0 /* XCRemoteSwiftPackageReference "SnapKit" */,
DF93B64C29E141ED00A1CBD0 /* XCRemoteSwiftPackageReference "Then" */,
DF18417C2A062437001A466A /* XCRemoteSwiftPackageReference "Alamofire" */,
);
productRefGroup = DFA4A01629D8095100BFB46A /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -437,24 +491,33 @@
DF18414A29FA6BFA001A466A /* Image.swift in Sources */,
DF18412D29F3B744001A466A /* CarrotTableViewCell.swift in Sources */,
DF1841592A0422D3001A466A /* BaseView.swift in Sources */,
DF1841912A0E668B001A466A /* MovieInformation.swift in Sources */,
DF1841602A04E1AA001A466A /* MyPage.swift in Sources */,
DF18412929F3AD9F001A466A /* CommonView.swift in Sources */,
DF1841992A0E8026001A466A /* MovieDataModel.swift in Sources */,
DF18413029F3B885001A466A /* Carrot.swift in Sources */,
DF1841722A052BF9001A466A /* MyPageHeaderView.swift in Sources */,
DF1841792A052ED4001A466A /* BuyPassView.swift in Sources */,
DF1841702A052611001A466A /* MyPageModel.swift in Sources */,
DF18412529F3ABC6001A466A /* FirstViewController_ThirdSeminar.swift in Sources */,
DF93B64629E1389600A1CBD0 /* SecondViewController_Closure.swift in Sources */,
DFA4A01D29D8095100BFB46A /* ViewController.swift in Sources */,
DF1841972A0E7A17001A466A /* MovieTableViewCell.swift in Sources */,
DF93B64029E133E400A1CBD0 /* FirstViewController_DelegatePattern.swift in Sources */,
DF93B65629E152E500A1CBD0 /* FirstViewController_Practice1.swift in Sources */,
DF1841762A052D37001A466A /* MyPassView.swift in Sources */,
DF1841672A04FCFE001A466A /* UINavigationItem+.swift in Sources */,
DF18416C2A052195001A466A /* UITableView+.swift in Sources */,
DF18418F2A0E00AA001A466A /* ViewController_WeatherAPI.swift in Sources */,
DF1841932A0E6C08001A466A /* MovieInformationService.swift in Sources */,
DF1841872A0628F2001A466A /* ViewController_FourthSeminar.swift in Sources */,
DF1841572A04220B001A466A /* BaseViewController.swift in Sources */,
DF1841952A0E6F30001A466A /* ViewController_TMDBAPI.swift in Sources */,
DF18413729F3C86C001A466A /* UIView+.swift in Sources */,
DFA4A01929D8095100BFB46A /* AppDelegate.swift in Sources */,
DFA4A02D29D80BAA00BFB46A /* FirstViewController_1st_Seminar.swift in Sources */,
DF18419B2A0E831A001A466A /* ImageCacheManager.swift in Sources */,
DF18418D2A0DF4F8001A466A /* CurrentWeatherService.swift in Sources */,
DF18414629FA67CB001A466A /* Color.swift in Sources */,
DF18415B2A042E5A001A466A /* Int+.swift in Sources */,
DF93B64229E1344F00A1CBD0 /* SecondViewController_DelegatePattern.swift in Sources */,
Expand All @@ -464,9 +527,14 @@
DF1841742A052C83001A466A /* MyProfileView.swift in Sources */,
DF18416E2A052235001A466A /* NSObject+.swift in Sources */,
DF18415D2A043575001A466A /* MyPageViewController.swift in Sources */,
DF18418B2A0DF337001A466A /* Weathers.swift in Sources */,
DFA4A02F29D8105400BFB46A /* SecondViewController_1st_Seminar.swift in Sources */,
DF1841892A062969001A466A /* SignUpResponse.swift in Sources */,
DF18413529F3BCC3001A466A /* UIImage+.swift in Sources */,
DFA4A01B29D8095100BFB46A /* SceneDelegate.swift in Sources */,
DF1841852A06282E001A466A /* SignUpService.swift in Sources */,
DF1841812A062548001A466A /* Config.swift in Sources */,
DF1841832A06257B001A466A /* NetworkResult.swift in Sources */,
DF18412B29F3B549001A466A /* CarrotViewController.swift in Sources */,
DF1841652A04ED3D001A466A /* MyPageTableViewCell.swift in Sources */,
);
Expand Down Expand Up @@ -605,6 +673,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
BASE_URL = "http://54.180.123.11";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8MTU4Q38X7;
Expand All @@ -624,6 +693,9 @@
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TMDB_URL = "https://api.themoviedb.org/3/search/movie?api_key=182d505d38c0dff20137f9a1ffc44888&query=";
WEATHER_API = 2e4e7c115a23a0ec023cd170849b696a;
WEATHER_URL = "https://api.openweathermap.org/data/2.5/weather?";
};
name = Debug;
};
Expand All @@ -632,6 +704,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
BASE_URL = "http://54.180.123.11";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 8MTU4Q38X7;
Expand All @@ -651,6 +724,9 @@
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
TMDB_URL = "https://api.themoviedb.org/3/search/movie?api_key=182d505d38c0dff20137f9a1ffc44888&query=";
WEATHER_API = 2e4e7c115a23a0ec023cd170849b696a;
WEATHER_URL = "https://api.openweathermap.org/data/2.5/weather?";
};
name = Release;
};
Expand Down Expand Up @@ -678,6 +754,14 @@
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
DF18417C2A062437001A466A /* XCRemoteSwiftPackageReference "Alamofire" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/Alamofire/Alamofire.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.0.0;
};
};
DF93B64929E13ED200A1CBD0 /* XCRemoteSwiftPackageReference "SnapKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/SnapKit/SnapKit.git";
Expand All @@ -697,6 +781,11 @@
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
DF18417D2A062437001A466A /* Alamofire */ = {
isa = XCSwiftPackageProductDependency;
package = DF18417C2A062437001A466A /* XCRemoteSwiftPackageReference "Alamofire" */;
productName = Alamofire;
};
DF93B64A29E13ED200A1CBD0 /* SnapKit */ = {
isa = XCSwiftPackageProductDependency;
package = DF93B64929E13ED200A1CBD0 /* XCRemoteSwiftPackageReference "SnapKit" */;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
{
"pins" : [
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"revision" : "78424be314842833c04bc3bef5b72e85fff99204",
"version" : "5.6.4"
}
},
{
"identity" : "snapkit",
"kind" : "remoteSourceControl",
Expand Down
2 changes: 1 addition & 1 deletion 32th-Sopt-Seminar/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// 2.
self.window = UIWindow(windowScene: windowScene)
// 3.
let navigationController = UINavigationController(rootViewController: MyPageViewController())
let navigationController = UINavigationController(rootViewController: ViewController_TMDBAPI())
self.window?.rootViewController = navigationController
// 4.
self.window?.makeKeyAndVisible()
Expand Down
13 changes: 13 additions & 0 deletions 32th-Sopt-Seminar/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>TMDB_URL</key>
<string>$(TMDB_URL)</string>
<key>WEATHER_API</key>
<string>$(WEATHER_API)</string>
<key>WEATHER_URL</key>
<string>$(WEATHER_URL)</string>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// Config.swift
// 32th-Sopt-Seminar
//
// Created by kyun on 2023/05/06.
//

import Foundation

enum Config {
enum Keys {
enum Plist {
static let baseURL = "BASE_URL"
static let weatherURL = "WEATHER_URL"
static let weatherAPI = "WEATHER_API"
static let tmdbURL = "TMDB_URL"
}
}

private static let infoDictionary: [String: Any] = {
guard let dict = Bundle.main.infoDictionary else {
fatalError("plist cannot found.")
}

return dict
}()
}

extension Config {

static let baseURL: String = {
guard let key = Config.infoDictionary[Keys.Plist.baseURL] as? String else {
fatalError("Base URL is not set in plist for this configuration.")
}

return key
}()

static let weatherURL: String = {
guard let key = Config.infoDictionary[Keys.Plist.weatherURL] as? String else {
fatalError("Weather URL is not set in plist for this configuration.")
}

return key
}()

static let weatherAPI: String = {
guard let key = Config.infoDictionary[Keys.Plist.weatherAPI] as? String else {
fatalError("Weather API is not set in plist for this configuration.")
}

return key
}()

static let tmdbURL: String = {
guard let key = Config.infoDictionary[Keys.Plist.tmdbURL] as? String else {
fatalError("TMDB URL is not set in plist for this configuration.")
}

return key
}()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
//
// CurrentWeatherService.swift
// 32th-Sopt-Seminar
//
// Created by kyun on 2023/05/12.
//

import Foundation

import Alamofire

final class CurrentWeatherService {

static let get = CurrentWeatherService()

private init() {}

func loadWeather(city: String,
completion: @escaping (NetworkResult<Any>) -> Void) {

let url = Config.weatherURL + "q=\(city)&appid=" + Config.weatherAPI

let header: HTTPHeaders = ["Content-Type" : "application/json"]

let dataRequest = AF.request(url, method: .get, headers: header)

dataRequest.responseData { response in
switch response.result {
case .success:
guard let statusCode = response.response?.statusCode else { return }
guard let value = response.value else { return }
let networkResult = self.judgeStatus(by: statusCode, value)
completion(networkResult)
case .failure:
completion(.networkErr)
}
}
}

private func judgeStatus(by statusCode: Int, _ data: Data) -> NetworkResult<Any> {

switch statusCode {
case 200:
return isValidData(data: data)
case 400, 409:
return isValidData(data: data)
case 500:
return .serverErr
default:
return .networkErr
}
}

private func isValidData(data: Data) -> NetworkResult<Any> {

let decoder = JSONDecoder()

guard let decodedData = try? decoder.decode(Weathers.self, from: data) else { return .pathErr }

return .success(decodedData as Any)
}
}
Loading