Questions tagged [associated-value]

34 questions
0
votes
2 answers

Filter array of items by enum property with associated value

class MyClass: Decodable { let title: String? let type: MyClass.MyType? enum MyType { case article(data: [Article]) case link(data: [LinkTile]) case none } } I would like to filter an array of MyClass…
Luda
  • 7,282
  • 12
  • 79
  • 139
0
votes
0 answers

Check for single case inequality on Swift associated enum? Error: "Variable binding in a condition requires an initializer"

I'm trying to compare inequality for a single case of my associated enum. enum ResponseEnum { case loading case success(responseArray) case failure(Error) } I can check if it is loading in a single line by writing: if case .loading =…
teradyl
  • 2,584
  • 1
  • 25
  • 34
0
votes
1 answer

Associate letters with its value and sort output in python

Please help on this. I have an input like this: a = """A|9578 C|547 A|459 B|612 D|53 B|6345 A|957498 C|2910""" I want to print in sorted way the numbers related with each letter like this: A_0|459 A_1|957498 A_2|9578 C_0|2910 C_1|547 …
Ger Cas
  • 2,188
  • 2
  • 18
  • 45
0
votes
2 answers

Exception handling with Swift 2 to 4 Migration

I'm migrating some code originally written in Swift2 to Swift4. I've completed the Swift3 intermediate upgrade and am hitting some errors in Xcode9 regarding some user defined enum uses outside their source file. Consider the following partial…
jxramos
  • 7,356
  • 6
  • 57
  • 105
1 2
3