diff --git a/iOS_Study_A.xcodeproj/project.pbxproj b/iOS_Study_A.xcodeproj/project.pbxproj index 1f5c336..c8fea37 100644 --- a/iOS_Study_A.xcodeproj/project.pbxproj +++ b/iOS_Study_A.xcodeproj/project.pbxproj @@ -10,9 +10,11 @@ 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 */ @@ -20,10 +22,11 @@ 954B6B602AC57BE100FDCFAB /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 954B6B622AC57BE100FDCFAB /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = ""; }; 954B6B642AC57BE100FDCFAB /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; - 954B6B672AC57BE100FDCFAB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 954B6B692AC57BE200FDCFAB /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 954B6B6C2AC57BE200FDCFAB /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 954B6B6E2AC57BE200FDCFAB /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + E1EFEB5B2B15F2BB0073E7B0 /* MemoTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MemoTableViewCell.swift; sourceTree = ""; }; + E1EFEB5D2B15F2EB0073E7B0 /* AddMemoViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddMemoViewController.swift; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -31,6 +34,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + E1EFEB5A2B15F2690073E7B0 /* SnapKit in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -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 */, @@ -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"; @@ -111,6 +119,9 @@ Base, ); mainGroup = 954B6B542AC57BE100FDCFAB; + packageReferences = ( + E1EFEB582B15F2690073E7B0 /* XCRemoteSwiftPackageReference "SnapKit" */, + ); productRefGroup = 954B6B5E2AC57BE100FDCFAB /* Products */; projectDirPath = ""; projectRoot = ""; @@ -127,7 +138,6 @@ files = ( 954B6B6D2AC57BE200FDCFAB /* LaunchScreen.storyboard in Resources */, 954B6B6A2AC57BE200FDCFAB /* Assets.xcassets in Resources */, - 954B6B682AC57BE100FDCFAB /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -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 = ""; - }; 954B6B6B2AC57BE200FDCFAB /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( @@ -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 = ( @@ -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 = ( @@ -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 */; } diff --git a/iOS_Study_A.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/iOS_Study_A.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved new file mode 100644 index 0000000..009c162 --- /dev/null +++ b/iOS_Study_A.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -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 +} diff --git a/iOS_Study_A/AddMemoViewController.swift b/iOS_Study_A/AddMemoViewController.swift new file mode 100644 index 0000000..e883b12 --- /dev/null +++ b/iOS_Study_A/AddMemoViewController.swift @@ -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) + 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) + } + } +} + + diff --git a/iOS_Study_A/Base.lproj/Main.storyboard b/iOS_Study_A/Base.lproj/Main.storyboard deleted file mode 100644 index 25a7638..0000000 --- a/iOS_Study_A/Base.lproj/Main.storyboard +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/iOS_Study_A/Info.plist b/iOS_Study_A/Info.plist index dd3c9af..0eb786d 100644 --- a/iOS_Study_A/Info.plist +++ b/iOS_Study_A/Info.plist @@ -15,8 +15,6 @@ Default Configuration UISceneDelegateClassName $(PRODUCT_MODULE_NAME).SceneDelegate - UISceneStoryboardFile - Main diff --git a/iOS_Study_A/MemoTableViewCell.swift b/iOS_Study_A/MemoTableViewCell.swift new file mode 100644 index 0000000..7296b42 --- /dev/null +++ b/iOS_Study_A/MemoTableViewCell.swift @@ -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) + } + } +} + diff --git a/iOS_Study_A/SceneDelegate.swift b/iOS_Study_A/SceneDelegate.swift index aaf78de..03aef07 100644 --- a/iOS_Study_A/SceneDelegate.swift +++ b/iOS_Study_A/SceneDelegate.swift @@ -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. diff --git a/iOS_Study_A/ViewController.swift b/iOS_Study_A/ViewController.swift index 0804a27..c143e36 100644 --- a/iOS_Study_A/ViewController.swift +++ b/iOS_Study_A/ViewController.swift @@ -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 + } + }