When you copy/paste code from Xcode into Keynote it includes the highlighted styling of the text.

To get rid of that background select the text then click

Text > Style > Gear drop down (grouped with Font) > Text Background > Color none.

If you do that your text will now look like this.