Class
Class method
Objective-C
@implementation Foo
+(int)method {
return 0;
}
@end
Swift
class Foo {
class func method() -> Int {
return 0
}
}
Instance method
Objective-C
@implementation Foo
-(int)method {
return 0;
}
@end
Swift
class Foo {
func method() -> Int {
return 0
}
}
Method with params
Objective-C
@implementation Foo
-(void)method:(int)arg1 label:(NSString *)arg2 {}
-(void)method2:(int)arg1 :(NSString *)arg2 {}
-(void)method3:(int)arg1 arg2:(NSString *)arg2 {}
@end
Swift
class Foo {
func method(arg1:Int, label arg2:String!) {}
func method2(arg1:Int, arg2:String!) {}
func method3(arg1:Int, arg2:String!) {}
}
Override Completion
Objective-C
@interface SuperFoo
-(void)someMethod:(NSNumber *)arg;
@end
@interface Foo : SuperFoo
-(void)someMethod:(NSNumber *)arg;
@end
@implementation Foo
-(void)someMethod:(NSNumber *)arg {
// ...
}
@end
Swift
class Foo : SuperFoo {
override func someMethod(arg:NSNumber!) {
// ...
}
}
Respect Interface declaration
If the signature of the method implementation is different from interface, the generated swift code follows interface declaration. Such patterns are mostly apparel with nullability specifiers.
Objective-C
@interface Foo
-(NSString * nonnull)method;
@end
@implementation Foo
-(NSString *)method {
// ...
}
@end
Swift
class Foo {
func method() -> String {
// ...
}
}