2015-09-10 10 views
8

ho aggiornato a Swift 2.0 e io piuttosto non riesco a capire questo quando provo a registrare un suono:Come risolvere tipo di espressione è ambigua, senza più contesto per un registratore audio in rapida 2

Tipo di espressione è ambigua, senza più contesto

su var recordSettings

Cosa devo fare per FixT questo errore e più importante, perché?

var recordSettings = [ 
     AVFormatIDKey: kAudioFormatAppleLossless, 
     AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue, 
     AVEncoderBitRateKey : 320000, 
     AVNumberOfChannelsKey: 2, 
     AVSampleRateKey : 44100.0 
    ] 

    var dirPaths = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true) 
    var docsDir: AnyObject = dirPaths[0] 
    var soundFilePath = docsDir.stringByAppendingPathComponent("tempRecordzz") 
    var soundFileURL:NSURL = NSURL(fileURLWithPath: soundFilePath) 



    var error: NSError? 
    do { 
     recorder = try AVAudioRecorder(URL: soundFileURL, settings: recordSettings) 
    } catch var error1 as NSError { 
     error = error1 
     recorder = nil 
    } 

risposta

15

Il tipo di kAudioFormatAppleLossless cambiato da Int (Swift 1.2/Xcode 6.4) per Int32 (Swift 2/Xcode 7) e UInt32 in Swift 7.0.1. Le dimensioni tipi interi fissi come Int32 e UInt32 sono non ponte automaticamente NSNumber oggetti per l'inserimento in un NSDictionary.

Una conversione esplicita aiuta a risolvere il problema:

let recordSettings = [ 
    AVFormatIDKey: Int(kAudioFormatAppleLossless), // <-- HERE 
    AVEncoderAudioQualityKey : AVAudioQuality.Max.rawValue, 
    AVEncoderBitRateKey : 320000, 
    AVNumberOfChannelsKey: 2, 
    AVSampleRateKey : 44100.0 
] 
+1

Perfetto. Grazie! –

+1

Vorrei un abbraccio: D .... Grazie mille – Husam

+1

'kAudioFormatAppleLossless' è' UInt32' a partire da Xcode7.0.1. – rintaro

Problemi correlati