Maybe I misunderstand enums in swift, but in obj-c I was using enums like this (and using a lot):
class SomeObject;
typedef NS_ENUM(NSUInteger, SomeType) {
Type1 = 0,
Type2, // = 1
Type3, // = 2
TypeInvalid // = 3
};
- (SomeType)getTypeOf(NSArray *a, SomeObject *o) {
//for (int i = 0; i < a.count; ++i)
// if ([a[i] isEqual:o])
// return i;
NUInteger result = [a indexOfObject:o];
return result == NSNotFound ? TypeInvalid : result;
}
// Also I could use this:
a[Type3] = someObject;
How to do the same in Swift? Am I forced to use constants (let Type1 = 0), like in Java (public static final int Type1 = 0;)?
isEqual:, just useindexOfObject:.