jmzwebb
jmzwebb

Reputation: 43

Objective-C equivalent to Swift's "Any"

Is there any way that an Objective-C method could operate on primitive parameters without knowing their types? For instance,

-(Any)returnFirst:(Any)first notSecond:(Any)second  {
  return first;
}

This could then be used like:

int a = [self returnFirst:500 notSecond:1000];
char b = [self returnFirst:'a' notSecond:'b'];

Upvotes: 3

Views: 2895

Answers (2)

Vlad
Vlad

Reputation: 6732

In Swift 3, the id type in Objective-C now maps to the Any type in Swift, which describes a value of any type, whether a class, enum, struct, or any other Swift type.

Source: https://developer.apple.com/swift/blog/?id=39

Upvotes: 1

rob mayoff
rob mayoff

Reputation: 385830

There is no equivalent to Any in Objective-C. Your example returnFirst:notSecond: cannot even be declared in Objective-C.

Upvotes: 1

Related Questions