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: [
.library(
name: "hello-world",
targets: ["hello-world"]
),
],
targets: [
.target(
name: "hello-world",
dependencies: [],
path: "",
exclude: [ "HelloWorldTest.m" ],
publicHeadersPath: ""
),
.testTarget(
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?