some_id
some_id

Reputation: 29886

Swift method to return a tuple in objective c class

I would like to return two objects from a method using swift.

How can this method be added to an existing objective c class to access the tuple from where ever the method is called, in non swift files?

Does the tuple need to be created in a swift class?

Upvotes: 10

Views: 8446

Answers (1)

codester
codester

Reputation: 37189

Tuple is not compatible in objective c.You can use Dictionary instead of tuple .From swift documentation.

You’ll have access to anything within a class or protocol that’s marked with the @objc attribute as long as it’s compatible with Objective-C. This excludes Swift-only features such as those listed here:

Generics
Tuple     //Tuple cannot be acesses from objective c
Enumerations defined in Swift
Structures defined in Swift
Top-level functions defined in Swift
Global variables defined in Swift
Typealiases defined in Swift
Swift-style variadics
Nested types
Curried functions

For example, a method that takes a generic type as an argument or returns a tuple will not be usable from Objective-C.

You cannot use these types in objective c in which tuple is included and cannot be accessed and it is not bind with any type in objective c and not compatible with objective c.

However you can do each and every thing with Swift Dictionaries that you can do with tuple.Use Dictionary instead of tuple.

Upvotes: 17

Related Questions