September 19, 2019

Swift – Codable

what is it

  • Allows creation of Swift object directly from JSON and vice versa
  • Introduced in Swift 4.0

How to use:

  • Derive your class/struct from Codeable
 struct Student : Codable {
	var name : String
	var roll_no: String
	var class : String
 }
  • Creating swift object from JSON string
let jsonData = jsonString.data(using: .utf8)
    let student = try JSONDecoder().decoder (Student.self, from jsonData)
    print (student.name)
  • use CodingKey when the Json variable is different from struct variable name
 struct Student : Codable {
	var name : String
	var rollNo: String
	var class : String

	enum CodingKeys: String, CodingKey {
       	 case name = “student_name”
       	 case rollNo = “roll_no”
       	 case class
   	 }

 }
  • Encoding is equally straight forward
let jsonData = try!

May 29, 2012

iPhone Tip: Single Tap Conference Dialing

If you belong to the lot who mark most percent of your time sheets with conf calls, this tip will at least reduce your frustration of manually dialing into those conference calls.

May 22, 2012

Remove Password from Adobe PDF files

In this quick how-to yow will learn how to remove password protection from those Adobe PDF files for which you have reader password with you.

April 24, 2012

Store Google+ Content to Evernote

There could be times when you want to store a Google+ post to Evernote to refer to it later. Lets see a quick way to do the same.