簡體   English   中英

將AppDelegate.h和AppDelegate.m替換為AppDelegate.swift

[英]Replace AppDelegate.h and AppDelegate.m to AppDelegate.swift

我只是有一個Objective-C項目,我想使用AppDelegate來訪問我的xcdatamodel,但是當我將AppDelegate.swift添加到我的項目時它會向我顯示編譯問題,這是錯誤的,因為它不知道AppDelegate使用了什么,什么是主要的。 然后我嘗試刪除AppDelegate.hAppDelegate.m並添加AppDelegate.swift ,但它也不起作用,仍然有編譯錯誤。 我怎么能添加AppDelegate.swift呢?

如果你想使用AppDelegate.swift而不是AppDelegate.h / AppDelegate.m ,你應該將Swift文件添加到項目中並刪除.h.m文件(當被問及橋接頭時,不要忘記單擊是)。 此外,您還應該刪除main.m因為它不再需要並且會導致鏈接器錯誤。

我建議您默認使用Swift創建一個新的Xcode項目,並檢查該項目中的AppDelegate代碼並將其復制/調整到您的項目中。

Teo是對的。 要解決main.m文件的編譯問題,請在類聲明之上添加@UIApplicationMain

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate 

暫無
暫無

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

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