ios - EXC_BAD_ACCESS in HealthKit in reading dateOfBirthWithError -
when call following function read dataofbirth, keep receiving bad access error while testing on device. i'm using swift 2.0 in xcode 7 beta
func updateusersage(){ do{ var error : nserror! let birthdate = try currenthealthstore.dateofbirthwitherror() let = nsdate() let datecomponents = nscalendar.currentcalendar().components(nscalendarunit.nsyearcalendarunit, fromdate: birthdate, todate: now, options: nscalendaroptions.wrapcomponents) let age = datecomponents.year self.agevaluelabel.text = nsnumberformatter.localizedstringfromnumber(nsnumber(integer: age), numberstyle: nsnumberformatterstyle.nostyle) } catch{ print("not avaialble") } }
currenthealthstore defined in appdelegate global variable:
let currenthealthstore = hkhealthstore()
and error received once line executed:
let birthdate = try currenthealthstore.dateofbirthwitherror()
this code works me in swift 2, xcode 7.1.1
let birthday = try healthstore.dateofbirth()
the name dateofbirthwitherror has been used before error passed throws.
Comments
Post a Comment