我一直在尝试检出CocoaPods新框架设置以使某些Pod运行起来,而在我的Objective-C项目中使用Swift时遇到了麻烦。
首先,这是CocoaPods预发行版0.35,您可以在此处阅读有关如何使用和安装它的信息。
这是我当前的Podfile:
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
pod 'MBProgressHUD'
pod 'SLPagingViewSwift'
MBProgressHUD是常见的旋转指示器,SLPagingViewSwift是一个随机项目,我通过在cocoapods搜索中键入Swift来找到。这是ViewController.m在我的项目中:
#import "ViewController.h"
@import SLPagingViewSwift;
@import MBProgressHUD;
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    
    // Works just fine
    MBProgressHUD *hud = [[MBProgressHUD alloc] initWithView:self.view];
    [self.view addSubview:hud];
    [hud show:YES];
    // Causes Error -- Won't build
    SLPagingViewSwift *sl = [[SLPagingViewSwift alloc] init];
}
@end
这是SLPagingViewSwift声明:
class SLPagingViewSwift: UIViewController, UIScrollViewDelegate {
如您所见,它继承自UIViewController,因此只需分配它并对其进行初始化就不成问题。如果我将文件单独添加为文件,则上面的代码运行良好。我知道这行得通。
tl; dr
如何在纯Objective-C类中使用CocoaPods创建的纯Swift框架?
故障排除
通常,我一直在尝试各种进口产品。苹果在这里推荐@import款式

但我一直在尝试其他多个品种:
// Compiler Error
#import <SLPagingViewSwift/SLPagingViewSwift.h>
// Builds Fine -- Doesn't Work
#import <SLPagingViewSwift/SLPagingViewSwift-Swift.h>
#import "SLPagingViewSwift-Swift.h"
我还不时尝试其他一些Swift库,以查看是否可以单击任何东西。
在Cocoapods问题上,我看不到有什么可以解决的,在他们的博客/发行资料中也没有发现任何东西。
注意
如果我SLPagingViewSwift.swift以老式方式将文件单独添加到项目中,则效果很好。