I have a few UI elements on my app's ViewController (mainly UILabels). I am having to recreate these on my Today extension's View Controller. This does not seem right. Is there a way to share/reuse these UI elements; for example in a container view?
Asked
Active
Viewed 1,044 times
0
-
You should be able to add the needed files to your extension's target. – GetSwifty Feb 27 '17 at 18:05
-
StoryBoard? not sure how that would help, since it will contain the whole viewcontroller of the app – Kashif Feb 27 '17 at 18:06
-
If you need only part of it, put the needed scenes in a different storyboard. – GetSwifty Feb 27 '17 at 18:08
1 Answers
2
There are a few ways to do this. (Swift modules, frameworks, static libraries)
The simplest way to get what you want is to just add the view's file to the Build Sources of the Today widgets target.
If you're UI component is AwesomeView.swift
it'll be listed under:
Xcode Project Settings > Targets > MainApp > Build Phases > Compiled Sources
Go to:
Targets > TodayWidget > Build Phases > Compiled Sources
Then click the + and add the AwesomeView.swift
file to the today widget target as well. Now it will be compiled into, and can be used by, both binaries.

Kyle Howells
- 3,008
- 1
- 25
- 35