Is there any way to upgrade a mid 2007 iMac to macOS Sierra?
OS X El Capitan 10.11.6 is the last supported release of macOS for your model of iMac. The latest release of Xcode that can be installed on your machine is Xcode 8.2.1 with macOS 10.12.2 SDK and iOS 10.2 SDK.

It is not officially possible to install macOS Sierra or use Xcode 9 (or later) on your iMac.