Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
How to exclude an C enum case when using the type in Swift

In my C code I generally have an enum case called count at the end. But when I use my enum in Swift it will also have that value, which I must handle in switch statements.

Is there some attribute I can use to exclude a case when importing into Swift?

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You can use the NS_SWIFT_UNAVAILABLE macro on enumerators:

typedef NS_ENUM(unsigned, Foo) {
    bar,
    baz,
    count NS_SWIFT_UNAVAILABLE("Count does not represent a case")
};

NS_SWIFT_UNAVAILABLE, like any __attribute__ that you want to apply to an enumerator, goes after the enumerator name but before the = if you need one.

The macro is defined if you include <Foundation/Foundation.h>. If you include CoreFoundation, you get CF_SWIFT_UNAVAILABLE, which does the same thing. If you include neither, you can use the long form:

__attribute__((availability(swift, unavailable, message="your message")))

Enumerators that are annotated with NS_SWIFT_UNAVAILABLE won't show up in autocomplete, and won't cause build issues if they're not handled on the Swift side. If you attempt to use it, you get a hard error that includes your message.

Keep in mind that starting with Swift 5, you may need to use NS_CLOSED_ENUM instead of NS_ENUM if your purpose is to avoid having a default case.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda