Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sharing code between original iOS App and App Extension

Sharing class between iOS app and extension app

I want to use a custom class in both my app and the extension app. If I just have the class in the main app folder, the extension doesn't pick up on it. I tried making a copy of it and putting it into the extension folder, but I of course get a invalid redeclaration of [my class] error. What's the best solution for this? It's just one class, not multiple resources.

like image 289
Ruben Martinez Jr. Avatar asked Mar 01 '15 18:03

Ruben Martinez Jr.


People also ask

How do I share data between iOS apps?

Shared Keychain Access: Allows you to securely store data to a shared keychain that other applications that are part of a suite of applications can access. All applications that share keychain access must use the same app ID prefix. For an example of shared keychain access in action.

How do app extensions work iOS?

You create an app extension by adding a new target to an app. As with any target, an extension target specifies settings and files that combine to build a product within your app project. You can add multiple extension targets to a single app (an app that contains one or more extensions is called a containing app).

Can you code iOS apps on iPhone?

You'll be writing Swift programming language directly into Xcode. After downloading Xcode and learning Swift, you're going to be able to not only build iOS apps for an iPhone, but also apps for other Apple products such as iPads, Apple watch apps, Apple TV apps, etc.

Can an iOS app open another app?

iOS Allows us to open some applications with some links or other ways from our app, like dialing a number when clicked on it, or writing a mail with some static body or writing a SMS. But this is limited to some applications, not every app can be opened from within an application.


2 Answers

Nothing should be copied. Just add required files to compile sources for your extension:

enter image description here

like image 105
Avt Avatar answered Sep 18 '22 21:09

Avt


Just make sure that the files you want to share gets a tick in the section Target Membership.

Select your file, open the utility panel on the right and tick the appropriate target under Target Membership.

enter image description here

like image 29
Duc Avatar answered Sep 20 '22 21:09

Duc