1

I am new to Swift, iOS development.

HTTP Request :

request.httpBody = postString.data(using: .utf8)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
    guard let data = data, error == nil else {                                                 // check for fundamental networking error
        print("error=\(error)")
        return
    }

    if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {           // check for http errors
        print("statusCode should be 200, but is \(httpStatus.statusCode)")
        print("response = \(response)")
    }

 let responseString = String(data: data, encoding: .utf8)
    print("responseString = \(responseString)")
}
task.resume()

Response String looks like this

BEGIN:VCALENDAR
PRODID:-//MobileUGStdTT//iCal4j 1.0//EN //DateGenerated 06 May 2017 12:05
 :07
VERSION:2.0
CALSCALE:GREGORIAN
BEGIN:VEVENT
DTSTAMP:20170506T040507Z
DTSTART:20170109T090000
DTEND:20170109T120000
SUMMARY:SG4207 (L)
DESCRIPTION:SG4207-MOBILE WIRELESS SOLUTION DESIGN (LECTURE)
LOCATION:ISS-03-03
UID:20170506T040507Z-MobUGStdTT@fe80:0:0:0:250:56ff:fea6:c7e%3
TZID:Asia/Singapore
BEGIN:VALARM
TRIGGER:-PT15M
REPEAT:4
DURATION:PT5M
ACTION:DISPLAY
DESCRIPTION:SG4207-MOBILE WIRELESS SOLUTION DESIGN (LECTURE) @ ISS-03-03\
 , starts 0900
END:VALARM
END:VEVENT
BEGIN:VEVENT
DTSTAMP:20170506T040507Z
DTSTART:20170116T090000
DTEND:20170116T120000

I need to convert this response to NSDataDictionary/ENUM, Since its not a regular JSON I am finding it hard to convert it to.

These are the Keys - DTSTART,SUMMARY,DESCRIPTION I am in need of.

Thanks for your help.

Dilip Tiwari
  • 1,441
  • 18
  • 31
Raghu
  • 313
  • 2
  • 7
  • 19
  • 1
    The text is in iCalendar (.ics) format which can be parsed with NSScanner or regular expression. – vadian May 06 '17 at 04:47
  • https://github.com/KiranPanesar/MXLCalendarManager ? from http://stackoverflow.com/questions/5059554/parse-ics-data-in-iphone-project – Larme May 06 '17 at 08:56
  • I am trying to use this library via cocoapods, It is giving me a error "Unable to find the specification" for MXLCalendarManger – Raghu May 06 '17 at 11:53
  • You have to do it your self, you can inspire you with some other works: https://github.com/kiliankoe/iCal (in Work In Progress) or https://github.com/MasudShuvo/IcsParser/blob/master/IcsParser/Parser/MSCalendarICSParser.m It seems there is nothing all done. – Larme May 06 '17 at 14:20
  • Thanks @Larme , I figured out a way to parse the ical format. Now I have it as a array of string array [0] BEGIN:VCALENDAR array[1]VERSION:2.0 array[2]CALSCALE:GREGORIAN array[3]BEGIN:VEVENT array[4]DTSTAMP:20170506T040507Z array[5]DTSTART:20170109T090000 and goes on ..... Now I need to convert this to class structure. how to pass data to the class via a object – Raghu May 07 '17 at 05:11

0 Answers0