I am trying to use Objective-C API in Swift and I have to typecast Swift Dictionary to NSSDictionary but if some way I can declare the NSDictionary in below written format, I can skim out redundant typecasting.
typedef NSDictionary* NSDictionary<NSString *, id> *;
In my Objective-C API there are several dictionaries and I want all them converted into above typdef.
You are trying to redefine all NSDictionary
as NSDictionary<NSString *, id>
. That's a big no-no. Instead, create your own type:
typedef NSDictionary<NSString *, id> MyDictionary;
// Usage
MyDictionary * dict = [MyDictionary dictionaryWithObjectsAndKeys:@1,@"one", @2,@"two", @3,@"three", nil];
Swift:
typealias MyDictionary = [String: Any]
let aDict: MyDictionary = [
"one": 1, "two": 2, "three": 3
]
func doSomething(aDict: MyDictionary) {
// ...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With