[英]Swift UIDevice.currentDevice() not compiling
I have a swift project in which i want to retrieve the name of the device and show in in a UITableViewCell
. 我有一个快速的项目,我想在其中检索设备的名称并显示在UITableViewCell
。
But when i want to call UIDevice.currentDevice()
in 但是当我想在中调用UIDevice.currentDevice()
时
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
the compiler fails with: 编译器失败并显示:
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1 命令/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc失败,退出代码为1
The following build commands failed: 以下构建命令失败:
CompileSwift normal arm64 "path to project folder"/custom_tableview_controller.swift CompileSwift正常的arm64“项目文件夹的路径” /custom_tableview_controller.swift
CompileSwiftSources normal arm64 com.apple.xcode.tools.swift.compiler (2 failures) CompileSwiftSources正常的arm64 com.apple.xcode.tools.swift.compiler(2个失败)
The awkward thing is calling UIDevice.currentDevice()
in any other file than my custom_tableview_controller.swift
file is working. 尴尬的事情是在我的custom_tableview_controller.swift
文件custom_tableview_controller.swift
正常工作的任何其他文件中调用UIDevice.currentDevice()
。
Additional information: 附加信息:
- Xcode 6.4(6E35b) -Xcode 6.4(6E35b)
- Debug -调试
This has been driving me crazy as well. 这也让我发疯。 I can't fix it. 我无法解决。 As a workaround I made an Objective-C class that solely sublcasses UIDevice. 作为一种解决方法,我制作了一个仅继承UIDevice的Objective-C类。 My class is AWDevice
. 我的课是AWDevice
。 In Swift the compiler is happy with AWDevice.currentDevice()
在Swift中,编译器对AWDevice.currentDevice()
很满意
This is really strange. 这真是奇怪。
I create that for get UIDevice in framework with Swift : 我使用Swift在框架中创建用于获取UIDevice的方法:
Create Obj-c Header.h and add 创建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]; }
In your target Framework -> Build Phases make this : 在目标框架->构建阶段中进行以下操作:
In your target Framework.h add : 在您的目标Framework.h中添加:
#import <BSStaticObjc.h>
Now in Swift call method 现在在Swift调用方法中
Device()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.