I define a class in Swift like that:
class RecordedAudio: NSObject {
var title: String!
var filePathUrl: NSURL!
init(title: String, filePathUrl: NSU
lastPathComponent
returns an optional String:
but your RecordedAudio
seems to require String
not String?
.
There are two easy ways to fix it:
Add !
in case you are sure lastPathComponent will never return nil
recordedAudio = RecordedAudio(title: recorder.url.lastPathComponent!, filePathUrl: recorder.url)
or
Use a default title in case lastPathComponent is nil
recordedAudio = RecordedAudio(title: recorder.url.lastPathComponent ?? "Default title", filePathUrl: recorder.url)