Swift and OC in the same project

來源:互聯網
上載者:User

標籤:doc   ack   檔案中   library   idg   name   car   需要   建立   

15:08:02 2017-03-06

官方解釋文檔

Swift and Objective-C in the Same Project

 

其實只要知道方法,很簡單;

首先在OC項目中建立swift檔案 或者 在swift項目中建立OC檔案 都會自動提示需不要生產橋樑檔案(xxx-bridging-Header.h);

當然你可以手動建立這個橋樑檔案,然後在Build settings -> Swift Compiler-General -> Objective-C Bridging Header 中加入橋樑檔案的路徑。

這是關鍵的一步,xcode編譯時間候,需要到這個橋樑檔案處理這種混合語言。

 

在OC項目中匯入swift檔案

  在OC檔案中,#import "productName-swift.h"  productName可在Build settings ->Packaing->ProductName查看。

  好的,包含這個標頭檔後,再試一試能否使用swift的類了?

在swift項目中匯入OC檔案

  在橋樑檔案中,加入需要在swift檔案使用的OC標頭檔,例如 #import"car.h" 

  接下來你便可在swift檔案中使用OC的類了

Swift and OC in the same project

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.