class Site
require 'httparty'
include HTTParty
format :json
attr_accessor :siteArray
attr_accessor :siteArrayController
PROPERTIES = [:id, :code, :name, :server, :location, :saved]
PROPERTIES.each { |prop| attr_accessor prop }
def self.getAllSites
siteArray = NSMutableArray.new
get('/sites').parsed_response.each do |site|
siteArrayController.addObject(self.new(site))
end
end
def initialize(attributes = {})
attributes.each { |key, value|
self.send((key.to_s + "=").to_s, value)
}
if @id.nil? then
@saved = false
else
@saved = true
end
end
end
Basically, I would like to call from the main App Delegate something like Site.getAllSites, which would talk to the Web Server, load and parse the json and init the actual objects, adding them to the siteArray, which would in turn populate the UI via Bindings.
So I guess my questions are:
1) Am I crazy trying to do it like this?
2) How do I define the siteArray and siteArrayController so that they are Class variables (rather than object variables) and can be bound to the UI?
Thanks in advance for anyone who can point me in the right direction.
Jeff