6. OBJECTIVE-C WITHIN SAME TARGET
Add Objective-C files to the Bridging-Header
Bridging-Header needs to be referenced in
build settings
Project-
Bridging-
Header.h
A.swift B.swift
MyObj.h
Car.h
MyObj.m
Car.m
8. THIRD PARTY FRAMEWORKS
If framework is written in Obj-C
And framework is not built as a module
Add framework header to bridging-header:
#ifndef Makestagram_Makestagram_Bridging_Header_h
#define Makestagram_Makestagram_Bridging_Header_h
#import <Parse/Parse.h>
#endif
14. OPTIONALITY IN OBJ-C
Since latest release of Objective-C we can
specify whether values can be nil or not
For unaudited APIs: Implicitly unwrapped
Optionals by default!
15. OPTIONALITY IN OBJ-C
// unaudited version -> generates warning
+ (UIView *)createViewWithName:(NSString *)name;
// return value and argument are non-optional
+ (__nonnull UIView *)createViewWithNameSwiftier:(__nonnull NSString *)name;
// return value and argument are optional
+ (__nullable UIView *)createViewWithNameSwiftierNullable:(__nullable NSString *)name;
21. OBJECTIVE-C BEHAVIOR IN
SWIFT CLASSES
class User {
dynamic var name: String
dynamic func setUp() {
//...
}
}
Use the dynamic keyword to enable Objective-C
features such as KVO and performSelector: