Search code examples
iosswiftxcodeloggingbase64

How can I get the full logs of a truncated base64 string from Xcode?


I have a extremely long base64 string that I generated on my IOS app, I print it like this print(longBase64), Xcode printed it but its truncated in logs, this is what it looks like in the end of the base64 string

k+WP7PFGn/LX/wDV/k96uW8SyNCbdPJs0j8v93j/AFUX/LHyM8Y9d35nIp1<…>

as you can see, <...> is not a base64 character, means Xcode truncated it.

This is how I generate that base64 string

extension UIImage {
    func toBase64() -> String {
        return jpegData(compressionQuality: 1)?.base64EncodedString() ?? ""
    }
}

I want to see the whole base64 string so that I can use it on other things such as postman

The question is, how can I get that whole base64 string?


Solution

  • Assuming you mean you want to be able to copy/paste the resulting Base64 string from Xcode to somewhere else...

    Using your extension and this code:

        guard let img = UIImage(named: "test") else { return }
        let b64: String = img.toBase64()
        // just to see the string length in debug console
        print(b64.count)
        print()
    

    Set a Breakpoint on the final print() line. When Xcode breaks, hover your mouse over the b64:

    enter image description here

    Click the "eye" icon at the right:

    enter image description here

    You can then click "Open With TextEdit" and you should have the entire string.

    Note: If you are generating an "extremely long base64 string" it may take Xcode a long time to show that -- as in several seconds -- when you may think it has "hung" or failed.

    I just tried it with print(b64.count) outputting 5001316 ... don't know if that's what you consider "extremely long."