This repository has been archived by the owner on Mar 23, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example of using dates in the demos
- Loading branch information
Showing
5 changed files
with
22 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,22 @@ | ||
class Post < NSRailsModel | ||
attr_writer :author, :content, :responses | ||
attr_writer :author, :content, :responses, :createdAt | ||
|
||
# Right now there's a bug in RubyMotion that requires you to define getter methods manually | ||
# Soon you'll be able just do "attr_accessor" above instead of this | ||
def author; @author; end | ||
def content; @content; end | ||
def responses; @responses; end | ||
def responses; @responses; end | ||
def createdAt; @createdAt; end | ||
|
||
|
||
# Define the NSRailsSync macro as usual, only as a class method returning a string | ||
# Remember that * is not supported in the Ruby environment, and has_many relationships have to be indicated with '-m' | ||
# Remember that in the Ruby environment, * is not supported, has_many relationships have to be indicated with '-m', and dates must declared with NSDate | ||
def self.NSRailsSync | ||
'author, content, responses:Response -m' | ||
'author, content, createdAt:NSDate, responses:Response -m' | ||
end | ||
|
||
# For responses, since it's an array, the ":" is required to define an association with another class. | ||
# For responses, since it's an array, -m is required (has-many). The ":" is required to define an association with another class. | ||
# In this case, the class of objects we want to fill our responses array with is Response (must be an NSRailsModel subclass) | ||
|
||
# For createdAt, :NSDate makes it so NSRails will automatically convert to a formatted date object (string) when sending to Rails, and return a Time object when retrieving. Handy. | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters