It is a lot more complicated than you think it is. If you are not tech-savvy do not even attempt it
Note: All data will be available to you in spite of signing out of the Apple ID and signing in with your Apple ID.
The only possibility that I can see is,
- Back up your friend's data. Take a backup of the device on iTunes or iCloud.
- Erase the device. Follow this process --> What to do before you sell, give away, or trade-in your iPhone ...
- Once erased Sign in with your Apple ID and use the device as long as your friend allows it.
- Then Take the back of the device on iTunes or iCloud. Ensure the old backup is archived and stored separately
- Restore the device from the Old backup and hand over the device to your friend.
Now your data is stored separately on a separate backup. Use it whenever you have your device.
Note: If you are not careful, backups will be overwritten and your friend will lose all his data forever.
How to create Multiple Backups for the same device.
- On iTunes Click on Manage Backups
- Right Click on a Backup and Click Archive
- Click Backup Now.
- You will see a fresh backup will get created See the GIF below
- Restore from Backup dated (Archived)