How to add extensions to iOS apps (part 2)

iOS Development, Tutorials

Learn how to add extensions to iOS apps to provide additional actions to your users without launching the app itself. In this part you’ll find out how to enable iOS app resource sharing and create a simple manager for saving and reading files.

In part one of our iPhone app development guide I wrote about:

  • creating the app project
  • programming the main view of iOS app
  • adding an extension to iOS app

Shared resources

To enable resource sharing, set a common data container that can be used by your targets (the main app and the extension).

Beside the marked target, choose the Capabilities bookmark. Select App Groups form the list and run it. Click the “+” button and write the container name.

App ios developer

Adding new container

After approving you should see the new entry.

How to add extensions to iOS apps

App groups


For now, we’ve just created a container for our iOS app targets. This whole process must be repeated for the main target of the app. So, on the left hand side, select AppExtensionSample from the list of targets and repeat these actions (write the same name when adding).

Local Storage Manager

Now that we have a dedicated container to save our data from both app targets, let’s move on to creating a simple manager for saving and reading data.

In the main app target, create new class called LocalStorageManager with the following code:

import UIKit

public class LocalStorageManager{
    static let sharedInstance = LocalStorageManager()
    private let sharedContainer: NSUserDefaults = NSUserDefaults(suiteName: "")!
    private var storedData: [String]! = []
    private init(){
    func readData() -> [String]{
        if let data = self.sharedContainer.objectForKey("FileList") as? [String] {
            self.storedData = data
        return self.storedData
    func insertData(fileName: String){
        self.sharedContainer.setObject(self.storedData, forKey: "FileList")
    func removeData(index: Int){
        self.sharedContainer.setObject(self.storedData, forKey: "FileList")
    func clearData(){

A simple singleton for using our local store. Pay attention to the sharedContainer declaration, where I refer to the name of the already created group container. By default, we would refer to the standardUserDefaults, that is allocated only to the one target in which we used it. This is how we’ll refer to a common container. Without firther obstacles, we’ll be able to save or read separated targets data.

Next on “How to add extensions to iOS apps”:

In the 3rd part of our iPhone app development guide, we will perform some final touches on the table implementation in the main application.



Paweł Kuźniak Mobile Developer

Paweł is an iOS developer at Zaven and a committed Rubik's cube aficionado. He can solve a 3x3x3 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.

Popular posts

Offline Access in a Mobile App Used on Construction Sites

Offline Access in a Mobile App Used on Construction Sites

For the last few years, we have been working on a user-friendly construction project management app. This kind of tool includes an array of features, for example issuing tasks and document management. However, there is one crucial feature that is often overlooked but plays a vital role on construction sites: offline functionality.

Read more
Enhancing API Testing Efficiency with JavaScript in Postman

Enhancing API Testing Efficiency with JavaScript in Postman

API testing is essential for good software, and Postman has made it easier by letting us use JavaScript to check our work. In this article, we'll see how using JavaScript in Postman helps us make sure our software is working right, saving us time and making our testing process smoother.

Read more
Flutter application template with GitHub Actions

Flutter application template with GitHub Actions

This article explains how to create Flutter application template with GitHub Actions to save yourself time and nerves.

Read more
Mobile Apps

Get your mobile app in 3 easy steps!


Spec out

with the help of our
business analyst



design, implement
and test, repeat!



get your app out
to the stores

back to top