Class and Category
Basic Class Definition
Objective-C
@interface Foo
@property int bar;
-(void)method;
@end
@implementation Foo
-(void)method {
// do something
}
@end
Swift
class Foo {
var bar:Int
func method() {
// do something
}
}
Inheritance
Objective-C
@interface Foo : Bar
@end
@implementation Foo
// ...
@end
Swift
class Foo : Bar {
// ...
}
Anonymous Category
Properties declared in interface or anonymous category are converted into instance variables of a single class together.
Properties from the anonymous category are treated as private.
Objective-C
@interface Foo
@property int bar;
@end
@interface Foo ()
@property int baz;
@end
@implementation Foo
@end
Swift
class Foo {
var bar:Int
private var baz:Int
}