您的位置:首页 > 移动开发 > Swift

OC调用Swift

2016-05-17 11:01 375 查看

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

Create new
*.swift
file (in Xcode) or add it by using Finder

Add swift bridging empty header if Xcode have not done this before (see 4 below)

Implement your Swift class by using
@objc
attribute:

import UIKit

@objc class Hello: NSObject {
func sayHello() {
print("Hi there!")
}
}


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

Import header (which is auto generated by Xcode) in your *.m file

#import "myproject-Swift.h"


Clean and rebuild your Xcode project

Profit!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: