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

Not working in Swift inheriting from NSObject #18

Open
mergesort opened this issue Mar 26, 2015 · 2 comments
Open

Not working in Swift inheriting from NSObject #18

mergesort opened this issue Mar 26, 2015 · 2 comments

Comments

@mergesort
Copy link

I have a very simple model, it's a few booleans, Strings, and so on.

import AutoCoding

public class Bitlink : NSObject {
    var longURLString = ""
    var shortURLString = ""

    var archived = false
    var title: String? = ""

    ... and so on
}

I'm using YapDatabase, which is leveraging NSCoder for persistence. When I save and read from the database, what I saved is correct going in and reading back out. Then when I restart the app, and query, it comes back with the default values.

I tried manually using initWithCoder: and encodeWithCoder:, and that resolved the issues, so I'm fairly certain this has something to do with AutoCoding.

Any thoughts?

@nicklockwood
Copy link
Owner

I'm going to need a bit more information. Can you provide a sample app?

@mergesort
Copy link
Author

Here you go.
http://www.filedropper.com/autocodingtest

In ViewController.swift, I uncommented out the code in viewDidLoad to save a Dog.
Then I close the app, and comment it out, so no dogs are saved. Then I run the app, enumerating through all the saved Dogs, and it will show 1 Dog, with the default properties that Dog's are initialized with.

I then delete the app, so I don't get an encoding conflict, and in Dog.swift I switch to manual encoding.
I repeat the process, save a Dog by uncommenting the code, close the app, comment out the code that saves dogs, enumerate through the dogs, and this time it pulls up the correct Dog object, not one initialized with the default properties.

Please let me know if that's unclear, and if I can help in any way.

Thanks!

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

2 participants