Operating system
The Early 2009 iMacs ship with OS X 10.5.6 Leopard, and they are compatible with OS X 10.11 El Capitan. Although it is not officially supported, the Early 2009 iMac can run macOS Sierra using Colin Mistr's Sierra Patch Tool.
https://lowendmac.com/2009/imac-early-2009/
Xcode
https://developer.apple.com/download/more/ to download a version of Xcode you want. Specifically, get 9.2. This is the recent version that works with mac OS Sierra.
https://stackoverflow.com/a/51405911/1549818
Xcode 9.2 includes Swift 4 and SDKs for iOS 11.2
https://developer.apple.com/xcode/whats-new/
So you will be limited to compiling up to iOS 11.2 with Xcode 9.2, providing you use the unofficial patch to install Sierra.
Activation lock
Upgrade your Mac to macOS Catalina.
https://support.apple.com/kb/HT208987
This Mac can’t run Catalina as discussed above so there cannot be any activation lock active.