Jeppe Christensen Jeppe Christensen - 6 months ago 48
Swift Question

REST and swift, entities are nil

So i have the following xml file here from which i want to get the information and display it inside my application.

I have made the following code:

class Parsexml: NSObject {

var address: String?
var category: String?
var city: String?
var name: String?

override init()

init(address: String, category: String, city: String, name: String){
self.address = address
self.category = category = city = name
override var description: String {
return "address: \(address), category: \(category), city: \(city), name: \(name)"

protocol HomeModelProtocal: class {
func itemsdownloaded(items:NSArray)

class HomeModel: NSObject, URLSessionDataDelegate {
weak var delegate: HomeModelProtocal!

var data: NSMutableData = NSMutableData()

let urlpath: String = ""

So far, it complies without errors, and i tried to make a simple call to my class and make it print in the console, in order to see if i get any values from my xml.

However, all my constructors are null.

What am i missing?


This is a json file not xml. You could do something like this:

if let data = NSData(contentsOfURL: NSURL(string: "")!) {
   let json = try NSJSONSerialization.JSONObjectWithData(data, options:.AllowFragments)
   if let items = json as? [AnyObject] {
      for item in items {
         // init ur object

Also you could use third party lib for json parsing.