2015-09-20 4 views
8

Ho aggiornato a swift 2 e questa funzione ha creato un mal di testa per me.Errore Nil valore di argomento predefinito di non può essere convertito in tipo 'NSLayoutFormatOptions'

Ciò sta causando l'errore durante il tentativo di eseguire l'app. Non ho idea di come risolvere questo problema mentre sto cercando di aggiornarlo a swift 2. Ho fatto una ricerca approfondita ma non in grado di rimediare al codice. L'errore si verifica su: NSLayoutFormatOptions = nil durante la creazione della funzione.

internal extension UIView { 

    func addConstraints(format format: String, options: NSLayoutFormatOptions = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView]) { 
     addConstraints(NSLayoutConstraint.constraintsWithVisualFormat(format, options: options, metrics: metrics, views: views)) 
    } 

    func addUniversalConstraints(format format: String, options: NSLayoutFormatOptions = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView]) { 
     addConstraints(format: "H:\(format)", options: options, metrics: metrics, views: views) 
     addConstraints(format: "V:\(format)", options: options, metrics: metrics, views: views) 
    } 

} 

Grazie se si può aiutare. :)

Cordiali saluti Gerard Grundy

risposta

10

tuo parametro options non è dichiarato come opzionale, quindi non è possibile impostare un valore predefinito di nil.

O fare options un optional:

func addConstraints(format format: String, options: NSLayoutFormatOptions? = nil, metrics: [String: AnyObject]? = nil, views: [String: UIView]) 

o rimuovere = nil dalla firma:

func addConstraints(format format: String, options: NSLayoutFormatOptions, metrics: [String: AnyObject]? = nil, views: [String: UIView]) 
+0

ok che ha aiutato anche se ora sto ottenendo un errore qui: selectRowAtIndex func pubblico (indice: Indice) { \t \t selectedRowIndex = indice \t \t \t \t tableView.selectRowAtIndexPath ( \t \t \t NSIndexPath (forRow: index, inSection: 0), \t \t \t animato: false, \t \t \t scrollPosition: .Middle) \t} –

+0

Questa è una questione completamente diversa e ho non ho idea di come aiutarti a farlo ... ti suggerisco di pubblicare una nuova domanda con i dettagli su di esso in modo da poter risolvere questa nuova domanda da qualcun altro. – Moritz

+1

impostando scrollPosition: .Middle per scorrerePosition: .Non risolve il problema come un problema –