{"id":32747,"date":"2024-11-01T09:11:15","date_gmt":"2024-11-01T09:11:15","guid":{"rendered":"http:\/\/atmokpo.com\/w\/?p=32747"},"modified":"2024-11-01T11:23:54","modified_gmt":"2024-11-01T11:23:54","slug":"swiftui-style-iphone-app-development-creating-a-to-do-list-using-12-table-view-controllers","status":"publish","type":"post","link":"https:\/\/atmokpo.com\/w\/32747\/","title":{"rendered":"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers"},"content":{"rendered":"<p><body><\/p>\n<p>Hello. In this post, we will explore how to develop an iPhone app using the Swift language with SwiftUI. Specifically, I will provide a detailed explanation of creating a to-do list flow using UITableViewController. We will compare the differences and use cases between SwiftUI and UIKit, and help you understand through hands-on practice.<\/p>\n<h2>1. Differences between SwiftUI and UIKit<\/h2>\n<p>SwiftUI is Apple&#8217;s new UI framework that helps you create user interfaces more intuitively. SwiftUI adopts a declarative programming approach, which is different from how you construct a UI using the traditional UIKit.<\/p>\n<h3>1.1 UI Composition<\/h3>\n<p>In UIKit, you manage each screen using ViewController, and you have to connect UIKit&#8217;s basic components directly in code or storyboard. In contrast, SwiftUI allows you to declare &#8216;views&#8217; as constants and compose the screen by combining them. This means you can easily manage UI state changes.<\/p>\n<h3>1.2 State Management<\/h3>\n<p>SwiftUI simplifies state management by providing various property wrappers like @State, @Binding, and @ObservedObject. These features improve upon the complex logic previously required in UIKit, such as using Delegate patterns or NotificationCenter as needed.<\/p>\n<h2>2. Setting Up the Project<\/h2>\n<p>Let\u2019s set up the project now. Open Xcode and create a new iOS app project.<\/p>\n<h3>2.1 Creating a New Project<\/h3>\n<ol>\n<li>Run Xcode and select &#8216;Create a new Xcode project.&#8217;<\/li>\n<li>Select &#8216;App&#8217; and click &#8216;Next.&#8217;<\/li>\n<li>Enter the Project Name, select &#8216;SwiftUI&#8217; for Interface, and &#8216;Swift&#8217; for Language.<\/li>\n<li>Click &#8216;Next,&#8217; then choose a location to save the project.<\/li>\n<\/ol>\n<h2>3. Creating a To-Do List with SwiftUI<\/h2>\n<p>Now, let&#8217;s look into how to create a to-do list using SwiftUI. In this step, the to-do list will be managed as an array.<\/p>\n<h3>3.1 Creating the Data Model<\/h3>\n<p>First, we will define the data model for the to-do list. We create a simple structure as below.<\/p>\n<pre>\n<code>struct Task: Identifiable {\n    var id = UUID()\n    var title: String\n    var isCompleted: Bool\n}<\/code>\n    <\/pre>\n<h3>3.2 Adding a To-Do List Array<\/h3>\n<p>Now, we create an array that includes multiple to-do items.<\/p>\n<pre>\n<code>class TaskStore: ObservableObject {\n    @Published var tasks: [Task] = []\n}<\/code>\n    <\/pre>\n<h3>3.3 Creating the View<\/h3>\n<p>The view for the to-do list can be created using the List structure to display each task. Write the code as follows.<\/p>\n<pre>\n<code>import SwiftUI\n\nstruct ContentView: View {\n    @ObservedObject var taskStore = TaskStore()\n\n    var body: some View {\n        NavigationView {\n            List {\n                ForEach(taskStore.tasks) { task in\n                    HStack {\n                        Text(task.title)\n                        Spacer()\n                        if task.isCompleted {\n                            Image(systemName: \"checkmark\")\n                        }\n                    }\n                }\n            }\n            .navigationBarTitle(\"To-Do List\")\n            .navigationBarItems(trailing: Button(action: {\n                \/\/ Logic to add a task\n            }) {\n                Image(systemName: \"plus\")\n            })\n        }\n    }\n}<\/code>\n    <\/pre>\n<h3>3.4 Adding a Task<\/h3>\n<p>We will implement an add button so that users can add tasks. We will add an Alert to prompt the user for input.<\/p>\n<pre>\n<code>@State private var showingAddTask = false\n@State private var newTaskTitle = \"\"\n\nButton(action: {\n    showingAddTask.toggle()\n}) {\n    Image(systemName: \"plus\")\n}\n.alert(isPresented: $showingAddTask) {\n    Alert(title: Text(\"Add New Task\"),\n          message: Text(\"Please enter the task title.\"),\n          primaryButton: .default(Text(\"Add\")) {\n              let newTask = Task(title: newTaskTitle, isCompleted: false)\n              taskStore.tasks.append(newTask)\n              newTaskTitle = \"\"\n          },\n          secondaryButton: .cancel())\n}\n.textFieldAlert(\"Task Title\", text: $newTaskTitle)<\/code>\n    <\/pre>\n<h2>4. Creating a To-Do List with UITableViewController<\/h2>\n<p>Now, let&#8217;s implement the same functionality using UITableViewController with UIKit. We will include UIKit in the project and set up the UITableView.<\/p>\n<h3>4.1 Creating the UITableViewController Class<\/h3>\n<pre>\n<code>class TaskListViewController: UITableViewController {\n    var tasks: [Task] = []\n    \n    \/\/ Initialize Data in viewDidLoad\n    override func viewDidLoad() {\n        super.viewDidLoad()\n        \/\/ Add default data\n        tasks.append(Task(title: \"Example Task\", isCompleted: false))\n    }\n    \n    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {\n        return tasks.count\n    }\n\n    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {\n        let cell = tableView.dequeueReusableCell(withIdentifier: \"cell\", for: indexPath)\n        let task = tasks[indexPath.row]\n        cell.textLabel?.text = task.title\n        return cell\n    }\n}<\/code>\n    <\/pre>\n<h3>4.2 Setting Up Table View Cells<\/h3>\n<p>To set up the table view cells, we register a UITableViewCell and set the delegate and datasource.<\/p>\n<pre>\n<code>override func viewDidLoad() {\n    super.viewDidLoad()\n    tableView.register(UITableViewCell.self, forCellReuseIdentifier: \"cell\")\n}\n<\/code><\/pre>\n<h3>4.3 Adding a Task<\/h3>\n<p>As we used an Alert in the SwiftUI app, we can use UIAlertController to receive user input in UIKit.<\/p>\n<pre>\n<code>@objc func addTask() {\n    let alert = UIAlertController(title: \"Add New Task\", message: \"Please enter the task title.\", preferredStyle: .alert)\n    alert.addTextField()\n    \n    let addAction = UIAlertAction(title: \"Add\", style: .default) { [weak self] _ in\n        guard let title = alert.textFields?.first?.text else { return }\n        let newTask = Task(title: title, isCompleted: false)\n        self?.tasks.append(newTask)\n        self?.tableView.reloadData()\n    }\n    \n    alert.addAction(addAction)\n    alert.addAction(UIAlertAction(title: \"Cancel\", style: .cancel))\n    present(alert, animated: true)\n}<\/code>\n    <\/pre>\n<h2>5. Conclusion<\/h2>\n<p>In this post, we explored the process of creating a to-do list app using SwiftUI and UIKit. SwiftUI offers greater intuition in UI composition and simplified state management, providing many conveniences for developers. Both UIKit and SwiftUI have their advantages, so it&#8217;s important to choose the appropriate framework based on the situation.<\/p>\n<p>Thank you for reading this far, and if you have any additional questions or need assistance, please feel free to leave a comment.<\/p>\n<p><\/body><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello. In this post, we will explore how to develop an iPhone app using the Swift language with SwiftUI. Specifically, I will provide a detailed explanation of creating a to-do list flow using UITableViewController. We will compare the differences and use cases between SwiftUI and UIKit, and help you understand through hands-on practice. 1. Differences &hellip; <a href=\"https:\/\/atmokpo.com\/w\/32747\/\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[125],"tags":[],"class_list":["post-32747","post","type-post","status-publish","format-standard","hentry","category-swift-iphone-app-development-swiftui"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/atmokpo.com\/w\/32747\/\" \/>\n<meta property=\"og:locale\" content=\"ko_KR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"og:description\" content=\"Hello. In this post, we will explore how to develop an iPhone app using the Swift language with SwiftUI. Specifically, I will provide a detailed explanation of creating a to-do list flow using UITableViewController. We will compare the differences and use cases between SwiftUI and UIKit, and help you understand through hands-on practice. 1. Differences &hellip; \ub354 \ubcf4\uae30 &quot;SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers&quot;\" \/>\n<meta property=\"og:url\" content=\"https:\/\/atmokpo.com\/w\/32747\/\" \/>\n<meta property=\"og:site_name\" content=\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-01T09:11:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-01T11:23:54+00:00\" \/>\n<meta name=\"author\" content=\"root\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:site\" content=\"@bebubo4\" \/>\n<meta name=\"twitter:label1\" content=\"\uae00\uc4f4\uc774\" \/>\n\t<meta name=\"twitter:data1\" content=\"root\" \/>\n\t<meta name=\"twitter:label2\" content=\"\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04\" \/>\n\t<meta name=\"twitter:data2\" content=\"4\ubd84\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/atmokpo.com\/w\/32747\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32747\/\"},\"author\":{\"name\":\"root\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\"},\"headline\":\"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers\",\"datePublished\":\"2024-11-01T09:11:15+00:00\",\"dateModified\":\"2024-11-01T11:23:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32747\/\"},\"wordCount\":524,\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"articleSection\":[\"Swift iPhone app development (SwiftUI)\"],\"inLanguage\":\"ko-KR\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/atmokpo.com\/w\/32747\/\",\"url\":\"https:\/\/atmokpo.com\/w\/32747\/\",\"name\":\"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"isPartOf\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#website\"},\"datePublished\":\"2024-11-01T09:11:15+00:00\",\"dateModified\":\"2024-11-01T11:23:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/atmokpo.com\/w\/32747\/#breadcrumb\"},\"inLanguage\":\"ko-KR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/atmokpo.com\/w\/32747\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/atmokpo.com\/w\/32747\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\ud648\",\"item\":\"https:\/\/atmokpo.com\/w\/en\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/atmokpo.com\/w\/#website\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/atmokpo.com\/w\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"ko-KR\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/atmokpo.com\/w\/#organization\",\"name\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\",\"url\":\"https:\/\/atmokpo.com\/w\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"contentUrl\":\"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png\",\"width\":400,\"height\":400,\"caption\":\"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8\"},\"image\":{\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/bebubo4\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7\",\"name\":\"root\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"ko-KR\",\"@id\":\"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g\",\"caption\":\"root\"},\"sameAs\":[\"http:\/\/atmokpo.com\/w\"],\"url\":\"https:\/\/atmokpo.com\/w\/author\/root\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/atmokpo.com\/w\/32747\/","og_locale":"ko_KR","og_type":"article","og_title":"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","og_description":"Hello. In this post, we will explore how to develop an iPhone app using the Swift language with SwiftUI. Specifically, I will provide a detailed explanation of creating a to-do list flow using UITableViewController. We will compare the differences and use cases between SwiftUI and UIKit, and help you understand through hands-on practice. 1. Differences &hellip; \ub354 \ubcf4\uae30 \"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers\"","og_url":"https:\/\/atmokpo.com\/w\/32747\/","og_site_name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","article_published_time":"2024-11-01T09:11:15+00:00","article_modified_time":"2024-11-01T11:23:54+00:00","author":"root","twitter_card":"summary_large_image","twitter_creator":"@bebubo4","twitter_site":"@bebubo4","twitter_misc":{"\uae00\uc4f4\uc774":"root","\uc608\uc0c1 \ub418\ub294 \ud310\ub3c5 \uc2dc\uac04":"4\ubd84"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/atmokpo.com\/w\/32747\/#article","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/32747\/"},"author":{"name":"root","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7"},"headline":"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers","datePublished":"2024-11-01T09:11:15+00:00","dateModified":"2024-11-01T11:23:54+00:00","mainEntityOfPage":{"@id":"https:\/\/atmokpo.com\/w\/32747\/"},"wordCount":524,"publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"articleSection":["Swift iPhone app development (SwiftUI)"],"inLanguage":"ko-KR"},{"@type":"WebPage","@id":"https:\/\/atmokpo.com\/w\/32747\/","url":"https:\/\/atmokpo.com\/w\/32747\/","name":"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers - \ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","isPartOf":{"@id":"https:\/\/atmokpo.com\/w\/#website"},"datePublished":"2024-11-01T09:11:15+00:00","dateModified":"2024-11-01T11:23:54+00:00","breadcrumb":{"@id":"https:\/\/atmokpo.com\/w\/32747\/#breadcrumb"},"inLanguage":"ko-KR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/atmokpo.com\/w\/32747\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/atmokpo.com\/w\/32747\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\ud648","item":"https:\/\/atmokpo.com\/w\/en\/"},{"@type":"ListItem","position":2,"name":"SwiftUI style, iPhone app development, creating a to-do list using 12 table view controllers"}]},{"@type":"WebSite","@id":"https:\/\/atmokpo.com\/w\/#website","url":"https:\/\/atmokpo.com\/w\/","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","description":"","publisher":{"@id":"https:\/\/atmokpo.com\/w\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/atmokpo.com\/w\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"ko-KR"},{"@type":"Organization","@id":"https:\/\/atmokpo.com\/w\/#organization","name":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8","url":"https:\/\/atmokpo.com\/w\/","logo":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/","url":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","contentUrl":"https:\/\/atmokpo.com\/w\/wp-content\/uploads\/2024\/11\/logo.png","width":400,"height":400,"caption":"\ub77c\uc774\ube0c\uc2a4\ub9c8\ud2b8"},"image":{"@id":"https:\/\/atmokpo.com\/w\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/bebubo4"]},{"@type":"Person","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/91b6b3b138fbba0efb4ae64b1abd81d7","name":"root","image":{"@type":"ImageObject","inLanguage":"ko-KR","@id":"https:\/\/atmokpo.com\/w\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/708197b41fc6435a7ce22d951b25d4a47e9e904270cb1f04682d4f025066f80c?s=96&d=mm&r=g","caption":"root"},"sameAs":["http:\/\/atmokpo.com\/w"],"url":"https:\/\/atmokpo.com\/w\/author\/root\/"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32747","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/comments?post=32747"}],"version-history":[{"count":1,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32747\/revisions"}],"predecessor-version":[{"id":32748,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/posts\/32747\/revisions\/32748"}],"wp:attachment":[{"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/media?parent=32747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/categories?post=32747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/atmokpo.com\/w\/wp-json\/wp\/v2\/tags?post=32747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}