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

[제로] 6주차 실습 #26

Open
wants to merge 1 commit 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
49 changes: 35 additions & 14 deletions iOS_Study_A.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,31 @@
954B6B612AC57BE100FDCFAB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954B6B602AC57BE100FDCFAB /* AppDelegate.swift */; };
954B6B632AC57BE100FDCFAB /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954B6B622AC57BE100FDCFAB /* SceneDelegate.swift */; };
954B6B652AC57BE100FDCFAB /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 954B6B642AC57BE100FDCFAB /* ViewController.swift */; };
954B6B682AC57BE100FDCFAB /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B662AC57BE100FDCFAB /* Main.storyboard */; };
954B6B6A2AC57BE200FDCFAB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B692AC57BE200FDCFAB /* Assets.xcassets */; };
954B6B6D2AC57BE200FDCFAB /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 954B6B6B2AC57BE200FDCFAB /* LaunchScreen.storyboard */; };
E1EFEB5A2B15F2690073E7B0 /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = E1EFEB592B15F2690073E7B0 /* SnapKit */; };
E1EFEB5C2B15F2BB0073E7B0 /* MemoTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1EFEB5B2B15F2BB0073E7B0 /* MemoTableViewCell.swift */; };
E1EFEB5E2B15F2EB0073E7B0 /* AddMemoViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = E1EFEB5D2B15F2EB0073E7B0 /* AddMemoViewController.swift */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
954B6B5D2AC57BE100FDCFAB /* iOS_Study_A.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = iOS_Study_A.app; sourceTree = BUILT_PRODUCTS_DIR; };
954B6B602AC57BE100FDCFAB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
954B6B622AC57BE100FDCFAB /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
954B6B642AC57BE100FDCFAB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = "<group>"; };
954B6B672AC57BE100FDCFAB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = "<group>"; };
954B6B692AC57BE200FDCFAB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
954B6B6C2AC57BE200FDCFAB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
954B6B6E2AC57BE200FDCFAB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E1EFEB5B2B15F2BB0073E7B0 /* MemoTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoTableViewCell.swift; sourceTree = "<group>"; };
E1EFEB5D2B15F2EB0073E7B0 /* AddMemoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddMemoViewController.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
954B6B5A2AC57BE100FDCFAB /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
E1EFEB5A2B15F2690073E7B0 /* SnapKit in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -59,7 +63,8 @@
954B6B602AC57BE100FDCFAB /* AppDelegate.swift */,
954B6B622AC57BE100FDCFAB /* SceneDelegate.swift */,
954B6B642AC57BE100FDCFAB /* ViewController.swift */,
954B6B662AC57BE100FDCFAB /* Main.storyboard */,
E1EFEB5B2B15F2BB0073E7B0 /* MemoTableViewCell.swift */,
E1EFEB5D2B15F2EB0073E7B0 /* AddMemoViewController.swift */,
954B6B692AC57BE200FDCFAB /* Assets.xcassets */,
954B6B6B2AC57BE200FDCFAB /* LaunchScreen.storyboard */,
954B6B6E2AC57BE200FDCFAB /* Info.plist */,
Expand All @@ -83,6 +88,9 @@
dependencies = (
);
name = iOS_Study_A;
packageProductDependencies = (
E1EFEB592B15F2690073E7B0 /* SnapKit */,
);
productName = iOS_Study_A;
productReference = 954B6B5D2AC57BE100FDCFAB /* iOS_Study_A.app */;
productType = "com.apple.product-type.application";
Expand Down Expand Up @@ -111,6 +119,9 @@
Base,
);
mainGroup = 954B6B542AC57BE100FDCFAB;
packageReferences = (
E1EFEB582B15F2690073E7B0 /* XCRemoteSwiftPackageReference "SnapKit" */,
);
productRefGroup = 954B6B5E2AC57BE100FDCFAB /* Products */;
projectDirPath = "";
projectRoot = "";
Expand All @@ -127,7 +138,6 @@
files = (
954B6B6D2AC57BE200FDCFAB /* LaunchScreen.storyboard in Resources */,
954B6B6A2AC57BE200FDCFAB /* Assets.xcassets in Resources */,
954B6B682AC57BE100FDCFAB /* Main.storyboard in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -139,22 +149,16 @@
buildActionMask = 2147483647;
files = (
954B6B652AC57BE100FDCFAB /* ViewController.swift in Sources */,
E1EFEB5E2B15F2EB0073E7B0 /* AddMemoViewController.swift in Sources */,
954B6B612AC57BE100FDCFAB /* AppDelegate.swift in Sources */,
954B6B632AC57BE100FDCFAB /* SceneDelegate.swift in Sources */,
E1EFEB5C2B15F2BB0073E7B0 /* MemoTableViewCell.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXSourcesBuildPhase section */

/* Begin PBXVariantGroup section */
954B6B662AC57BE100FDCFAB /* Main.storyboard */ = {
isa = PBXVariantGroup;
children = (
954B6B672AC57BE100FDCFAB /* Base */,
);
name = Main.storyboard;
sourceTree = "<group>";
};
954B6B6B2AC57BE200FDCFAB /* LaunchScreen.storyboard */ = {
isa = PBXVariantGroup;
children = (
Expand Down Expand Up @@ -291,7 +295,6 @@
INFOPLIST_FILE = iOS_Study_A/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
LD_RUNPATH_SEARCH_PATHS = (
Expand All @@ -318,7 +321,6 @@
INFOPLIST_FILE = iOS_Study_A/Info.plist;
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
INFOPLIST_KEY_UIMainStoryboardFile = Main;
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight";
LD_RUNPATH_SEARCH_PATHS = (
Expand Down Expand Up @@ -356,6 +358,25 @@
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */

/* Begin XCRemoteSwiftPackageReference section */
E1EFEB582B15F2690073E7B0 /* XCRemoteSwiftPackageReference "SnapKit" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/SnapKit/SnapKit.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 5.0.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
E1EFEB592B15F2690073E7B0 /* SnapKit */ = {
isa = XCSwiftPackageProductDependency;
package = E1EFEB582B15F2690073E7B0 /* XCRemoteSwiftPackageReference "SnapKit" */;
productName = SnapKit;
};
/* End XCSwiftPackageProductDependency section */
};
rootObject = 954B6B552AC57BE100FDCFAB /* Project object */;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "snapkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SnapKit/SnapKit.git",
"state" : {
"revision" : "f222cbdf325885926566172f6f5f06af95473158",
"version" : "5.6.0"
}
}
],
"version" : 2
}
58 changes: 58 additions & 0 deletions iOS_Study_A/AddMemoViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// AddMemoViewController.swift
// iOS_Study_A
//
// Created by 신혜림 on 2023/11/28.
//

import UIKit
import SnapKit


class AddMemoViewController: UIViewController {

private var memoTextField: UITextField = {
let textField = UITextField()
textField.placeholder = "메모를 작성하세요."
textField.borderStyle = .roundedRect
return textField
}()

override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
navigationItem.title = "메모 작성"

setupSubviews()
}

private func setupSubviews() {
view.addSubview(memoTextField)

memoTextField.snp.makeConstraints { make in
make.top.equalTo(view.safeAreaLayoutGuide).offset(20)
make.leading.equalTo(view).offset(20)
make.trailing.equalTo(view).offset(-20)
Comment on lines +34 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make.leading.trailing.equalTo(view).inset(20)
한 줄로 줄일 수 있어요!

make.height.equalTo(40)
}

let writeButton = UIBarButtonItem(title: "작성하기", style: .plain, target: self, action: #selector(writeButtonTapped))
navigationItem.rightBarButtonItem = writeButton
}

@objc private func writeButtonTapped() {
guard let memoText = memoTextField.text, !memoText.isEmpty else {
// Handle empty memo or do nothing if the text field is empty
return
}

// Pass the memo text back to ViewController
if let navigationController = navigationController,
let viewController = navigationController.viewControllers.first(where: { $0 is ViewController }) as? ViewController {
viewController.addNewMemo(memo: memoText)
navigationController.popViewController(animated: true)
}
}
}


24 changes: 0 additions & 24 deletions iOS_Study_A/Base.lproj/Main.storyboard

This file was deleted.

2 changes: 0 additions & 2 deletions iOS_Study_A/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
Expand Down
45 changes: 45 additions & 0 deletions iOS_Study_A/MemoTableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//
// MemoTableViewCell.swift
// iOS_Study_A
//
// Created by 신혜림 on 2023/11/28.
//

import UIKit
import SnapKit

class MemoTableViewCell: UITableViewCell {
static let identifier = "MemoTableViewCell"

var titleLabel: UILabel = {
let label = UILabel()

return label
}()

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
configureSubviews()
makeConstraints()
}

override func awakeFromNib() {
super.awakeFromNib()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

func configureSubviews() {
contentView.addSubview(titleLabel)
}

func makeConstraints() {
titleLabel.snp.makeConstraints { make in
make.centerY.equalTo(contentView)
make.leading.equalTo(contentView).inset(15)
}
}
}

14 changes: 9 additions & 5 deletions iOS_Study_A/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {


func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
guard let _ = (scene as? UIWindowScene) else { return }
}
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)

