Skip to content

targets.delete corrupts the project file? #462

Closed
@JanC

Description

Hi,
I've updated to xcodeproj 1.4.2 and I have troubled removing a target from a project. This same code works fine in version 1.3.0

@d360_kit_project_path = "MyKit.xcodeproj"

@xcp_project = Xcodeproj::Project.open(@d360_kit_project_path)
target_name = "MyKitTests"
@xcp_target = @xcp_project.targets.select { |target| target.name == target_name }.first

if @xcp_target
    puts "Removing target #{@xcp_target.name}"
    @xcp_project.targets.delete(@xcp_target)
end
@xcp_project.save(@xcp_project.path)

The result is

Removing target MyKitTests
/Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project/object/configuration_list.rb:101:in `ascii_plist_annotation': undefined method `isa' for nil:NilClass (NoMethodError)
Did you mean?  is_a?
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:286:in `block in to_ascii_plist'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:285:in `each'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:285:in `to_ascii_plist'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:353:in `block in save'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:353:in `open'
	from /Users/jan/.rvm/gems/ruby-2.3.0/gems/xcodeproj-1.4.2/lib/xcodeproj/project.rb:353:in `save'
	from remove_target.rb:14:in `<main>'

In attachment is a sample project to reproduce it

bundle exec ruby remove_target.rb 

Any ideas?

cheers
MyKit.zip

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions