I try to achieve it in the following way:
cannot use mutating member on immutable value
Error clearly state that
peripheral.services? is not immutable content. so you cannot edit the contents in it.
You need to use
removeAllServices() - Removes all published services
remove(CBMutableService) - remove the specified service