How to use .symbolVariant(.contains: )

I'm getting a weird response from Xcode in trying to use symbolVariant(.contains). I also don't understand why it demands the type cast. What am I doing wrong?

Here's the code as text:

import SwiftUI

let Variants: [SymbolVariants] = [
  .circle,
  .square,
  .fill,
  .rectangle,
  .slash,
  .none
]

func varAvail(_ image: Image) -> [SymbolVariants] {
  var res: [SymbolVariants] = []
  for variant in Variants {
    if image.symbolVariant(.contains(variant)) as! Bool {
      res.append(variant)
    }
  }
}

Hello @hacksaw,

It's not totally clear to me what you are trying to do here so I can't offer a solution for you, but I can tell you that that code correctly does not compile:

contains(_:) is an instance method of SymbolVariants, but your code is attempting to call it as if it were a static method on SymbolVariants.

-- Greg

What I'm trying to do is given a particular symbol, find out what variants it has.

How to use .symbolVariant(.contains: )
 
 
Q