Search code examples
iosuitableviewrubymotion

BubbleWrap RSSParser to TableView


I am using RubyMotion, BubbleWrap::RSSParser, and ProMotion. My goal is to read an RSS feed with BubbleWrap::RSSParser to popular a TableView.

I have the following setup:

def on_init
  @data = []
end

def table_data
  [{
    title: "",
    cells: @data
  }]
end

def on_load
  @data = []
  feed = BW::RSSParser.new("URL")
  feed.parse do |item|
    @data << item.to_hash
  end
  @data
end

For some reason, the @data array is nil, but when I do p item.to_hash the hash prints out correctly to the console.

Does anyone know why this isn't working?


Solution

  • I think it might be because the RSSParser is an asynchronous request. You probably return @data empty, before the request is completed.

    EDIT: From BubbleWrap docs, you can set a delegate for the parser. Something like

    feed_parser = BW::RSSParser.new("http://feeds.feedburner.com/sdrbpodcast")
    feed_parser.delegate = self 
    feed_parser.parse do |item|
      @data << item.to_hash
    end
    
    def when_parser_is_done
      table_data
    end