2017-01-12 41 views
1

這裏有一個有趣的挑戰......泛型繼承和斯威夫特編譯

對於一些工作原因,我想automatise所有UITableView對象,我們在辦公室編寫的管理。問題是,當你有一個應用程序與很多UITableView對象,你會不斷重複相同的數據採購模式:numberOfRowInSection,cellForRowAtIndexPath,等等......

我一直在想這個,我發現了一種自動化所有這種重複數據採購模式的方法:泛型繼承。

代碼太長,不能發佈到這裏,所以我創建了一個GitHub repo here

您會在Concept文件夾下找到一個遊樂場來演示概念是如何工作的。

在Framework文件夾下,您會發現一種將Playground概念轉換爲Swift框架的非工作方法。到現在爲止,它似乎是一個Swift編譯器錯誤,使其無法正常工作。下面是試圖編譯框架的命令行編譯器會引發什麼:

LLVM ERROR: Broken function found, compilation aborted! 
2017-01-12 07:37:36.228 xcodebuild[64275:5358071] DVTAssertions: Warning in /Library/Caches/com.apple.xbs/Sources/IDEFrameworks/IDEFrameworks-11766.1/IDEFoundation/Playgrounds/IDEPlaygroundAuxiliarySourceCompilerOperation.m:386 
Details: Unable to read diagnostics from file ".../GenericTableViewController/build/GenericTableViewController.build/Debug-iphoneos/GenericTableViewController.build/Objects-normal/armv7/GenericTableViewController.dia" (Invalid File): Invalid diagnostics signature 
Function: void XCGenerateDiagnosticsFromFile(NSString *__strong, NSString *__strong, NSDictionary *__strong, NSDictionary *__strong, IDEActivityLogSectionRecorder *__strong, BOOL (^__strong)(IDEActivityLogMessage *__strong)) 
Thread: <NSThread: 0x7ffb7c2a3f60>{number = 14, name = (null)} 
Please file a bug at http://bugreport.apple.com with this warning message and any useful information you can provide. 

這是非常奇怪的,因爲相同的代碼工作下一個遊樂場,但一個標準的Xcode項目下沒有編...

人有助於?

+0

請選擇一個更能描述您的問題的標題。 – Raphael

+0

這個消息很明顯,這是一個(潛在的)錯誤,所以我不確定問題是什麼。 – Raphael

+0

已經解決了,查下回答 –

回答

0

那麼,經過一番調查,我已經結束了正確的編譯。我發現Build Settings上的Optimization Level是關鍵。

默認情況下,它的版本號爲Noone,版本號爲Fast, Whole Module Optimization。現在,如果您將Debug設置爲Fast, Whole Module Optimization,它將在Debug上進行編譯,您可以使用上述代碼。

我將更新GitHub回購共享。謝謝你們。

更多信息:https://bugs.swift.org/browse/SR-2565