0

I have a set of snippets for iOS, MacOS, WatchOS and TvOS that I would like to embed in a Cocoapod library (possibly supporting also Carthage as well).

The tricky part for me is that I have targets for all the platforms (iOS, MacOS TvOS etc...) but some of the files are targeted only in a subset of them.

In my Xcode project I divided the code in folders like:

  • Library_Common (target all)
  • Library_iOS (target iOS)
  • Library_WatchOS (target WatchOS)
  • Library_MacOS (target MacOS)

This because, for example, the iOS part of the library may need UIKit and the MacOS may need other frameworks not available for iOS.

How can I setup the podspec in such a way that this library can be embedded in all the platforms?

Is there a way to do it or is better to split it in different libraries? The problem of this approach would be that the Library_Common part would be repeated for each one.

GrizzlyBear
  • 1,098
  • 1
  • 13
  • 27
  • https://www.natashatherobot.com/cocoapods-installing-same-pod-multiple-targets/ – Sachin Vas Mar 26 '19 at 12:48
  • The question is not about installing, but generating the library itself. :) – GrizzlyBear Mar 26 '19 at 13:57
  • 1
    Yes, it is better to split it into Common and platform based changes. This way even for the end user who have multiple platforms will have a single copy of Common. If you are publishing a closed source framework, you have to use vendored_frameworks. If it is a open source you can define subspec. – Sachin Vas Mar 27 '19 at 05:02

1 Answers1

0

I finally found what I was looking for and seems to be specified in the podspec documentation itself. Unfortunately I didn't saw it before:

https://guides.cocoapods.org/syntax/podspec.html#group_multi_platform_support

This means, in my case I have the following settings:

s.source_files  = "MyLibrary_common/**/*.{h,m}"
s.ios.source_files = "MyLibrary_iOS/**/*.{h,m}"
s.osx.source_files = "MyLibrary_macOS/**/*.{h,m}"
s.tvos.source_files = "MyLibrary_tvOS/**/*.{h,m}"
s.watchos.source_files = "MyLibrary_watchOS/**/*.{h,m}"
GrizzlyBear
  • 1,098
  • 1
  • 13
  • 27