-
Notifications
You must be signed in to change notification settings - Fork 0
[루시] 5주차 미션 #22
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
base: main
Are you sure you want to change the base?
[루시] 5주차 미션 #22
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// AppDelegate.swift | ||
// networkexiercise | ||
// | ||
// Created by 김수민 on 2023/11/19. | ||
// | ||
|
||
import UIKit | ||
|
||
@main | ||
class AppDelegate: UIResponder, UIApplicationDelegate { | ||
|
||
|
||
|
||
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { | ||
// Override point for customization after application launch. | ||
return true | ||
} | ||
|
||
// MARK: UISceneSession Lifecycle | ||
|
||
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { | ||
// Called when a new scene session is being created. | ||
// Use this method to select a configuration to create the new scene with. | ||
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) | ||
} | ||
|
||
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) { | ||
// Called when the user discards a scene session. | ||
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. | ||
// Use this method to release any resources that were specific to the discarded scenes, as they will not return. | ||
} | ||
|
||
|
||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"colors" : [ | ||
{ | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"platform" : "ios", | ||
"size" : "1024x1024" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="01J-lp-oVM"> | ||
<dependencies> | ||
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13104.12"/> | ||
<capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--View Controller--> | ||
<scene sceneID="EHf-IW-A2E"> | ||
<objects> | ||
<viewController id="01J-lp-oVM" sceneMemberID="viewController"> | ||
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3"> | ||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
<color key="backgroundColor" xcode11CocoaTouchSystemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> | ||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/> | ||
</view> | ||
</viewController> | ||
<placeholder placeholderIdentifier="IBFirstResponder" id="iYj-Kq-Ea1" userLabel="First Responder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="53" y="375"/> | ||
</scene> | ||
</scenes> | ||
</document> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>UIApplicationSceneManifest</key> | ||
<dict> | ||
<key>UIApplicationSupportsMultipleScenes</key> | ||
<false/> | ||
<key>UISceneConfigurations</key> | ||
<dict> | ||
<key>UIWindowSceneSessionRoleApplication</key> | ||
<array> | ||
<dict> | ||
<key>UISceneConfigurationName</key> | ||
<string>Default Configuration</string> | ||
<key>UISceneDelegateClassName</key> | ||
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string> | ||
</dict> | ||
</array> | ||
</dict> | ||
</dict> | ||
</dict> | ||
</plist> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// weather.swift | ||
// networkexiercise | ||
// | ||
// Created by 김수민 on 2023/11/19. | ||
// | ||
|
||
import Foundation | ||
|
||
struct weather: Decodable { | ||
var lat: Double | ||
var lon: Double | ||
var timezone: String | ||
var timezone_offset: Int | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// | ||
// SceneDelegate.swift | ||
// WeekFour | ||
// | ||
// Created by 김수민 on 2023/11/09. | ||
// | ||
|
||
|
||
import UIKit | ||
|
||
class SceneDelegate: UIResponder, UIWindowSceneDelegate { | ||
|
||
var window: UIWindow? | ||
|
||
|
||
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { | ||
guard let windowScene = (scene as? UIWindowScene) else { return } | ||
window = UIWindow(windowScene: windowScene) // SceneDelegate의 프로퍼티에 설정해줌 | ||
let mainViewController = ViewController() // 맨 처음 보여줄 ViewController | ||
|
||
window?.rootViewController = mainViewController | ||
window?.makeKeyAndVisible() | ||
} | ||
|
||
|
||
func sceneDidDisconnect(_ scene: UIScene) { | ||
// Called as the scene is being released by the system. | ||
// This occurs shortly after the scene enters the background, or when its session is discarded. | ||
// Release any resources associated with this scene that can be re-created the next time the scene connects. | ||
// The scene may re-connect later, as its session was not necessarily discarded (see `application:didDiscardSceneSessions` instead). | ||
} | ||
|
||
func sceneDidBecomeActive(_ scene: UIScene) { | ||
// Called when the scene has moved from an inactive state to an active state. | ||
// Use this method to restart any tasks that were paused (or not yet started) when the scene was inactive. | ||
} | ||
|
||
func sceneWillResignActive(_ scene: UIScene) { | ||
// Called when the scene will move from an active state to an inactive state. | ||
// This may occur due to temporary interruptions (ex. an incoming phone call). | ||
} | ||
|
||
func sceneWillEnterForeground(_ scene: UIScene) { | ||
// Called as the scene transitions from the background to the foreground. | ||
// Use this method to undo the changes made on entering the background. | ||
} | ||
|
||
func sceneDidEnterBackground(_ scene: UIScene) { | ||
// Called as the scene transitions from the foreground to the background. | ||
// Use this method to save data, release shared resources, and store enough scene-specific state information | ||
// to restore the scene back to its current state. | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// | ||
// ViewController.swift | ||
// networkexiercise | ||
// | ||
// Created by 김수민 on 2023/11/19. | ||
// | ||
import SnapKit | ||
import UIKit | ||
import Moya | ||
class ViewController: UIViewController { | ||
let apiKey = "206b9ba8742999c6453ebc8907feef22" // OpenWeatherMap에서 발급받은 API 키를 사용해야 합니다. | ||
let provider = MoyaProvider<WeatherAPI>() | ||
|
||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
configUI() | ||
layout() | ||
setAPIValue() | ||
} | ||
|
||
var testTextview: UITextView { | ||
let textView = UITextView() | ||
textView.frame = CGRect(x: 20, y: 100, width: 300, height: 200) | ||
textView.font = UIFont.systemFont(ofSize: 16) | ||
textView.text = "안녕하세요, UITextView 예제입니다." | ||
return textView | ||
} | ||
|
||
var apiButton: UIButton { | ||
let apiButton = UIButton(type: .system) // 시스템 버튼으로 초기화 | ||
apiButton.setTitle("버튼", for: .normal) | ||
apiButton.backgroundColor = .blue | ||
return apiButton | ||
} | ||
|
||
func configUI() { | ||
view.addSubview(testTextview) | ||
view.addSubview(apiButton) | ||
} | ||
|
||
func layout(){ | ||
apiButton.snp.makeConstraints { make in | ||
// make.top.equalTo(testTextview.snp.bottom).offset(10) // 텍스트 뷰 아래로 10포인트 떨어짐 | ||
make.centerX.equalToSuperview() | ||
} | ||
apiButton.snp.makeConstraints { make in | ||
// make.top.equalTo(testTextview.snp.bottom).offset(10) // 텍스트 뷰 아래로 10포인트 떨어짐 | ||
make.centerX.equalToSuperview() | ||
} | ||
Comment on lines
+47
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. apiButton만 두번 되어 있어요 |
||
} | ||
|
||
|
||
|
||
// API 호출 예제 | ||
func setAPIValue(){ | ||
|
||
provider.request(.oneCall(lat: 37.7749, lon: -122.4194, exclude: ["current", "minutely", "hourly", "daily", "alerts"], apiKey: self.apiKey)) { result in | ||
switch result { | ||
case let .success(response): | ||
// API 요청이 성공한 경우 처리 | ||
print(response) | ||
let result = try? response.map(weather.self) | ||
if let result = result?.timezone { | ||
self.testTextview.text = result | ||
print(result) | ||
} | ||
case let .failure(error): | ||
// API 요청이 실패한 경우 처리 | ||
print(error) | ||
} | ||
} | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// | ||
// weatherAPI.swift | ||
// networkexiercise | ||
// | ||
// Created by 김수민 on 2023/11/19. | ||
// | ||
|
||
import Foundation | ||
import Moya | ||
|
||
enum WeatherAPI { | ||
case oneCall(lat: Double, lon: Double, exclude: [String], apiKey: String) | ||
} | ||
|
||
extension WeatherAPI: TargetType { | ||
var baseURL: URL { | ||
return URL(string: "https://api.openweathermap.org/data/3.0")! | ||
} | ||
|
||
var path: String { | ||
switch self { | ||
case .oneCall: | ||
return "/onecall" | ||
} | ||
} | ||
|
||
var method: Moya.Method { | ||
return .get | ||
} | ||
|
||
var sampleData: Data { | ||
return Data() | ||
} | ||
|
||
var task: Task { | ||
switch self { | ||
case let .oneCall(lat, lon, exclude, apiKey): | ||
return .requestParameters(parameters: ["lat": lat, "lon": lon, "exclude": exclude, "appid": apiKey], encoding: URLEncoding.default) | ||
} | ||
} | ||
|
||
var headers: [String: String]? { | ||
return ["Content-type": "application/json"] | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
프로퍼티 선언이 잘못 돼서 시뮬레이션이 튕겨요!
값을 불러오는 거니까 UILabel을 사용하는 게 더 좋을 것 같아요