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

176
Vistas
Swift: Where Is NSDragOperationNone?

In Objective-C, I can return NSDragOperationNone from various drag/drop methods to indicate that I do not want to handle a given drag. This is listed explicitly in Apple's Docs for the Objective-C version of NSDragOperation:

https://developer.apple.com/documentation/appkit/nsdragoperation?language=objc

However, if you view that page for Swift, or you look at the NSDragOperation definition in Apple's Swift headers, .none is not an option.

So...how do I decline a drag operation in Swift? In a method such as:

func tableView(_ tableView: NSTableView, validateDrop info: NSDraggingInfo, proposedRow row: Int, proposedDropOperation dropOperation: NSTableView.DropOperation) -> NSDragOperation

NOTE:

1) I am explicitly dealing with AppKit and macOS, not UIKit or iOS.

2) I realize I can just init NSDragOperation with a rawvalue of 0, which is the value given to NSDragOperationNone in Objective-C, but that's fragile. What is the Swift way of declining a drag?

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

0

You might have realised this already, but NSDragOperation is a bit mask. The value of each case is a power of 2, and you are supposed to use | to mask them in Objective-C.

In Swift, NSDragOperation is bridged to conform to OptionSet and you can use them with a set-like syntax like this:

let dragOp: NSDragOperation = [.copy, .link]

So a none operation is just an empty set:

let dragOp: NSDragOperation = []
over 4 years ago · Santiago Trujillo Denunciar

0

Use []. .none is deprecated. See https://forums.developer.apple.com/thread/65205

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