Skip to content

[루시] 6주차 미션 ~ 10주차 미션 #41

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

Open
wants to merge 2 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
Binary file not shown.
425 changes: 425 additions & 0 deletions SixthWorkbook/SixthWorkbook.xcodeproj/project.pbxproj

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.

45 changes: 45 additions & 0 deletions SixthWorkbook/SixthWorkbook/APIExercise_SwiftUI/WeatherAPI.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// WeatherAPI.swift
// SixthWorkbook
//
// Created by 김수민 on 2023/12/09.
//

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"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// WeatherAPIView.swift
// SixthWorkbook
//
// Created by 김수민 on 2023/12/09.
//

import SwiftUI
import Moya

struct WeatherAPIView: View {
let apiKey = "206b9ba8742999c6453ebc8907feef22"
let provider = MoyaProvider<WeatherAPI>()

@State private var apiResult: String = "안녕하세요"

var body: some View {
VStack {
Text(apiResult)
.font(.system(size: 16))
.padding()

Button(action: setAPIValue) {
Text("API 호출")
.foregroundColor(.white)
.padding()
.background(Color.blue)
}
.padding()
}

}

// 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.apiResult = result
print(result)
}
case let .failure(error):
// API 요청이 실패한 경우 처리
print(error)
}
}
}
}

struct WeatherAPIView_Previews: PreviewProvider {
static var previews: some View {
WeatherAPIView()
}
}
15 changes: 15 additions & 0 deletions SixthWorkbook/SixthWorkbook/APIExercise_SwiftUI/weather.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// weatherModel.swift
// SixthWorkbook
//
// Created by 김수민 on 2023/12/09.
//

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,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
}
}
6 changes: 6 additions & 0 deletions SixthWorkbook/SixthWorkbook/Assets.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"author" : "xcode",
"version" : 1
}
}
169 changes: 169 additions & 0 deletions SixthWorkbook/SixthWorkbook/ContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import SwiftUI

struct ContentView: View {
let coloredNavAppearance = UINavigationBarAppearance()
@State var tag:Int? = nil

init() {
coloredNavAppearance.configureWithOpaqueBackground()
coloredNavAppearance.backgroundColor = UIColor.systemMint
coloredNavAppearance.titleTextAttributes = [.foregroundColor: UIColor.white]
coloredNavAppearance.largeTitleTextAttributes = [.foregroundColor: UIColor.white]
UINavigationBar.appearance().standardAppearance = coloredNavAppearance
UINavigationBar.appearance().scrollEdgeAppearance = coloredNavAppearance
}

var body: some View {
let buttons = ["Button 1", "Button 2", "Button 3", "Button 4", "Button 5", "Button 6"]
NavigationView {
VStack {
// ScrollView 추가
ScrollView {
// Scroll View에 표시될 내용 추가
HStack {
Image(systemName: "magnifyingglass")
.foregroundColor(Color(.systemGray6))
TextField("Search", text: .constant("df"))
.padding(8)
.background(Color(.systemGray6))
.cornerRadius(8)
Spacer()

}
.padding()
.frame(maxWidth: .infinity)
.background(.mint)
NavigationLink(destination: secondNextView(), tag: 1, selection: self.$tag ) {

}
Button(action: {
self.tag = 1
print("Button Clicked!")
}) {
Text("누구나 받으세요!\n최대 12,000원 할인")
.foregroundColor(.black)
.padding()
.frame(maxWidth: .infinity)
}

.frame(maxWidth: .infinity)
.background(Color.white)
.padding()
.cornerRadius(8)
LazyVGrid(columns: Array(repeating: GridItem(), count: 2), spacing: 16) {
ForEach(buttons, id: \.self) { buttonTitle in
Button(action: {
// 각 버튼이 클릭되었을 때의 동작 정의
print("\(buttonTitle) Clicked!")
}) {
Text(buttonTitle)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(Color.blue)
.cornerRadius(10)
}
}
}
.padding()
ScrollView(.horizontal, showsIndicators: false){
HStack{
ForEach(buttons, id: \.self) { buttonTitle in
Button(action: {
// 각 버튼이 클릭되었을 때의 동작 정의
print("\(buttonTitle) Clicked!")
}) {
Text(buttonTitle)
.foregroundColor(.white)
.padding()
.frame(maxWidth: .infinity)
.background(Color.blue)
.cornerRadius(10)
}
}
}
.padding()
}

Text("Item 0")
.padding()
.frame(maxWidth: .infinity)
.frame(height: 100)
Text("Item 0")
.padding()
.frame(maxWidth: .infinity)
Text("Item 0")
.padding()
.frame(maxWidth: .infinity)
Text("Item 0")
.padding()
.frame(maxWidth: .infinity)
.frame(height: 400)
}
.frame(maxWidth: .infinity)
.background(Color(.systemGray5))
// 하단에 버튼 추가
HStack {
TabButtonView(image: "magnifyingglass", title: "검색")
.frame(maxWidth: .infinity)
TabButtonView(image: "heart", title: "찜")
.frame(maxWidth: .infinity)
TabButtonView(image: "heart", title: "찜")
.frame(maxWidth: .infinity)
TabButtonView(image: "heart", title: "찜")
.frame(maxWidth: .infinity)
NavigationLink(destination: WeatherAPIView(), tag: 3, selection: self.$tag ) {
}
Button(action: {self.tag = 3}){
VStack{
Image(systemName: "book")
Text("날씨API")
}
}.frame(maxWidth: .infinity)
NavigationLink(destination: LogInView(), tag: 2, selection: self.$tag ) {
}
Button(action: {self.tag = 2}){
VStack{
Image(systemName: "person")
Text("로그인")
}
}.frame(maxWidth: .infinity)

}
.frame(maxWidth: .infinity)
.frame(height: 20)
.padding()

}
.navigationBarItems(
leading:
Text("동작구 여의대방로 44길 46")
.foregroundColor(.white)
.font(.headline),
trailing:
HStack {
Button(action: { print("click button") }) {
Image(systemName: "line.horizontal.3")
.imageScale(.large)
.foregroundColor(.white)
.padding()
}
Button(action: { print("click button") }) {
Image(systemName: "alarm")
.imageScale(.large)
.foregroundColor(.white)
.padding()
}
}
)
}
}
}

struct contentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}


Loading