It's in the doc:
So just specify no option at all when encoding to avoid adding any line ending character, and specify ignoreUnknownCharacters
when decoding to ignore line ending characters.
Step 1: Hex String to Data is a separate StackOverflow question (but you should avoid Hex String to begin with, it's a big waste of bytes!)
Step 2: Data to base64 Data or base64 String (choose one)
// By default, no line endings are inserted: https://developer.apple.com/reference/foundation/nsdata/1412739-base64encodeddata
let encodedAsData = data.base64EncodedData()
// By default, no line endings are inserted: https://developer.apple.com/reference/foundation/nsdata/1413546-base64encodedstring
let encodedAsString = data.base64EncodedString()