我有一个快速的项目,我想要检索设备名称并在UITableViewCell
中显示。
但是当我想在
UIDevice.currentDevice()
时
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
编译器失败:
命令 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc 退出代码1失败
以下构建命令失败:
CompileSwift普通arm64"项目文件夹路径" /custom_tableview_controller.swift
CompileSwiftSources正常arm64 com.apple.xcode.tools.swift.compiler (2次失败)
尴尬的是在我的UIDevice.currentDevice()
文件工作之外的任何其他文件中调用custom_tableview_controller.swift
。
其他信息:
- Xcode 6.4(6E35b)
- 调试
答案 0 :(得分:1)
这也让我疯狂。我无法解决它。作为一种解决方法,我创建了一个Objective-C类,它只能完成UIDevice。我的班级是AWDevice
。在Swift中,编译器对AWDevice.currentDevice()
这真的很奇怪。
答案 1 :(得分:1)
我创建了用于在框架中使用Swift获取UIDevice:
创建Obj-c Header.h并添加
#import <UIKit/UIKit.h>
/**
* Static Current Device
* @note Can't get UIDevice CurrentDevice in Swift, Hack with obj-c
*
* @return UIDevice
*/
static UIDevice* Device() { return [UIDevice currentDevice]; }
在您的目标框架中 - &gt; Build Phases使这个:
在您的目标Framework.h中添加:
#import <BSStaticObjc.h>
现在使用Swift调用方法
Device()