Ruby gem Xcodeproj在项目保存时抛出异常

时间:2017-05-03 06:23:48

标签: ruby xcode xcode-project xcodeproj

当我在尝试使用Xcodeproj时,我发现错误可能来自滥用API。你能指出我做错了吗?

require 'xcodeproj'

project = Xcodeproj::Project.new("test.xcodeproj")
new_target_name = 'test'
project.new_target(:framework, new_target_name, :ios)
project.save

target_to_remove = project.targets.select {|t| t.name == new_target_name}.first
project.targets.delete(target_to_remove)
project.save

target_to_remove.remove_from_project

此代码段给出了以下错误消息。

/usr/local/lib/ruby/gems/2.4.0/gems/xcodeproj-1.4.4/lib/xcodeproj/project/object/configuration_list.rb:101:in `ascii_plist_annotation': undefined method `isa' for nil:NilClass (NoMethodError)
    from /usr/local/lib/ruby/gems/2.4.0/gems/xcodeproj-1.4.4/lib/xcodeproj/project.rb:286:in `block in to_ascii_plist'
    from /usr/local/lib/ruby/gems/2.4.0/gems/xcodeproj-1.4.4/lib/xcodeproj/project.rb:285:in `each'
    from /usr/local/lib/ruby/gems/2.4.0/gems/xcodeproj-1.4.4/lib/xcodeproj/project.rb:285:in `to_ascii_plist'
    from /usr/local/lib/ruby/gems/2.4.0/gems/xcodeproj-1.4.4/lib/xcodeproj/project.rb:353:in `block in save'
    from /usr/local/lib/ruby/gems/2.4.0/gems/xcodeproj-1.4.4/lib/xcodeproj/project.rb:353:in `open'
    from /usr/local/lib/ruby/gems/2.4.0/gems/xcodeproj-1.4.4/lib/xcodeproj/project.rb:353:in `save'
    from /Users/testuser/Desktop/XcodeprojTest/test.rb:10:in `<top (required)>'
    from -e:1:in `load'
    from -e:1:in `<main>'

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

这对我有用:

targets_to_remove = project.targets.select { |target| target.name == new_target_name }
targets_to_remove.each { |target| target.remove_from_project }

我认为只需调用remove_from_project就可以删除它,并且可以正确清理所有引用。