swift: fix credentials #2

also write accounts in sorted order

Change-Id: I7f0b9cb5fc6cef641152a61442ff330e0c79066c