Saad Ullah Saad Ullah - 4 months ago 9
iOS Question

My application is not running on iPhone/iPad but running fine on simulator

I'm getting all the data from a server and parsing it using JSON. After getting each story, I made a class called

MyStory
.

class MyStory: NSObject
{
var location = ""
var storyId = 0
var title = ""
var story = ""
var AllImages = [Image]()

var images = NSArray() {
willSet(newValue){

// print("newvalue \(newValue)")

for obj in newValue {
let img = Image(dictionary: obj as! [String : AnyObject])
AllImages.append(img)

//imagePaths.append(img.imagePath)
let helper = HelperClass()

var imageDetail = "http://www.sleeksolutions.net/saad/" + img.imagePath
helper.imagepath.append(imageDetail)



//print("counter: \(helper.imagepath.count)")

}
}
}

init(dictionary: [String:AnyObject]) {
super.init()
self.setValuesForKeysWithDictionary(dictionary)
}

override func setValue(value: AnyObject?, forKey key: String) {
if key == "images"
{
// print("key = \(key) , value : \(value)")
}
//error occurs here.
super.setValue(value, forKey: key)
}

}


And this function is called by the class
SeeStories
. Here is the code:

let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL: url!)
request.timeoutInterval = 10
request.HTTPMethod = "GET"

let task = session.dataTaskWithRequest(request)
{
(dat, res, er) in

if er == nil
{
do
{
print("m hereeee")
self.serverStatus = true

let jsonObject = try NSJSONSerialization.JSONObjectWithData(dat!, options: .MutableContainers)
let arr = jsonObject as! NSDictionary

//print(jsonObject)

let storiees = arr["stories"] as! NSArray

for obj in storiees{
//Calling to MyStory Class here
let s = MyStory(dictionary: obj as! [String : AnyObject])
self.stories.append(s)

let stat = self.fetch(s)

if stat == false
{
self.saveInCoreData(s)
}
}
}
}
}


Here is the picture of error in terminal

Answer

Check the dictionary you are getting (which you use to create a MyStory object). From the looks of it, storyId is returned as a String and you try to save it into a long. storyId should be setup as a String variable instead

class MyStory: NSObject
{
    var location  = ""
    var storyId = "" //THIS instead of = 0
    var title = ""
    var story = ""...

I could be wrong but this is my best guess from the error log shown in your question.

Comments