let mainViewController = ViewController()
let navigationController = UINavigationController(rootViewController: mainViewController)

window?.rootViewController = navigationController
window?.makeKeyAndVisible()
}

func sceneDidDisconnect(_ scene: UIScene) {
// Called as the scene is being released by the system.
Expand Down
64 changes: 61 additions & 3 deletions iOS_Study_A/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,72 @@
//

import UIKit
import SnapKit


class ViewController: UIViewController {
var memoList: [String] = []

var memoTableView: UITableView = {
let tableView = UITableView()
tableView.register(MemoTableViewCell.self, forCellReuseIdentifier: MemoTableViewCell.identifier)

return tableView
}()

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
super.viewDidLoad()
configureSubviews()
makeConstraints()
setNavigationBar()

memoTableView.dataSource = self
memoTableView.delegate = self

view.backgroundColor = .white
}

func addNewMemo(memo: String) {
memoList.append(memo)
memoTableView.reloadData()
}

func configureSubviews() {
view.addSubview(memoTableView)
}

func makeConstraints() {
memoTableView.snp.makeConstraints { make in
make.edges.equalTo(view.safeAreaLayoutGuide)
}
}

func setNavigationBar() {
let addButton = UIBarButtonItem(image: UIImage(systemName: "plus"), style: .plain, target: self, action: #selector(addButtonTapped))

navigationItem.title = "메모장"
navigationItem.rightBarButtonItem = addButton
}

@objc func addButtonTapped() {
let addMemoViewController = AddMemoViewController()
self.navigationController?.pushViewController(addMemoViewController, animated: true)
}
}

extension ViewController: UITableViewDelegate, UITableViewDataSource {

}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return memoList.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = memoTableView.dequeueReusableCell(withIdentifier: MemoTableViewCell.identifier, for: indexPath) as? MemoTableViewCell else {
return UITableViewCell()
}

cell.titleLabel.text = memoList[indexPath.row]

return cell
}
}