i attempting grab nsurl image or video when user selects through imagepickercontroller, using photos framework
import photos func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [string : anyobject]) { let url: nsurl = (info["uiimagepickercontrollerreferenceurl"] as! nsurl) mediauploadview.image = info[uiimagepickercontrolleroriginalimage]as? uiimage print(url) self.dismissviewcontrolleranimated(true, completion: nil) return uiimagepickercontrollerreferenceurl }
i receive error "unexpected non void return value in void function".
the end goal use nsurl upload image / video / gif firebase database.
i'm not sure if logic here correct, i'm still new coding. appreciated!
in swift, have in @ end of function before opening "{" return value going be, if don't, considered void function. void function means not return value. so, tell it return nsurl, try this:
import photos func imagepickercontroller(picker: uiimagepickercontroller, didfinishpickingmediawithinfo info: [string : anyobject]) -> nsurl { let url: nsurl = (info[uiimagepickercontrollerreferenceurl] as! nsurl) mediauploadview.image = info[uiimagepickercontrolleroriginalimage]as? uiimage print(url) self.dismissviewcontrolleranimated(true, completion: nil) return url
}
just copy , paste this, difference tells function return value be, , no longer return error. suggest removing "" around the
(info[uiimagepickercontrollerreferenceurl] as! nsurl)
this return nsurl.