Swift UIDevice.currentDevice()不编译
我有一个快速的项目,我想要检索设备的名称并显示在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“项目文件夹path”/custom_tableview_controller.swift
CompileSwiftSources正常的arm64 com.apple.xcode.tools.swift.compiler(2次失败)
尴尬的是调用UIDevice.currentDevice()
在任何其他文件比我的custom_tableview_controller.swift
文件正在工作。
附加信息:
– Xcode 6.4(6E35b)
– debugging
我创build了用Swift获取框架中的UIDevice:
创buildObj-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]; }
在你的目标框架 – >构build阶段使这个:
在你的目标Framework.h中添加:
#import <BSStaticObjc.h>
现在在Swift中调用方法
Device()
这也一直让我疯狂。 我无法修复它。 作为一个解决方法,我做了一个Objective-C类,只是sublcasses UIDevice。 我的课是AWDevice
。 在Swift中,编译器很满意AWDevice.currentDevice()
这真的很奇怪