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

๐Ÿ’…๐Ÿป 7์ฃผ์ฐจ ์„ธ๋ฏธ๋‚˜ #16

Merged
merged 14 commits into from
Aug 21, 2023
Merged
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
18 changes: 9 additions & 9 deletions 4thWeek/Assignment/Assignment/Home/HomeMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
36 changes: 36 additions & 0 deletions ๋ฌด์ œ ํด๋”/Seminar/Seminar/AppDelegate.swift
Original file line number Diff line number Diff line change
@@ -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<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,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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13122.16" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
<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="tne-QT-ifu">
<objects>
<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="8bC-Xf-vdC">
<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="dkx-z0-nzr" sceneMemberID="firstResponder"/>
</objects>
</scene>
</scenes>
</document>
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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 + "์›"

}
}
Loading