0

I have used xCode 6.3's convertor to convert my project to swift 1.2, After that i was still left with many errors, but i fixed them all manually.

Now when i compile i get:
<unknown>:0: error: '[Set<T>]' is not convertible to 'Hashable'.

The only place i use Set is:

var productID:Set<NSObject> = [subscriptionId]
var productsRequest:SKProductsRequest =    SKProductsRequest(productIdentifiers: productID )

I have tried cleaning the project and also tried deleting the DerivedData folder, but that didn't help.

I have searched but i couldn't find anyone with the same problem.
Anyone know how to solve this?

Amitay
  • 468
  • 5
  • 20

1 Answers1

0

This won’t be a problem with derived data. It looks like where previously you had an NSArray (probably of NSSet), you now have an Array of Set. Presumably you’re then trying to do something like use that value to key a dictionary type. In 6.3, several API calls that previously returned NSSomething now return native Swift types.

Swift Arrays aren’t hashable (because they might contain something that isn’t hashable). NSArrays are (though not always in a helpful way, depending on what they contain, so be wary).

Bear in mind, with type inference, that your explicit use of Set or Array won’t be the only places you might have a set. If you call a function that returns an array of sets, and you assign that value like so: let thing = funcThatReturnsArrayOfSets() then you will have a [Set<whatever>] even without explicitly writing that type in your code.

To fix this, you need to find the line where you’re getting the error, look at the types involved, then trace back to where those variables were declared. Option-click all the things to see what types they are.

Airspeed Velocity
  • 40,491
  • 8
  • 113
  • 118
  • I have went over the iOS 8.3 API diffs and i could find any api that i am using that has changed to Set... but i will keep looking.. – Amitay Apr 16 '15 at 12:27
  • The problem isn’t that you have a set, the problem is that you have an array i.e. it’s `[Set]` rather than the `NSArray` it used to be. It happens to contain a `Set`, but it’s the array that’s the issue, since Swift arrays are’t hashable. – Airspeed Velocity Apr 16 '15 at 12:33
  • its hard to pinpoint the error, i don't have a line number or anything... just that error... – Amitay Apr 16 '15 at 12:37
  • OK, so i have fixed it, So before swift 1.2 i had a class named Set. after 1.2 i renamed the class, apparently i have missed renaming a reference. after renaming it, it compiles properly. thank you for your help. And Apple, refactoring for swift would be nice :) – Amitay Apr 16 '15 at 13:04