{"id":339,"date":"2016-07-08T11:23:33","date_gmt":"2016-07-08T09:23:33","guid":{"rendered":"https:\/\/zaven.co\/blog\/?p=339"},"modified":"2025-04-08T19:55:20","modified_gmt":"2025-04-08T17:55:20","slug":"add-extensions-ios-apps-part2","status":"publish","type":"post","link":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/","title":{"rendered":"How to add extensions to iOS apps (part 2)"},"content":{"rendered":"<p>Learn how to add extensions to iOS apps to provide additional actions to your users without launching the app itself. In this part you\u2019ll find out how to enable iOS app resource sharing and create a simple manager for saving and reading files.<!--more-->In <a href=\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part1\/\" target=\"_blank\" rel=\"noopener\">part one<\/a> of our iPhone app development guide&nbsp;I wrote about:<\/p>\n<ul>\n<li>creating the app project<\/li>\n<li>programming the main view of iOS app<\/li>\n<li>adding an extension to iOS app<\/li>\n<\/ul>\n<h2>Shared resources<\/h2>\n<p>To enable resource sharing, set a common data container that can be used by your targets (the main app and the extension).<\/p>\n<p>Beside the marked target, choose the <code>Capabilities<\/code> bookmark. Select <code>App Groups<\/code> form the list and run it. Click the \u201c+\u201d button and write the container name.<\/p>\n<div id=\"attachment_358\" style=\"width: 533px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/9.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-358\" class=\"wp-image-358 size-full\" src=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/9.png\" alt=\"App ios developer\"  ><\/a><p id=\"caption-attachment-358\" class=\"wp-caption-text\">Adding new container<\/p><\/div>\n<p>After approving you should see the new entry.<\/p>\n<div id=\"attachment_359\" style=\"width: 740px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/10.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-359\" class=\"wp-image-359 size-medium\" src=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/10-730x188.png\" alt=\"How to add extensions to iOS apps \"   srcset=\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/10-730x188.png 730w, https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/10.png 894w\" sizes=\"auto, (max-width: 730px) 100vw, 730px\" \/><\/a><p id=\"caption-attachment-359\" class=\"wp-caption-text\">App groups<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>For now, we\u2019ve just created a container for our iOS app targets. <strong>This whole process must be repeated<\/strong> for the main target of the app. So, on the left hand side, select <code>AppExtensionSample<\/code> from the list of targets and repeat these actions (write the same name when adding).<\/p>\n<h2>Local Storage Manager<\/h2>\n<p>Now that we have a dedicated container to save our data from both app targets, let\u2019s move on to creating a simple manager for saving and reading data.<\/p>\n<p>In the main app target, create new class called <code>LocalStorageManager<\/code> with the following code:<\/p>\n<pre><code class=\"language-swift\">\nimport UIKit\n\npublic class LocalStorageManager{\n    \n    static let sharedInstance = LocalStorageManager()\n    \n    private let sharedContainer: NSUserDefaults = NSUserDefaults(suiteName: \"group.co.zaven.AppExtensionSample\")!\n    \n    private var storedData: [String]! = []\n    \n    private init(){\n        self.readData()\n    }\n    \n    func readData() -&gt; [String]{\n        if let data = self.sharedContainer.objectForKey(\"FileList\") as? [String] {\n            self.storedData = data\n        }\n        return self.storedData\n    }\n    \n    func insertData(fileName: String){\n        self.storedData.append(fileName)\n        self.sharedContainer.setObject(self.storedData, forKey: \"FileList\")\n    }\n    \n    func removeData(index: Int){\n        self.storedData.removeAtIndex(index)\n        self.sharedContainer.setObject(self.storedData, forKey: \"FileList\")\n    }\n    \n    func clearData(){\n        self.storedData.removeAll()\n        self.sharedContainer.removeObjectForKey(\"FileList\")\n    }\n}\n\n<\/code><\/pre>\n<p>A simple singleton for using our local store. Pay attention to the <code>sharedContainer<\/code> declaration, where I refer to the name of the already created group container. By default, we would refer to the <code>standardUserDefaults<\/code>, that is allocated only to the one target in which we used it. This is how we\u2019ll refer to a common container. Without firther obstacles, we\u2019ll be able to save or read separated targets data.<\/p>\n<hr>\n<h3><strong>Next on \u201cHow to add extensions to iOS apps\u201d:<\/strong><\/h3>\n<p>In <a href=\"https:\/\/zaven.co\/blog\/add-extensions-ios-8-apps-part3\/\" target=\"_blank\" rel=\"noopener\">the 3rd part<\/a> of our iPhone app development guide, we will perform some final touches on the table implementation in the main application.<\/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.23.1484738118522&amp;__hsfp=846626033\" target=\"_blank\" rel=\"noopener\">HERE<\/a>.<\/strong><\/h3>\n<hr>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to add extensions to iOS apps to provide additional actions to your users without launching the app itself. In this part you\u2019ll find out how to enable iOS app resource sharing and create a simple manager for saving and reading files.<\/p>\n","protected":false},"author":4,"featured_media":344,"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-339","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 2) | Zaven Blog<\/title>\n<meta name=\"description\" content=\"How to add extensions to iOS apps: how to enable iOS app resource sharing and create a simple manager for saving and reading files.\" \/>\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-part2\/\" \/>\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 2) | Zaven Blog\" \/>\n<meta property=\"og:description\" content=\"How to add extensions to iOS apps: how to enable iOS app resource sharing and create a simple manager for saving and reading files.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/\" \/>\n<meta property=\"og:site_name\" content=\"Zaven Blog\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-08T09:23:33+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\/Depositphotos_111789376_l-2015_maly1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"568\" \/>\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-part2\/\",\"url\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/\",\"name\":\"How to add extensions to iOS apps (part 2) | Zaven Blog\",\"isPartOf\":{\"@id\":\"https:\/\/zaven.co\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Depositphotos_111789376_l-2015_maly1.jpg\",\"datePublished\":\"2016-07-08T09:23:33+00:00\",\"dateModified\":\"2025-04-08T17:55:20+00:00\",\"author\":{\"@id\":\"https:\/\/zaven.co\/blog\/#\/schema\/person\/c29fc600e8bb0269e5390d84f114ac54\"},\"description\":\"How to add extensions to iOS apps: how to enable iOS app resource sharing and create a simple manager for saving and reading files.\",\"breadcrumb\":{\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#primaryimage\",\"url\":\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Depositphotos_111789376_l-2015_maly1.jpg\",\"contentUrl\":\"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Depositphotos_111789376_l-2015_maly1.jpg\",\"width\":1000,\"height\":568,\"caption\":\"How to add extensions to iOS apps\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#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 2)\"}]},{\"@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 2) | Zaven Blog","description":"How to add extensions to iOS apps: how to enable iOS app resource sharing and create a simple manager for saving and reading files.","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-part2\/","og_locale":"en_US","og_type":"article","og_title":"How to add extensions to iOS apps (part 2) | Zaven Blog","og_description":"How to add extensions to iOS apps: how to enable iOS app resource sharing and create a simple manager for saving and reading files.","og_url":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/","og_site_name":"Zaven Blog","article_published_time":"2016-07-08T09:23:33+00:00","article_modified_time":"2025-04-08T17:55:20+00:00","og_image":[{"width":1000,"height":568,"url":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Depositphotos_111789376_l-2015_maly1.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-part2\/","url":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/","name":"How to add extensions to iOS apps (part 2) | Zaven Blog","isPartOf":{"@id":"https:\/\/zaven.co\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#primaryimage"},"image":{"@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#primaryimage"},"thumbnailUrl":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Depositphotos_111789376_l-2015_maly1.jpg","datePublished":"2016-07-08T09:23:33+00:00","dateModified":"2025-04-08T17:55:20+00:00","author":{"@id":"https:\/\/zaven.co\/blog\/#\/schema\/person\/c29fc600e8bb0269e5390d84f114ac54"},"description":"How to add extensions to iOS apps: how to enable iOS app resource sharing and create a simple manager for saving and reading files.","breadcrumb":{"@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#primaryimage","url":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Depositphotos_111789376_l-2015_maly1.jpg","contentUrl":"https:\/\/zaven.co\/blog\/wp-content\/uploads\/2016\/07\/Depositphotos_111789376_l-2015_maly1.jpg","width":1000,"height":568,"caption":"How to add extensions to iOS apps"},{"@type":"BreadcrumbList","@id":"https:\/\/zaven.co\/blog\/add-extensions-ios-apps-part2\/#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 2)"}]},{"@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\/339","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=339"}],"version-history":[{"count":26,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts\/339\/revisions"}],"predecessor-version":[{"id":69930,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/posts\/339\/revisions\/69930"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/media\/344"}],"wp:attachment":[{"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/media?parent=339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/categories?post=339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zaven.co\/blog\/wp-json\/wp\/v2\/tags?post=339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}