Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No newData event received in custom class #194

Closed
rickvdl opened this issue May 2, 2017 · 6 comments
Closed

No newData event received in custom class #194

rickvdl opened this issue May 2, 2017 · 6 comments

Comments

@rickvdl
Copy link

rickvdl commented May 2, 2017

Hi,

I'm currently working on a class that handles a few network requests. So far all Siesta examples and trying some things on my own worked fine, I just used the code in my UIViewController for testing purposes. When creating the class I noticed that the same requests I tried earlier in my UIViewController's suddenly don't work in my custom class. I do see the observerAdded and requested event in the resourceChanged delegate method, but the newData event never gets passed to my custom class.

The stripped down version of my class looks like this:

class AuthSessionController {
    
    init() {
        
        let api = Service(baseURL: "https://jsonplaceholder.typicode.com")
        api.resource("/users").addObserver(self).loadIfNeeded()
        
    }
}

extension AuthSessionController: ResourceObserver {
    func resourceChanged(_ resource: Resource, event: ResourceEvent) {
        print(event)
    }
    
    func resourceRequestProgress(for resource: Resource, progress: Double) {
        print(progress)
    }
    
    func stoppedObserving(resource: Resource) {
        print("Stopped")
    }
}

And I'm instantiating the class in my UIViewController as normal:

override func viewDidLoad() {
      super.viewDidLoad()
        
      let authSessionController = AuthSessionController() 
}

But for some reason this is what I see in the log:

observerAdded
requested

In my previous testing I did see the newData event and my data as expected. Using Charles I was able to see that the requests went fine, and the latestError property always returns nil.
I have been debugging for the last 2-3 hours but since there really isn't a lot of code I'm running out of ideas.

Thanks in advance

@jordanpwood
Copy link

My first thought is that I see that authSessionController is a local variable to viewDidLoad. Is there a strong reference to it somewhere? I have the same question about api as well.

@rickvdl
Copy link
Author

rickvdl commented May 2, 2017

@jordanpwood

Moving the variable above the viewDidLoad actually works.
Thanks!

@rickvdl rickvdl closed this as completed May 2, 2017
@pcantrell
Copy link
Member

pcantrell commented May 2, 2017

To understand why your AuthSessionController() gets deallocated as soon as viewDidLoad() finishes, take a look at the memory management section of the Siesta user guide.

(And thanks @jordanpwood! 👏)

@rickvdl
Copy link
Author

rickvdl commented May 2, 2017

@pcantrell Thanks a lot for clarifying, will take a look at the documentation :)
BTW, I was running this on tvOS and so far it has been working perfectly.

@pcantrell
Copy link
Member

Good to hear that it’s working on tvOS! Thanks for letting me know. I’ll check that box off on #28. Are you using Carthage, Cocoapods, or neither to include Siesta?

@rickvdl
Copy link
Author

rickvdl commented May 2, 2017

@pcantrell Sure, I prefer Cocoapods, but since the spec wasn't updated yet I am just cloning the Siesta project and adding the .xcodeproj to my workspace just like the submodule method https://github.com/bustoutsolutions/siesta#git-submodule

Thanks a lot :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants