`objc` command line tool no longer works / update docs to use SPM instead?


It appears the objc command line tool no longer works— when attempting to follow the instructions to start down the Obj-C track, running objc -x HelloWorld spits out the Ruby error:

/usr/local/lib/ruby/gems/3.2.0/gems/xcoder-0.1.18/lib/xcode/project.rb:219:in `save': undefined method `exists?' for File:Class (NoMethodError)

      Dir.mkdir(path) unless File.exists?(path)
Did you mean?  exist?
	from /usr/local/lib/ruby/gems/3.2.0/gems/xcoder-0.1.18/lib/xcode/project.rb:206:in `save!'
	from /usr/local/lib/ruby/gems/3.2.0/gems/objc-0.0.4/lib/objc/xcode_project.rb:38:in `add'
	from /usr/local/lib/ruby/gems/3.2.0/gems/objc-0.0.4/lib/objc.rb:19:in `with'
	from /usr/local/lib/ruby/gems/3.2.0/gems/objc-0.0.4/bin/objc:45:in `<top (required)>'
	from /usr/local/opt/ruby/bin/objc:25:in `load'
	from /usr/local/opt/ruby/bin/objc:25:in `<main>'

While this may have something to do with my OS version (macOS 12.6.2) or installed Ruby version (3.2.0) or something else, it should be noted that the objc gem seems abandoned (last update in 2017) and the xcoder gem it depends on (in which is seems the error is getting thrown from) is outright “No Longer Maintained”.

That said, I believe we have a better solution now: Swift Package Manager. SPM can specify Obj-C targets and run tests from the CLI. For example, I was able to get the intro hello-world project running by just adding this Package.swift to the folder:

// swift-tools-version: 5.7
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
	name: "hello-world",
	products: [
			name: "hello-world",
			targets: ["hello-world"]
	targets: [
			name: "hello-world",
			dependencies: [],
			path: "",
			exclude: [ "HelloWorldTest.m" ],
			publicHeadersPath: ""
			name: "hello-worldTests",
			dependencies: ["hello-world"],
			path: "",
			sources: [ "HelloWorldTest.m" ]

Package.swift also has the benefit of acting as a Xcode-friendly project file— so the user can open and edit in Xcode without having to go through all the steps to create & configure a .xcodeproj.

What are your thoughts on removing all the objc gem stuff from the docs/instructions and replacing them with Package.swift and swift test instructions?

By and large, this would involve updating the following in https://github.com/exercism/objective-c, which I’d be happy to take a stab at:

  • docs/TESTS.md
  • exercises/shared/.docs/tests.md
  • README.md

Now that I’m thinking about it, it would probably be simplest to just include an appropriate Package.swift in each generated exercise’s files (which would be downloaded with everything else via exercism download --exercise=… --track=objective-c).

Still the docs would need to be updated, but there wouldn’t need to be any instructions about how to set up the Package.swift’s path:, sources:, exclude:, etc. values.