Use of bridgeToObjectiveC() in swift

ios, swift

Solution

My understanding is that `bridgeToObjectiveC()` is provided so that you don't necessarily need to know what the corresponding objective-c type is; the compiler decides what the appropriate type is.

For example: if you have an array of `Any` objects can you call `bridgeToObjectiveC()` on each of them with `map` without worrying about whether there are String, Int, and Double values.

Using the `as` keyword allows you to explicitly choose which type you want to cast the value as.

Problem

What does bridgeToObjectiveC() will do in swift. It seems like converting a `Swift` object into `ObjectiveC` object. Is this same as type casting? For example i can convert a swift `String` into `NSString` like ``` var swingString:String = "test string" var correspondingNSString = swingString.bridgeToObjectiveC() // Using bridge var correspondingNSString = swingString as NSString // type casting ``` I want to know both are same or not?

Original source