我需要在RubyMotion中下载和解压缩文件.我尝试寻找示例,但找不到任何此过程.
我有一个变量(@file),它是请求中的所有数据.我需要将该数据写入文件然后解压缩,保留未压缩的数据并删除tmp压缩文件.
这是我到目前为止:
class LoadResourcesViewController < UIViewController
def viewDidAppear(animated)
@loading_bar = retrieve_subview_with_tag(self, 1)
req=NSURLRequest.requestWithURL(NSURL.URLWithString("#{someurl}"))
@connection = NSURLConnection.alloc.initWithRequest req, delegate: self, startImmediately: true
end
def connection(connection, didFailWithError:error)
p error
end
def connection(connection, didReceiveResponse:response)
@file = NSMutableData.data
@response = response
@download_size = response.expectedContentLength
end
def connection(connection, didReceiveData:data)
@file.appendData data
@loading_bar.setProgress(@file.length.to_f/@download_size.to_f)
end
def connectionDidFinishLoading(connection)
#create tmp file
#uncompress .tar, .tar.gz or .zip
#presist uncompresssed files and delete original tmp file
puts @file.inspect
@connection.release
solutionStoryboard = UIStoryboard.storyboardWithName("Master", bundle:nil)
myVC = solutionStoryboard.instantiateViewControllerWithIdentifier("Main3")
self.presentModalViewController(myVC, animated:true)
end …Run Code Online (Sandbox Code Playgroud) 我需要能够获取液体中的对象列表,并以特定格式在页面上显示它们.
如果我有一个对象数组(页面),我需要能够以下列方式打印它们:
列表类别名称(page.category.name)
列出每个子类别名称以及每个子类别名称下的页面列表(page.subcategory.name和page.title)
通常在红宝石中我会简单地对页面进行分组,但我不能用液体进行分组.我尝试的另一件事是捕获页面的类别和子类别的唯一列表,但我找不到从阵列中获取唯一项目列表的方法.任何建议的帮助都会很棒.