I have created a class as below:

import Foundation
import RealmSwift

class StockCellContent: Object{

    @objc dynamic var StockName: String = ""
    @objc dynamic var image: String = ""
    @objc dynamic var requiredStockPrice: Double = 0.0000
    @objc dynamic var requiredPriceUpOrDown: String = ""
    @objc dynamic var StockPrice: Double = 0.0000
    //var parentCategory = LinkingObjects(fromType: Category.self, property: "StockCellContent")


then i have created a object of that class and called a function which gets the data through an api and saves it in the object. Then i add the object to an array to be printed on the UITableView. The UITableView prints the values perfectly fine but when i try to pass the same object anywhere else or even print it to the console the data becomes nil or the default value with which it has been initialised. I don't understand what i am doing wrong here.

the function is as below:

func dataReceived(data: String) {
    self.stockKeyword = data
    //var stockData = StockCellContent()
    //var stockDataTest = StockObjectTest()
    let params = ["function" : "GLOBAL_QUOTE", "symbol" : stockKeyword, "apikey" : stockApiKey]
    let stockData = getStockPriceFromJSON(url: stockApiURL, parameters: params)


    //self.stockCellContents = stockData
    self.save(stockCellContent: stockData)

    self.stockUpdateFlag = true

The print of stockData.StockPrice shows 0.0 even stockData.StockName shows empty

0 Answers