{"id":347,"date":"2016-07-08T11:25:36","date_gmt":"2016-07-08T09:25:36","guid":{"rendered":"https:\/\/zaven.co\/blog\/?p=347"},"modified":"2025-04-08T19:55:20","modified_gmt":"2025-04-08T17:55:20","slug":"add-extensions-ios-apps-part3","status":"publish","type":"post","link":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/","title":{"rendered":"How to add extensions to iOS apps (part 3)"},"content":{"rendered":"<p>Welcome to the third part of our guide: &#8220;how to add extensions to iOS apps&#8221;, where we\u2019ll complete the table implementation in the main view of our iOS application.<!--more--><\/p>\n<p>In <a href=\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part-2\/\" target=\"_blank\" rel=\"noopener\">the previous part <\/a>of our iPhone app development guide I explained how to:<\/p>\n<ul>\n<li>enable resource sharing in an app<\/li>\n<li>create a manager for saving and reading data<\/li>\n<\/ul>\n<h2>Table implementation<\/h2>\n<p>Let\u2019s go back to our main <code>ViewController<\/code> and finish implementing the table.<br \/>\nWe already have a place to save our data and thanks to the manager we\u2019ve created, data can now be added and removed within the view.<\/p>\n<p>First off, implement these two protocols that will allow us to use our table:<br \/>\n<code>UITableViewDelegate<\/code> and <code>UITableViewDataSource<\/code>.<\/p>\n<p>Our class should look like this:<\/p>\n<pre><code class=\"language-swift\">\nimport UIKit\n\nclass ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {\n\n    @IBOutlet weak var tableView: UITableView!\n    \n    override func viewDidLoad() {\n        super.viewDidLoad()\n    }\n    \n    override func didReceiveMemoryWarning() {\n        super.didReceiveMemoryWarning()\n    }\n\n}\n<\/code><\/pre>\n<p>We should see an error message, what means that we have to add the missing delegates <code>numberOfRowslnSection<\/code> and <code>callForRowAtlndexPath<\/code>. Let\u2019s do this!<br \/>\nFirst, add the delegates service and data source to our table. In <code>viewDidLoad()<\/code> insert the following lines:<\/p>\n<pre><code class=\"language-swift\">\nself.tableView.delegate = self\nself.tableView.dataSource = self\n<\/code><\/pre>\n<p>Next, implement the required delegates.<\/p>\n<pre><code class=\"language-swift\">\nfunc tableView(tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {\n        return LocalStorageManager.sharedInstance.readData().count\n    }\n    \n    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -&gt; UITableViewCell {\n        let cell = UITableViewCell()\n        cell.textLabel!.text = LocalStorageManager.sharedInstance.readData()[indexPath.row]\n        return cell\n    }\n<\/code><\/pre>\n<p>In the first one, determine the amount of rows per section (in this case we have only one section). In the next one, define the behavior of the cell row. The only thing left is to set the text using the <code>indexPath.row<\/code> for returned table from our manager\u2019s <code>readData()<\/code> method.<\/p>\n<p>If we would run our app now, we would only see lines separating particular table rows. Add manually a few entries just to see if everything works as expected.<\/p>\n<p>In the <code>viewDidLoad()<\/code> method, add three lines which will insert data to our container using our manager.<\/p>\n<pre><code class=\"language-swift\">\noverride func viewDidLoad() {\n    super.viewDidLoad()\n    LocalStorageManager.sharedInstance.insertData(\"Entry 1\")\n    LocalStorageManager.sharedInstance.insertData(\"Entry 1\")\n    LocalStorageManager.sharedInstance.insertData(\"Entry 1\")\n    self.tableView.delegate = self\n    self.tableview.dataSource = self\n}\n<\/code><\/pre>\n<p>If we run the app now, we&#8217;ll see three manually added positions in our table.<\/p>\n<div id=\"attachment_387\" style=\"width: 330px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/13-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-387\" class=\"wp-image-387 size-full\" src=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/13-1.png\" alt=\"How to add extensions to iOS apps \"  ><\/a><p id=\"caption-attachment-387\" class=\"wp-caption-text\">The table with sample entries<\/p><\/div>\n<p>As you can see, our entries were added to the table so everything should work properly. Let\u2019s replace these three lines in <code>viewDidLoad()<\/code> with one that will clear all saved data.<\/p>\n<pre><code class=\"language-swift\">\noverride func viewDidLoad() {\n    super.viewDidLoad()\n    LocalStorageManager.sharedInstance.clearData()\n    self.tableView.delegate = self\n    self.tableview.dataSource = self\n}\n<\/code><\/pre>\n<p>After running the app, our table should be empty. By the way, we should add the possibility to delete entries in the table through cell swiping.<br \/>\nImplement two required delegates:<\/p>\n<pre><code class=\"language-swift\">\n    func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -&gt; [UITableViewRowAction]? {\n        let remove = UITableViewRowAction(style: .Destructive, title: \"Remove\") { action, index in\n            LocalStorageManager.sharedInstance.removeData(index.row)\n            self.tableView.reloadData()\n        }     \n        return [remove]\n    }\n\n    func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -&gt; Bool {\n        return true\n    }\n<\/code><\/pre>\n<p>In the first one, add a <code>RowAction<\/code> with the title <code>Remove<\/code>.<br \/>\nThen delete entries from our database. Remember to refresh the table with <code>reloadData()<\/code> after deleting a line. In the second delegate, define which row should have the option of choosing an action, return \u201ctrue\u201d for all of them. Now, after running the iOS app, it will be possible to delete entries by swiping a line.<\/p>\n<div id=\"attachment_389\" style=\"width: 330px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/15-1.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-389\" class=\"wp-image-389 size-full\" src=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/15-1.png\" alt=\"iOS app development\"  ><\/a><p id=\"caption-attachment-389\" class=\"wp-caption-text\">Removing&nbsp;entries<\/p><\/div>\n<hr>\n<h3>Next on \u201cHow to add extensions to iOS apps\u201d:<\/h3>\n<p>In <a href=\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part-4\/\" target=\"_blank\" rel=\"noopener\">the last part<\/a> of our iPhone app development guide we\u2019ll cover adding and saving files.<\/p>\n<p>&nbsp;<\/p>\n<hr>\n<h3><strong>You can have a look at the finished app in our GitHub repo <a href=\"https:\/\/github.com\/zavenco\/AppExtensionSample?__hstc=172624316.442dd803fb88070e130b762b6ea5b6db.1471594325614.1484730129131.1484738118522.166&amp;__hssc=172624316.9.1484738118522&amp;__hsfp=846626033\" target=\"_blank\" rel=\"noopener\">here<\/a>.<\/strong><\/h3>\n<hr>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Welcome to the third part of our guide: &#8220;how to add extensions to iOS apps&#8221;, where we\u2019ll complete the table implementation in the main view of our iOS application.<\/p>\n","protected":false},"author":4,"featured_media":348,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[57,5],"tags":[37,38,34,36,35],"class_list":["post-347","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ios-development","category-tutorials","tag-app-extension","tag-app-ios-developer","tag-ios-app-building","tag-ios-app-development","tag-iphone-app-development"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.8.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to add extensions to iOS apps (part 3) | Zaven Blog<\/title>\n<meta name=\"description\" content=\"Add extensions to iOS apps: the third part of the guide: we\u2019ll complete the table implementation in the main view of our iOS application.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add extensions to iOS apps (part 3) | Zaven Blog\" \/>\n<meta property=\"og:description\" content=\"Add extensions to iOS apps: the third part of the guide: we\u2019ll complete the table implementation in the main view of our iOS application.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/\" \/>\n<meta property=\"og:site_name\" content=\"Zaven Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-08T09:25:36+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-08T17:55:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Craig-Rodway.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1801\" \/>\n\t<meta property=\"og:image:height\" content=\"1232\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Pawe\u0142 Ku\u017aniak\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Pawe\u0142 Ku\u017aniak\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/\",\"url\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/\",\"name\":\"How to add extensions to iOS apps (part 3) | Zaven Blog\",\"isPartOf\":{\"@id\":\"https:\/\/zaven.co\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Craig-Rodway.jpg\",\"datePublished\":\"2016-07-08T09:25:36+00:00\",\"dateModified\":\"2025-04-08T17:55:20+00:00\",\"author\":{\"@id\":\"https:\/\/zaven.co\/blog\/#\/schema\/person\/c29fc600e8bb0269e5390d84f114ac54\"},\"description\":\"Add extensions to iOS apps: the third part of the guide: we\u2019ll complete the table implementation in the main view of our iOS application.\",\"breadcrumb\":{\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#primaryimage\",\"url\":\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Craig-Rodway.jpg\",\"contentUrl\":\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Craig-Rodway.jpg\",\"width\":1801,\"height\":1232,\"caption\":\"How to add extensions to iOS apps\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/zaven.co\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add extensions to iOS apps (part 3)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/zaven.co\/blog\/#website\",\"url\":\"https:\/\/zaven.co\/blog\/\",\"name\":\"Zaven Blog\",\"description\":\"Software development blog. Generative AI, web &amp; mobile applications.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/zaven.co\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/zaven.co\/blog\/#\/schema\/person\/c29fc600e8bb0269e5390d84f114ac54\",\"name\":\"Pawe\u0142 Ku\u017aniak\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zaven.co\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/18ab5ae9a3e0bf0aaec573b90bbf3ea8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/18ab5ae9a3e0bf0aaec573b90bbf3ea8?s=96&d=mm&r=g\",\"caption\":\"Pawe\u0142 Ku\u017aniak\"},\"description\":\"Pawe\u0142 is technical analyst, developer and IT operations specialist at Zaven. He can solve a 3x3x3 Rubik's cube in a matter of seconds and you can find more complicated ones lying around on his desk (solved, obviously). His problem-solving attitude is reflected in his work, as he likes to keep himself busy with non-trivial puzzles.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/pawe-kuniak-a33735104\"],\"url\":\"https:\/\/zaven.co\/blog\/author\/pkuzniakzaven-pl\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add extensions to iOS apps (part 3) | Zaven Blog","description":"Add extensions to iOS apps: the third part of the guide: we\u2019ll complete the table implementation in the main view of our iOS application.","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:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/","og_locale":"en_US","og_type":"article","og_title":"How to add extensions to iOS apps (part 3) | Zaven Blog","og_description":"Add extensions to iOS apps: the third part of the guide: we\u2019ll complete the table implementation in the main view of our iOS application.","og_url":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/","og_site_name":"Zaven Blog","article_published_time":"2016-07-08T09:25:36+00:00","article_modified_time":"2025-04-08T17:55:20+00:00","og_image":[{"width":1801,"height":1232,"url":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Craig-Rodway.jpg","type":"image\/jpeg"}],"author":"Pawe\u0142 Ku\u017aniak","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Pawe\u0142 Ku\u017aniak","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/","url":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/","name":"How to add extensions to iOS apps (part 3) | Zaven Blog","isPartOf":{"@id":"https:\/\/zaven.co\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#primaryimage"},"image":{"@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#primaryimage"},"thumbnailUrl":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Craig-Rodway.jpg","datePublished":"2016-07-08T09:25:36+00:00","dateModified":"2025-04-08T17:55:20+00:00","author":{"@id":"https:\/\/zaven.co\/blog\/#\/schema\/person\/c29fc600e8bb0269e5390d84f114ac54"},"description":"Add extensions to iOS apps: the third part of the guide: we\u2019ll complete the table implementation in the main view of our iOS application.","breadcrumb":{"@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#primaryimage","url":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Craig-Rodway.jpg","contentUrl":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Craig-Rodway.jpg","width":1801,"height":1232,"caption":"How to add extensions to iOS apps"},{"@type":"BreadcrumbList","@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part3\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/zaven.co\/blog\/"},{"@type":"ListItem","position":2,"name":"How to add extensions to iOS apps (part 3)"}]},{"@type":"WebSite","@id":"https:\/\/zaven.co\/blog\/#website","url":"https:\/\/zaven.co\/blog\/","name":"Zaven Blog","description":"Software development blog. Generative AI, web &amp; mobile applications.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/zaven.co\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/zaven.co\/blog\/#\/schema\/person\/c29fc600e8bb0269e5390d84f114ac54","name":"Pawe\u0142 Ku\u017aniak","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zaven.co\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/18ab5ae9a3e0bf0aaec573b90bbf3ea8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/18ab5ae9a3e0bf0aaec573b90bbf3ea8?s=96&d=mm&r=g","caption":"Pawe\u0142 Ku\u017aniak"},"description":"Pawe\u0142 is technical analyst, developer and IT operations specialist at Zaven. He can solve a 3x3x3 Rubik's cube in a matter of seconds and you can find more complicated ones lying around on his desk (solved, obviously). His problem-solving attitude is reflected in his work, as he likes to keep himself busy with non-trivial puzzles.","sameAs":["https:\/\/www.linkedin.com\/in\/pawe-kuniak-a33735104"],"url":"https:\/\/zaven.co\/blog\/author\/pkuzniakzaven-pl\/"}]}},"_links":{"self":[{"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts\/347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/comments?post=347"}],"version-history":[{"count":28,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts\/347\/revisions"}],"predecessor-version":[{"id":69929,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts\/347\/revisions\/69929"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/media\/348"}],"wp:attachment":[{"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/media?parent=347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/categories?post=347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/tags?post=347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}