Is there a way to code sign ad-hoc iOS apps for longer than 7 days in Xcode? I know, on Xcode, you can create an iPhone app, and test it on your own phone via USB cable, but this expires after 7 days. 

I want to create a swift app just for my iPhone and not have it expire so quickly. What are my options?
Free developer membership apps require resigning to be functional after 7 days.

Paid developer membership apps expire after 1 year. You can also submit an app for testing to TestFlight which signs apps for 90 days. You can purchase a developer membership at https://developer.apple.com

If your device is jailbroken, you can resign your apps with a free developer account for as long as you wish, on device with Extender: Reloaded, available from the repo http://repo.incendo.ws.