How to declare public header files as CocoaPod author?

守給你的承諾、 提交于 2019-12-13 04:18:13

问题


I haven't really done iOS development before, nor have I ever worked with CocoaPods (as a consumer or an author) - but I've been rapidly learning so I can piece together a library for my company.

I started a new Objective-C project using pod lib create (it has to be Objective-C for business reasons) and got to work figuring things out.

Now I'm trying to figure out how to make my library classes import-able by someone using my pod. I have the following folder structure in Xcode:

- bfsdk
|- Podspec Metadata
||- bfsdk.podspec
||- README.md
||- LICENSE
|
|- Example for bfsdk
||- BFAppDelegate.h
||- BFAppDelegate.m
||- Main.storyboard
||- BFViewController.h
||- BFViewController.m
||- LaunchScreen.storyboard
||- Images.xcassets
||- Supporting Files
|||- bfsdk-Info.plist
|||- InfoPlist.strings
|||- main.m
|||- bfsdk-Prefix.pch
|
|- Tests
||- ...
|
|- Frameworks
||- Foundation.framework
||- CoreGraphics.framework
||- UIKit.framework
||- XCTest.framework
||- Pods_bfsdk_Example.framework
||- Pods_bfsdk_Tests.framework
|
|- Products
||- ...
|
|- Pods
||- Pods-bfsdk_Example.debug.xcconfig
||- Pods-bfsdk_Example.release.xcconfig
||- Pods-bfsdk_Tests.debug.xcconfig
||- Pods-bfsdk_Tests.release.xcconfig

- Pods
|- Podfile
|- Development Pods
||- bfsdk
|||- ReplaceMe.m
|||- Pod
||||- bfsdk.podspec
||||- LICENSE
||||- README.md
|||
|||- Support Files
||||- bfsdk.modulemap
||||- bfsdk.xcconfig
||||- bfsdk-dummy.m
||||- bfsdk-Info.plist
||||- bfsdk-prefix.pch
||||- bfsdk-umbrella.h
|
|- Frameworks
||- iOS
|||- CoreGraphics.framework
|||- Foundation.framework
|||- MobileCoreServices.framework
|||- Security.framework
|||- SystemConfiguration.framework
|||- XCTest.framework
|
|- Pods
||- Expecta
|||- ...
||- Specta
|||- ...
|
|- Products
||- ...
|
|- Target Supports Files
||- Pods-bfsdk_Example
|||- ...
||- Pods-bfsdk_Tests
|||- ...

(That's a lot of files for an "empty" project)

Ideally I would love if someone could explain the vast majority of what I'm looking at:

  • Why are CoreGraphics and UIKit included in an empty project?
  • What are the .xcconfig files all about? (Pods-bfsdk_Example.debug.xcconfig for instance)
  • What's with the bfsdk-dummy.m file?
  • What's the .modulemap file all about?
  • What's with the -umbrella.h file?
  • What's with the -prefix.pch file?
  • Why are MobileCoreServices, Security, and SystemConfiguration included in an empty project?
  • Why do the "example" and "tests" stuff show up in both the bfsdk project and the Pods project? Shouldn't one project be the library (and therefore have no knowledge of where it is being implemented, e.g. in the Example and Tests apps?)

Ignoring all of those questions, though, there is one thing that I definitely need help figuring out. In my Example app, namely in my bfsdk/Example for bfsdk/BFViewController.m file, I want to be able to import my library like so:

// Assuming I keep the file named "ReplaceMe" and use that as my class name:
#import <bfsdk/ReplaceMe.h>

@implementation BFViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    ReplaceMe *test = [[ReplaceMe alloc] init];
}

@end

This would mimic how other CocoaPods libraries are used. For instance, if I were to include AFNetworking into my project then I could include it with:

// Directly specify the class I want to use
#import <AFNetworking/AFHTTPSessionManager.h>

// Or specify the entire library
#import <AFNetworking/AFNetworking.h>

However when I try to include my class this way, auto-complete recommends:

#import <bfsdk/bfsdk-umbrella.h>

Trying to type anything else doesn't work.

So my question is: How do I declare ReplaceMe.h as a public header in CocoaPods so that anyone including my library can either use:

#import <bfsdk/bfsdk.h>

// or

#import <bfsdk/ReplaceMe.h>

来源:https://stackoverflow.com/questions/56842043/how-to-declare-public-header-files-as-cocoapod-author

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!