# App extensions, Xcode and Cocoapods, OMG!

DevFeed: [App extensions, Xcode and Cocoapods, OMG!](<https://devfeed.tech/articles/app-extensions-xcode-and-cocoapods-omg-21617.md>)

Original publisher: [Read original article](<http://miqu.me/blog/2016/11/28/app-extensions-xcode-and-cocoapods-omg/>)

Author: Miguel Angel Quiñones

Published: 2016-11-28T09:44:54Z

Content type: article

Language: en

Sources: [Miguel Quinones](<https://devfeed.tech/sources/miguel-quinones.md>)

Topics: [App](<https://devfeed.tech/topics/app.md>), [Extension](<https://devfeed.tech/topics/extension.md>), [Xcode](<https://devfeed.tech/topics/xcode.md>), [Library](<https://devfeed.tech/topics/library.md>), [Tooling](<https://devfeed.tech/topics/tooling.md>), [Code](<https://devfeed.tech/topics/code.md>)

Tags: [app](<https://devfeed.tech/tags/app.md>), [apple](<https://devfeed.tech/tags/apple.md>), [cocoapods](<https://devfeed.tech/tags/cocoapods.md>), [extensions](<https://devfeed.tech/tags/extensions.md>), [ios](<https://devfeed.tech/tags/ios.md>), [library](<https://devfeed.tech/tags/library.md>), [swift](<https://devfeed.tech/tags/swift.md>), [tooling](<https://devfeed.tech/tags/tooling.md>), [xcode](<https://devfeed.tech/tags/xcode.md>)

## AI overview

This article explains compilation and integration problems that can occur when sharing CocoaPods libraries between an iOS app and an app extension. It covers APIs unavailable to extensions, conditional compilation, extension-specific code paths, and CocoaPods target deduplication.

## Source excerpt

Have you encountered this error when upgrading to the latest CocoaPods (1.1.0), or sharing a library between your iOS App and your extension? 1 'sharedApplication' is unavailable: not available on iOS (App Extension) - Use view controller based solutions where appropriate instead. If yes, continue reading, as you might have encountered same issue as myself. I've recently had to upgrade a project to using Cocoapods 1.1.0. Things stopped compiling, and I had to investigate the root cause of the problem. It has to do with iOS App extensions, unavailable APIs and how fragile our tooling is ;). TL;DR The first cause of error can be fixed by conditionally compiling with a macro. See example here It's better if you define whole classes or API unavailable using NS_EXTENSION_UNAVAILABLE_IOS If you had this error in a 3rd party library you'll need it to be fixed by the author (see below) If you are a library author and need to have different code paths via preprocessor macros, read this thread, and follow the recommendation to create a separated subspec for an extension target Unavailable API for App extensions Since the introduction of Application extensions several years ago, Apple has marked some API as unavailable for these targets. For example, sharedApplication from UIApplication: 1 @property(class, nonatomic, readonly) UIApplication *sharedApplication NS_EXTENSION_UNAVAILABLE_IOS("Use view controller based solutions where appropriate instead."); or in Swift: 1 2 @available(iOSApplicationExtension, unavailable) open class var shared: UIApplication { get } Apple is using a new macro, NS_EXTENSION_UNAVAILABLE_IOS to mark API as unavailable. There's a new setting on Xcode, APPLICATION_EXTENSION_API_ONLY, and if set, the code will not compile if it contains a call to sharedApplication. This setting is automatically enabled for extension targets so you get the error in your code when you are writing it. Writing separate code for an App target and and extension target is not