简体   繁体   English

Swift UIDevice.currentDevice()无法编译

[英]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.

相关问题 UIDevice.currentDevice()。beginGeneratingDeviceOrientationNotifications()无法正常工作 - UIDevice.currentDevice().beginGeneratingDeviceOrientationNotifications() not working 如何设置通知对象的“ UIDevice.currentDevice()”? - How to set the 'UIDevice.currentDevice()' for object of notification? iOS9:替代UIDevice.currentDevice()。setValue(...)强制定位 - iOS9: Alternative to UIDevice.currentDevice().setValue(…) to force orientation UIDevice.currentDevice()。orientation.isLandscape的目标c等效项是什么? - What is the objective c equivalent of UIDevice.currentDevice().orientation.isLandscape? 替代[UIDevice currentDevice] .identifierForVendor - Alternative to [UIDevice currentDevice].identifierForVendor UIDevice currentDevice模型可能的值 - UIDevice currentDevice model possible values [[UIDevice currentDevice] systemName] 的可能值; - Possible values for [[UIDevice currentDevice] systemName]; [UIDevice currentDevice]可以使用什么? - What can be used with [UIDevice currentDevice]? 使用OCMock模拟[[UIDevice currentDevice] userInterfaceIdiom] - Using OCMock to mock [[UIDevice currentDevice] userInterfaceIdiom] 为什么“ [[UIDevice currentDevice] identifierForVendor]”会导致内存泄漏? - why does “[[UIDevice currentDevice] identifierForVendor]”cause memory leak?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM