Object 鲁比莫;RestKit
有没有人让Rubymotion使用RestKit的RKObjectManager并成功地从服务器加载了一些对象?我有很多麻烦。我让RestKit的客户工作得很好。我可以得到和张贴成功,这是伟大的。但我无法使用RKObjectManager加载资源。我的耙子看起来像这样:Object 鲁比莫;RestKit,object,loading,restkit,rubymotion,Object,Loading,Restkit,Rubymotion,有没有人让Rubymotion使用RestKit的RKObjectManager并成功地从服务器加载了一些对象?我有很多麻烦。我让RestKit的客户工作得很好。我可以得到和张贴成功,这是伟大的。但我无法使用RKObjectManager加载资源。我的耙子看起来像这样: $:.unshift("/Library/RubyMotion/lib") require 'motion/project' Motion::Project::App.setup do |app| # Use `rake
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'RestKitTest'
app.frameworks += %w(CoreData CFNetwork Security MobileCoreServices SystemConfiguration QuartzCore)
app.vendor_project('vendor/RestKit', :xcode, :target => 'RestKit', :headers_dir => '../Headers/RestKit/')
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
@window.rootViewController = TestViewController.alloc.init
@window.rootViewController.wantsFullScreenLayout = true
@window.makeKeyAndVisible
true
end
end
class TestViewController < UIViewController
def init
super
puts "checkpoint 1"
manager = RKObjectManager.managerWithBaseURLString "http://mlpong.herokuapp.com"
puts "checkpoint 2"
mapping = RKObjectMapping.mappingForClass League.class
puts "checkpoint 3"
# mapping.mapAttributes("id", "name", "url", nil)
mapping.mapKeyPath("id", toAttribute:"id")
mapping.mapKeyPath("name", toAttribute:"name")
mapping.mapKeyPath("url", toAttribute:"url")
puts "checkpoint 4"
manager.mappingProvider.setObjectMapping(mapping, forKeyPath:"")
puts "checkpoint 5"
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", delegate:self)
puts "checkpoint 6"
self
end
def objectLoader(loader, didFailWithError:error)
puts "failed with error: #{error.domain}"
end
def objectLoader(loader, didLoadObjects:objects)
puts "success!"
end
end
我的应用程序代理如下所示:
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'RestKitTest'
app.frameworks += %w(CoreData CFNetwork Security MobileCoreServices SystemConfiguration QuartzCore)
app.vendor_project('vendor/RestKit', :xcode, :target => 'RestKit', :headers_dir => '../Headers/RestKit/')
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
@window.rootViewController = TestViewController.alloc.init
@window.rootViewController.wantsFullScreenLayout = true
@window.makeKeyAndVisible
true
end
end
class TestViewController < UIViewController
def init
super
puts "checkpoint 1"
manager = RKObjectManager.managerWithBaseURLString "http://mlpong.herokuapp.com"
puts "checkpoint 2"
mapping = RKObjectMapping.mappingForClass League.class
puts "checkpoint 3"
# mapping.mapAttributes("id", "name", "url", nil)
mapping.mapKeyPath("id", toAttribute:"id")
mapping.mapKeyPath("name", toAttribute:"name")
mapping.mapKeyPath("url", toAttribute:"url")
puts "checkpoint 4"
manager.mappingProvider.setObjectMapping(mapping, forKeyPath:"")
puts "checkpoint 5"
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", delegate:self)
puts "checkpoint 6"
self
end
def objectLoader(loader, didFailWithError:error)
puts "failed with error: #{error.domain}"
end
def objectLoader(loader, didLoadObjects:objects)
puts "success!"
end
end
我的存根TestViewController如下所示:
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'RestKitTest'
app.frameworks += %w(CoreData CFNetwork Security MobileCoreServices SystemConfiguration QuartzCore)
app.vendor_project('vendor/RestKit', :xcode, :target => 'RestKit', :headers_dir => '../Headers/RestKit/')
end
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame UIScreen.mainScreen.bounds
@window.rootViewController = TestViewController.alloc.init
@window.rootViewController.wantsFullScreenLayout = true
@window.makeKeyAndVisible
true
end
end
class TestViewController < UIViewController
def init
super
puts "checkpoint 1"
manager = RKObjectManager.managerWithBaseURLString "http://mlpong.herokuapp.com"
puts "checkpoint 2"
mapping = RKObjectMapping.mappingForClass League.class
puts "checkpoint 3"
# mapping.mapAttributes("id", "name", "url", nil)
mapping.mapKeyPath("id", toAttribute:"id")
mapping.mapKeyPath("name", toAttribute:"name")
mapping.mapKeyPath("url", toAttribute:"url")
puts "checkpoint 4"
manager.mappingProvider.setObjectMapping(mapping, forKeyPath:"")
puts "checkpoint 5"
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", delegate:self)
puts "checkpoint 6"
self
end
def objectLoader(loader, didFailWithError:error)
puts "failed with error: #{error.domain}"
end
def objectLoader(loader, didLoadObjects:objects)
puts "success!"
end
end
如果我注释掉mapAttributes行,并使用另一个(更长)版本的对象映射(检查点4之前未注释的3行),我将通过所有检查点,但在我rake--trace时收到此消息:
** Invoke default (first_time)
** Invoke simulator (first_time)
** Invoke build:simulator (first_time)
** Execute build:simulator
** Execute simulator
/usr/bin/defaults write com.apple.iphonesimulator "SimulateDevice" "'iPhone'"
DYLD_FRAMEWORK_PATH="/Applications/Xcode.app/Contents/Developer/../Frameworks":"/Applications/Xcode.app/Contents/Developer/../OtherFrameworks" /Library/RubyMotion/bin/sim 2 1 5.1 "/Applications/Xcode.app/Contents/Developer" "./build/iPhoneSimulator-5.1-Development/RestKitTest.app"
checkpoint 1
checkpoint 2
checkpoint 3
checkpoint 4
checkpoint 5
checkpoint 6
(main)> terminate called without an active exception** Execute default
我整天都在犯这些错误。如果有人有任何想法,请告诉我。非常感谢你的帮助。谢谢
Pachun您调用了一些不存在的方法
manager.mappingProvider.setObjectMapping(mapping, forKeyPath:"")
puts "checkpoint 5"
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", delegate:self)
puts "checkpoint 6"
应该是
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", mapping:mapping, delegate:self)
puts "checkpoint 5"
请参阅我在上面找到答案的类似问题:您调用了一些不存在的方法
manager.mappingProvider.setObjectMapping(mapping, forKeyPath:"")
puts "checkpoint 5"
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", delegate:self)
puts "checkpoint 6"
应该是
manager.loadObjectsAtResourcePath("/leagues.json?auth_token=my_auth_token", mapping:mapping, delegate:self)
puts "checkpoint 5"
请参阅我在上找到答案的类似问题:您的第一个问题是
mapAttributes
应该这样使用:mapping.mapAttributes([“id”、“name”、“url”)
。然而,我仍然不知道如何克服第二个错误。(这段代码在标准的Xcode/Objective-C项目中似乎工作得很好,但在rubymotion项目中却不行)您的第一个问题是mapAttributes
应该这样使用:mapping.mapAttributes([“id”、“name”、“url”)
。然而,我仍然不知道如何克服第二个错误。(这段代码在标准的Xcode/Objective-C项目中似乎工作得很好,但在RubyMoon项目中却不行)