Open the mac terminal and enter the WebDriverAgent directory:
Enter: cd /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-xcuitest-driver/WebDriverAgent
Then enter the command: xcodebuild -project WebDriverAgent.xcodeproj -scheme WebDriverAgentRunner -destination'id=36d1639971532c51145a64dd7f4a6e793a4b7d1b' test
Where id is the udid (UUID) of the tested iOS device
If it still doesn't work, then restart the computer and try again.