---
title: Pod subspec
slug: pod-subspec
docTags: 
createdAt: 2021-03-12T18:13:22.000Z
---

If we have a framework that offers multiple frameworks that all together are one big solution but at the same time can be used separately we can define one "parent" framework that lists all others as subspec.

# Podspec with subspec frameworks

```ruby
Pod::Spec.new do |s|
 s.name = 'MyCompany'

 s.subspec 'UI' do |ui|
  ui.source_files = 'UI.xcframework'
  ui.dependency 'MyCompany/Core'
 end

 s.subspec 'Core' do |core|
  core.source_files = 'Core.xcframework'
 end

 s.subpsec 'CalcEngine' do |ce|
  ce.source_files = 'CalcEngine.xcframework'
 end
end

```

## Install default frameworks

If only "parent" framework is added to Podfile all children frameworks defined as subspec will also be installed.

```ruby
pod 'MyCompany'

```

If we look at the example podspec this will install all frameworks from podspec.

- **MyCompany/Core**
- **MyCompany/UI**
- **MyCompany/CalcEngine**

## Define default frameworks

By default, all subspec frameworks will be installed, but it can be changed by specifying `default_subspec` array.

```ruby
s.default_subspec = 'Core'

```

This means that by defining `pod MyCompany` in **Podfile** it will install only **MyCompany/Core**.

## Install specific framework

If we want to install a specific framework only we can define it in the Podfile like this.

```ruby
pod 'MyCompany/CalcEngine'

```

This will install only **CalcEngine** framework.

## Install collection of subspecs

Instead of typing `pod 'MyCompany/{framework_name}'` for every subspec, there's an option to install them by  specifying an array of frameworks.

So, instead of:

```ruby
pod 'MyCompany/Core'
pod 'MyCompany/CalcEngine'
pod 'MyCompany/UI'
```

Shorter version is:

```ruby
pod 'MyCompany', :subspecs => ['Core', 'CalcEngine', 'UI']
```

# References

- [https://guides.cocoapods.org/making/specs-and-specs-repo.html#examples-of-specifications](https://guides.cocoapods.org/making/specs-and-specs-repo.html#examples-of-specifications)
- [https://guides.cocoapods.org/syntax/podspec.html#subspec](https://guides.cocoapods.org/syntax/podspec.html#subspec)

