Access NSString *const *Array in Swift

79 Views Asked by At

Still trying my best to learn swift and hit this problem with some old library code -

I have something like this -

static NSString *const fooStrings[] = {
  @"Foo"
}

Getting a value through this is rather easy in Objective C:

NSString *foo = fooStrings[0];

How do I get these in Swift though? I've tried casting UnsafePointer<NSString> and getting the string back with code similar to that above. I also tried fooStrings.elements[0] or trying dereferencing with &fooStrings.elements[0] or (fooStrings as UnsafePointer).pointee[0], but every time, it complains about not being able to do this with an NSString * strong.

I'm obviously out of my depth here and am asking for help as I wasn't able to find an answer to what looks like a straightforward thing to do.

0

There are 0 best solutions below