簡體   English   中英

Swift UIDevice.currentDevice()無法編譯

[英]Swift UIDevice.currentDevice() not compiling

我有一個快速的項目,我想在其中檢索設備的名稱並顯示在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個失敗)


尷尬的事情是在我的custom_tableview_controller.swift文件custom_tableview_controller.swift正常工作的任何其他文件中調用UIDevice.currentDevice()

附加信息:
-Xcode 6.4(6E35b)
-調試

這也讓我發瘋。 我無法解決。 作為一種解決方法,我制作了一個僅繼承UIDevice的Objective-C類。 我的課是AWDevice 在Swift中,編譯器對AWDevice.currentDevice()很滿意

這真是奇怪。

我使用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]; }

在目標框架->構建階段中進行以下操作:

在此處輸入圖片說明

在您的目標Framework.h中添加:

#import <BSStaticObjc.h>

現在在Swift調用方法中

Device()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM