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

Swift: Update Docs/Example Repos with use of dynamic keyword #46

Open
natevecc opened this issue Jan 11, 2016 · 4 comments
Open

Swift: Update Docs/Example Repos with use of dynamic keyword #46

natevecc opened this issue Jan 11, 2016 · 4 comments

Comments

@natevecc
Copy link

Was running into an issue where objects weren't updating when saving to the server. I managed to figure out that Swift doesn't support KVO out of the box: docs(see section Key-Value Observing).

Long story short when using Swift with the cloudmine-ios library make sure to add dynamic in objects that extend CMObject:

class MyClass: CMObject {
  // the right way. changes to this property will be picked up by KVO, the object will be marked 
  // dirty and saved when calling #save() or #saveWithUser()
  dynamic var myProperty: String?

  // the wrong way. changes will not be picked up by KVO and the object will never be marked 
  // as dirty and saved correctly
  var anotherProperty: String?
}
@ethanmick
Copy link
Contributor

@pbenmoser4 @jraymondcm

@wjoshraymond
Copy link

@ethanmick thanks. We'll add a note to the documentation.

Do we know if extending CMObject is the only circumstance under which this would be necessary for our SDK?

@natevecc
Copy link
Author

Also found another work around that works well with enums which don't support the dynamic keyword.

enum State: String {
  case Phase1
  case Phase2
}

class MyClass: CMObject {
  var myProperty: State {
    didSet: {
      self.dirty = true
    }
  }
}

@ethanmick
Copy link
Contributor

@jraymondcm Yes, since CMObjects are the only class that uses the KVO to set themselves to dirty.

@natevecc Thanks for that example too. We should mention the CMObject dirty setting in our docs. I'll talk to @jraymondcm

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