From now on, I would like to develop iOS applications with Swift, but I would also like to utilize the source code of Objective-C that I have created so far.How do I configure the Objective-C source code to be included in the Swift project?
xcode swift objective-c
<ProductName>-Bridging-Header.h must be created so that Swift can reference the Objective-C class.
Below is the procedure for using the Objective-C class for the new Swift project.
Create Any Class with Objective-C
#import<Foundation/Foundation.h>
@ interfaceObjcClass —NSObject
-(void)log;
@end
@implementationObjcClass
-(void)log{
NSLog (@"Objc Class Log");
}
@end
Select YES as you are asked if you want to create Bridging-Header.h
Import the Objective-C class you want to use from Swift into -Bridging-Header.h
#import "ObjcClass.h"
Write the code using the Objective-C class from the swift file
func application(application:UIApplication, didFinishLaunchingWithOptions launchOptions:[NSObject:AnyObject]?) ->Bool{
varobjcClass=ObjcClass()
objcClass.log()
// Override point for customization after application launch.
return true
}
I will also post a sample project.
You must first create a Bridging Header file that bridges between Objective-C
and Swift
.
XCode 6.1 Japanese Language Planning Table of Contents is familiar.
Other precautions for interoperability are summarized and recommended.
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
618 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.