ios - Swift 3.0 Couldn't get required object pointer (substituting NULL): Couldn't load 'self' because its value couldn't be evaluated -
when executing code:
public enum month : string { case january = "jan" case february = "feb" case march = "mar" case april = "apr" case may = "may" case june = "jun" case july = "jul" case august = "aug" case september = "sep" case october = "oct" case november = "nov" case december = "dec" func todate() -> date { let dateformatter = dateformatter() dateformatter.dateformat = "dd.mmm.yyyy hh:mm a" let datestring = "01.\(self.rawvalue).2016 12:00 pm" return dateformatter.date(from: datestring)! } }
i'm getting:
fatal error: unexpectedly found nil while unwrapping optional value
when try printing "po dateformatter.date(from: datestring)!" crash happening:
fatal error: unexpectedly found nil while unwrapping optional value error: warning: couldn't required object pointer (substituting null): couldn't load 'self' because value couldn't evaluated
error: execution interrupted, reason: exc_breakpoint (code=1, subcode=0x100c551ec). process has been returned state before expression evaluation.
this happening on iphone 6s running ios 10.1.1 , not happening on of simulators , on device running ios 9.x.x
anyone has idea whats going on , "couldn't load 'self' because value couldn't evaluated" means.
i tried in new project code , can still reproduce error.
even hardcoding month, without self part gives same error:
let datestring = "01.nov.2016 12:00 pm"
update
for coming proper way construct date object this:
let calendar = calendar.current var components = datecomponents() components.day = 1 components.month = month components.year = year components.hour = 12 components.minute = 00 let date = calendar.date(from: components)!
your code give totally incorrect results in less 2 months time. , crash if user's locale not english speaking.
Comments
Post a Comment