当我尝试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>'
有什么想法?
这对我有用:
targets_to_remove = project.targets.select { |target| target.name == new_target_name }
targets_to_remove.each { |target| target.remove_from_project }
我相信只能致电remove_from_project
即可将其删除,并且要正确清理所有参考。