码迷,mamicode.com
首页 > 编程语言 > 详细

OC调用Swift

时间:2016-05-17 11:38:33      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:

Step by step swift integration for Xcode Objc-based project:

  1. Create new *.swift file (in Xcode) or add it by using Finder
  2. Add swift bridging empty header if Xcode have not done this before (see 4 below)
  3. Implement your Swift class by using @objc attribute:

    import UIKit
    
    @objc class Hello: NSObject {
        func sayHello() {
            print("Hi there!")
        }
    }
  4. Open Build Settings and check those parameters:
    • Product Module Name : myproject
    • Defines Module : YES
    • Embedded Content Contains Swift : YES
    • Install Objective-C Compatibility Header : YES
    • Objective-C Bridging Header : $(SRCROOT)/Sources/SwiftBridging.h
  5. Import header (which is auto generated by Xcode) in your *.m file

    #import "myproject-Swift.h"
  6. Clean and rebuild your Xcode project
  7. Profit!

OC调用Swift

标签:

原文地址:http://www.cnblogs.com/dzhs/p/5500747.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!