diff --git a/4thWeek/Assignment/Assignment/Home/HomeMainView.swift b/4thWeek/Assignment/Assignment/Home/HomeMainView.swift index 28bbf92..3d56c79 100644 --- a/4thWeek/Assignment/Assignment/Home/HomeMainView.swift +++ b/4thWeek/Assignment/Assignment/Home/HomeMainView.swift @@ -142,17 +142,17 @@ class HomeMainView: UIView { } private func getMovie() { - MovieService.shared.getMovie() { response in - switch response { - case .success(let data): - guard let data = data as? MovieResponse else { return } - self.responseData = data.results - self.firstCollectionView.reloadData() - default: - return - } + MovieService.shared.getMovie() { response in + switch response { + case .success(let data): + guard let data = data as? MovieResponse else { return } + self.responseData = data.results + self.firstCollectionView.reloadData() + default: + return } } + } } extension HomeMainView : UICollectionViewDelegate { diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/AppDelegate.swift" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/AppDelegate.swift" new file mode 100644 index 0000000..f5cf510 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/AppDelegate.swift" @@ -0,0 +1,36 @@ +// +// AppDelegate.swift +// Seminar +// +// Created by 신지원 on 2023/08/20. +// + +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) { + // 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. + } + + +} + diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/AccentColor.colorset/Contents.json" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/AccentColor.colorset/Contents.json" new file mode 100644 index 0000000..eb87897 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/AccentColor.colorset/Contents.json" @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/AppIcon.appiconset/Contents.json" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/AppIcon.appiconset/Contents.json" new file mode 100644 index 0000000..13613e3 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/AppIcon.appiconset/Contents.json" @@ -0,0 +1,13 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/Contents.json" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/Contents.json" new file mode 100644 index 0000000..73c0059 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/Contents.json" @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/princess.imageset/Contents.json" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/princess.imageset/Contents.json" new file mode 100644 index 0000000..b96b68f --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/princess.imageset/Contents.json" @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "스크린샷 2023-05-01 오전 1.35.36.png", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/princess.imageset/\354\212\244\355\201\254\353\246\260\354\203\267 2023-05-01 \354\230\244\354\240\204 1.35.36.png" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/princess.imageset/\354\212\244\355\201\254\353\246\260\354\203\267 2023-05-01 \354\230\244\354\240\204 1.35.36.png" new file mode 100644 index 0000000..6a598ca Binary files /dev/null and "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Assets.xcassets/princess.imageset/\354\212\244\355\201\254\353\246\260\354\203\267 2023-05-01 \354\230\244\354\240\204 1.35.36.png" differ diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Base.lproj/LaunchScreen.storyboard" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Base.lproj/LaunchScreen.storyboard" new file mode 100644 index 0000000..865e932 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Base.lproj/LaunchScreen.storyboard" @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Base.lproj/Main.storyboard" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Base.lproj/Main.storyboard" new file mode 100644 index 0000000..25a7638 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Base.lproj/Main.storyboard" @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/CarrotResult.swift" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/CarrotResult.swift" new file mode 100644 index 0000000..723eba2 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/CarrotResult.swift" @@ -0,0 +1,36 @@ +// +// User.swift +// Seminar +// +// Created by 신지원 on 2023/08/20. +// + +import Foundation + +import RealmSwift + +class CarrotResult: Object { + + @Persisted(primaryKey: true) var id: Int + @Persisted var image: String + @Persisted var product: String + @Persisted var place: String + @Persisted var time: String + @Persisted var tradeStatus: String + @Persisted var price: Int + @Persisted var liked: Bool + + convenience init(id: Int, image: String, product: String, place: String, time: String, tradeStatus: String, price: Int, liked: Bool) { + + self.init() + + self.id = id + self.image = image + self.product = product + self.place = place + self.time = time + self.tradeStatus = tradeStatus + self.price = price + self.liked = liked + } +} diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/CarrotTableViewCell.swift" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/CarrotTableViewCell.swift" new file mode 100644 index 0000000..cc7b50a --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/CarrotTableViewCell.swift" @@ -0,0 +1,172 @@ +// +// CarrotTableViewCell.swift +// Seminar +// +// Created by 신지원 on 2023/08/20. +// + +import UIKit + +import SnapKit +import Then +import RealmSwift + +class CarrotTableViewCell: UITableViewCell { + + //재사용 Cell 을 등록하기 위하여 선언하는 식별자 + static let identifier = "CarrotTableViewCell" + + private lazy var carrotImage = UIImageView() + private let productLabel = UILabel() + private let placeLabel = UILabel() + private let timeLabel = UILabel() + private let reservationLabel = UILabel() + private let priceLabel = UILabel() + private let horizontalStackView = UIStackView() + private let likedButton = UIButton() + + override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { + super.init(style: style, reuseIdentifier: reuseIdentifier) + + setStyle() + setLayout() + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + + func setStyle() { + + separatorInset.left = 0 + + selectionStyle = .none + + carrotImage.do { + $0.layer.cornerRadius = 5 + } + + productLabel.do { + $0.font = UIFont.systemFont(ofSize: 12) + } + + placeLabel.do { + $0.font = UIFont.boldSystemFont(ofSize: 11) + } + + timeLabel.do { + $0.font = UIFont.boldSystemFont(ofSize: 11) + } + + reservationLabel.do { + $0.textAlignment = .center + $0.textColor = .white + $0.font = UIFont.boldSystemFont(ofSize: 11) + $0.layer.cornerRadius = 3 + } + + priceLabel.do { + $0.font = UIFont.boldSystemFont(ofSize: 13) + } + + horizontalStackView.do { + $0.axis = .horizontal + $0.distribution = .fill + $0.alignment = .center + $0.spacing = 5 + } + + likedButton.do { + $0.tintColor = .systemGreen + $0.setImage(UIImage(systemName: "star"), for: .normal) + $0.setImage(UIImage(systemName: "star.fill"), for: .selected) +// $0.addTarget(self, action: #selector(likedButtonTapped), for: .touchUpInside) + } + } + + func setLayout() { + + [productLabel, placeLabel, + timeLabel, horizontalStackView, carrotImage, likedButton] + .forEach { contentView.addSubview($0) } + + [reservationLabel, priceLabel] + .forEach { horizontalStackView.addArrangedSubview($0) } + + carrotImage.snp.makeConstraints { + $0.size.equalTo(100) + $0.centerY.equalToSuperview() + $0.leading.equalToSuperview().inset(10) + } + + productLabel.snp.makeConstraints { + $0.leading.equalTo(carrotImage.snp.trailing).offset(14) + $0.top.equalToSuperview().inset(30) + } + + placeLabel.snp.makeConstraints { + $0.leading.equalTo(productLabel.self) + $0.top.equalTo(productLabel.snp.bottom).offset(6) + } + + timeLabel.snp.makeConstraints { + $0.leading.equalTo(placeLabel.snp.trailing).offset(3) + $0.top.equalTo(placeLabel.self) + } + + reservationLabel.snp.makeConstraints { + $0.height.equalTo(20) + $0.width.equalTo(50) + } + + horizontalStackView.snp.makeConstraints { + $0.leading.equalTo(placeLabel.self) + $0.top.equalTo(timeLabel.snp.bottom).offset(6) + $0.height.equalTo(30) + } + + likedButton.snp.makeConstraints { + $0.trailing.equalToSuperview().inset(30) + $0.centerY.equalToSuperview() + $0.size.equalTo(30) + } + } + + //CarrotData 를 뿌려주는 과정 + func configureCell(_ carrot: CarrotResult) { + + carrotImage.image = UIImage(named: "princess") + +// Realm 에 이미지 이름을 ".princess" 로 입력하여 구현되지 않았습니다,, +// carrotImage.image = UIImage(named: "\(carrot.image)") + + productLabel.text = carrot.product + placeLabel.text = carrot.place + timeLabel.text = carrot.time + + reservationLabel.text = carrot.tradeStatus + switch carrot.tradeStatus { + case ".completed" : + reservationLabel.text = "예약 완료" + reservationLabel.backgroundColor = .black + case ".reservation" : + reservationLabel.text = "예약중" + reservationLabel.backgroundColor = .systemGreen + case ".shared" : + reservationLabel.text = "나눔 완료" + reservationLabel.backgroundColor = .gray + default : + reservationLabel.text = "거래중" + reservationLabel.backgroundColor = .systemPink + } + + var price = String(carrot.price) + var i = 3 + while price.count > i { + price.insert(",", at: price.index(price.endIndex, offsetBy: -i)) + i += 4 + } + priceLabel.text = price + "원" + + } +} diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/CarrotViewController.swift" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/CarrotViewController.swift" new file mode 100644 index 0000000..37d8c60 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/CarrotViewController.swift" @@ -0,0 +1,81 @@ +// +// CarrotViewController.swift +// Seminar +// +// Created by 신지원 on 2023/08/20. +// + +import UIKit + +import SnapKit +import Then +import RealmSwift + +class CarrotViewController: UIViewController { + + private let tableView = UITableView() + + let realm = try! Realm() + + private lazy var dummy : [CarrotResult] = [] + + override func viewDidLoad() { + super.viewDidLoad() + setStyle() + setLayout() + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + self.dummy = getRealm() + self.tableView.reloadData() + } + + private func setStyle() { + + tableView.do { + $0.register(CarrotTableViewCell.self, forCellReuseIdentifier: CarrotTableViewCell.identifier) + $0.rowHeight = 120 + $0.delegate = self + $0.dataSource = self + } + } + + private func setLayout() { + + view.addSubview(tableView) + + tableView.snp.makeConstraints { + $0.top.equalTo(view.safeAreaInsets) + $0.bottom.leading.trailing.equalToSuperview() + } + } + + private func getRealm() -> [CarrotResult] { + let result = realm.objects(CarrotResult.self) + var array: [CarrotResult] = [] + result.forEach { + array.append($0) + } + return array + } +} + +extension CarrotViewController: UITableViewDelegate {} + +extension CarrotViewController: UITableViewDataSource { + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return dummy.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + guard let cell = tableView.dequeueReusableCell(withIdentifier: CarrotTableViewCell.identifier, for: indexPath) as? CarrotTableViewCell else { return UITableViewCell() } + + cell.configureCell(dummy[indexPath.row]) + + return cell + } +} + diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Info.plist" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Info.plist" new file mode 100644 index 0000000..0eb786d --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/Info.plist" @@ -0,0 +1,23 @@ + + + + + UIApplicationSceneManifest + + UIApplicationSupportsMultipleScenes + + UISceneConfigurations + + UIWindowSceneSessionRoleApplication + + + UISceneConfigurationName + Default Configuration + UISceneDelegateClassName + $(PRODUCT_MODULE_NAME).SceneDelegate + + + + + + diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/LikedViewController.swift" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/LikedViewController.swift" new file mode 100644 index 0000000..2db32c6 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/LikedViewController.swift" @@ -0,0 +1,81 @@ +// +// CarrotViewController.swift +// Seminar +// +// Created by 신지원 on 2023/08/20. +// + +import UIKit + +import SnapKit +import Then +import RealmSwift + +class LikedViewController: UIViewController { + + private let tableView = UITableView() + + let realm = try! Realm() + + private lazy var dummy : [CarrotResult] = [] + + override func viewDidLoad() { + super.viewDidLoad() + setStyle() + setLayout() + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + self.dummy = getRealm() + self.tableView.reloadData() + } + + private func setStyle() { + + tableView.do { + $0.register(CarrotTableViewCell.self, forCellReuseIdentifier: CarrotTableViewCell.identifier) + $0.rowHeight = 120 + $0.delegate = self + $0.dataSource = self + } + } + + private func setLayout() { + + view.addSubview(tableView) + + tableView.snp.makeConstraints { + $0.top.equalTo(view.safeAreaInsets) + $0.bottom.leading.trailing.equalToSuperview() + } + } + + private func getRealm() -> [CarrotResult] { + let resultLiked = realm.objects(CarrotResult.self).filter("liked = %@", true) + var array: [CarrotResult] = [] + resultLiked.forEach { + array.append($0) + } + return array + } +} + +extension LikedViewController: UITableViewDelegate {} + +extension LikedViewController: UITableViewDataSource { + + func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return dummy.count + } + + func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + + guard let cell = tableView.dequeueReusableCell(withIdentifier: CarrotTableViewCell.identifier, for: indexPath) as? CarrotTableViewCell else { return UITableViewCell() } + + cell.configureCell(dummy[indexPath.row]) + + return cell + } +} + diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/RealmViewController.swift" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/RealmViewController.swift" new file mode 100644 index 0000000..a91ef40 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/RealmViewController.swift" @@ -0,0 +1,35 @@ +// +// ViewController.swift +// Seminar +// +// Created by 신지원 on 2023/08/20. +// + + +//import UIKit +// +//import RealmSwift +// +//final class RealmViewController: UIViewController { +// +// let localRealm = try! Realm() +// +// override func viewDidLoad() { +// super.viewDidLoad() +// +// let task = CarrotResult(id: 7, +// image: ".princess", +// product: "쿠로미 예뿌죠?", +// place: "쿠로미 나라", +// time: "3월 28일", +// tradeStatus: ".completed", +// price: 1000000, +// liked: false) +// +// try! localRealm.write { +// localRealm.add(task) +// } +// +// print(Realm.Configuration.defaultConfiguration.fileURL!) +// } +//} diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/SceneDelegate.swift" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/SceneDelegate.swift" new file mode 100644 index 0000000..9638d7a --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/SceneDelegate.swift" @@ -0,0 +1,53 @@ +// +// SceneDelegate.swift +// Seminar +// +// Created by 신지원 on 2023/08/20. +// + +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) + window?.rootViewController = UINavigationController(rootViewController: TabBarViewController()) + window.UINavigationBar.isHidden + 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. + } + + +} + diff --git "a/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/TabBarViewController.swift" "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/TabBarViewController.swift" new file mode 100644 index 0000000..f13d820 --- /dev/null +++ "b/\353\254\264\354\240\234 \355\217\264\353\215\224/Seminar/Seminar/TabBarViewController.swift" @@ -0,0 +1,27 @@ +// +// TabBarViewController.swift +// Seminar +// +// Created by 신지원 on 2023/08/20. +// + +import UIKit + +class TabBarViewController: UITabBarController { + + override func viewDidLoad() { + + super.viewDidLoad() + + let carrotViewController = CarrotViewController() + carrotViewController.tabBarItem = UITabBarItem(title: "Carrot", image: UIImage(systemName: "star.fill"), tag: 0) + + let likedViewController = LikedViewController() + likedViewController.tabBarItem = UITabBarItem(title: "Favorite", image: UIImage(systemName: "star.fill"), tag: 1) + + tabBar.barTintColor = .white + tabBar.isTranslucent = false + setViewControllers([carrotViewController, likedViewController].map{UINavigationController(rootViewController: $0)}, animated: false) + } + +}