Posts

Showing posts from May, 2019

Swift code in Objective-C

Image
Xcode allows to write you with a Swift and use it in your existing project which could be in Objective-C. Consider the below UserObject Swift Written Class. UserObject Class in Swift import Foundation class UserObject: NSObject {     var userId: String ?          func printName(nameValue: String ) -> Void {         print ( "Name = \ ( nameValue )" )     }         func printAnotherName(nameValue: String ) -> Void {         print ( "Name = \ ( nameValue )" )     } } ViewController in Objective-C Now what if you want this newly written UserObject Swift Class to use in your existing Objective-C Class. @interface ViewController () @end @implementation ViewController - ( void )viewDidLoad {     [ super viewDidLoad ];     UserObject *userObject = [[ UserObject alloc ] init ];      userObject. userId = @"1" ;     [ userObject   printNameWithNameValue : @"Joh