Reswift: newState() is not executing

Created on 20 May 2018  路  3Comments  路  Source: ReSwift/ReSwift

I have this code in one of my TableViewControllers:

import UIKit
import ReSwift

class ProfileTableViewController: UITableViewController, StoreSubscriber {
    var user: User?

    @IBOutlet weak var userLabel: UILabel!

    override func viewDidLoad() {
        super.viewDidLoad()

        print("This code definately works")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func newState(state: AppState) {
        self.user = state.user
        self.userLabel.text = self.user?.displayName;
    }
}

However, the newState() function is never called.

Is there anything else I need to do?

The weird part is I have another ViewController in my code, and newState works fine there. It's just this one that doesn't work.

Most helpful comment

@dolanmiu welp thanks, just had the same issue :)

All 3 comments

I just tried to do an even simpler case, still failed (Yes I have binded my view controller class to the storyboard view):

import UIKit
import ReSwift

class HomeViewController: UIViewController, StoreSubscriber {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    func newState(state: AppState) {
        print(state)
    }
}

Ignore me, I forgot to add store.subscribe(self)

@dolanmiu welp thanks, just had the same issue :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

MichaelGuoXY picture MichaelGuoXY  路  7Comments

dolanmiu picture dolanmiu  路  6Comments

adamhongmy picture adamhongmy  路  3Comments

nferruzzi picture nferruzzi  路  10Comments

jn000 picture jn000  路  5Comments