2 Replies
      Latest reply on Jan 7, 2016 4:05 AM by sleipn1r
      sleipn1r Level 1 Level 1 (0 points)

        Hi

         

        i am new in swift ...

        now i want so save this string in my string var.

        How can i do it.

         

         

        let myKey = "

        -----BEGIN PGP PUBLIC KEY BLOCK-----

        Version: GnuPG v2

         

         

        mQINBFZ5LnoBEADEYFRYJ1Xq/pOXFtKERULHI3B3vpYGTw/CMY917YBkjini/M8D

        CJYTw2Ak1yqGJMHnTnQNQuHXF0e5HDDwFP6zmsvq2r8TvDZQlt8dz2vbmKpVjmjY

        DU6Ab00FhwlVD7ikXyJbsORs8ywwtXDw/g/Hcd7yePaDHbQ+WIXKBPRwx09y6WI8

        4zFdzBNuZfgDzvNJ+uan1YastN4J4QsxoMN4ZaZqwRGdZdsNMq151e4R+vXbgoDT

        Cokt5qzfKtYKnYb5FuqA1vqrYJBBRFCVq0+ghBYEJZRucAh6NoMtjknlbbOdp0AV

        IWJh1nDkdQ4w8w2OM0c91y4WiI/eH3Tsvj5wyTgdjpIs+Rig/lBvh8R2wlPB8YUV

        b8pXeQX4FhqU4YGB/YO6FbFSmvq06AuC0Mm+KMJZP+yhaBoZ6xizWgo3M3Qi9drJ

        qRVgqrBnir3sh924/E25XXZPDFn8rQoxmU10/QYfeIQ3j0l7XVCLnhIb4OBNrzA0

        ID+bi3FDsxlCO9FmdKE3V38OdZWrO9erUPHaijZEGsxFUn2JJOvSX2YZnwxrdQZ5

        fy52vr6o1ocuKuOguqxTNTdK1X70ba4PR6z7q7ne4eVeP8RYMypXJW6okQARAQAB

        tDdoZWlkZW1hbm43N0Bnb29nbGVtYWlsLmNvbSA8aGVpZGVtYW5uNzdAZ29vZ2xl

        bWFpbC5jb20+iQI4SBMBAgAiBQJWeS56AhsvBgsJCAcDAgYVCAIJCgsEFgIDAQIe

        AQIXgAAKCRB2opL/6HlO2GCbD/9ir2ihl6YRZdbcEYDqyp93Hwii+RqHuvffyQB9

        mMhLMzqm77NiDRPWJTSjP0Re0SZ/jOIGm7Gz7fHFpyv5oLSy58GfVT3iwQhvxOOb

        8Vg31yQH/Py9nblazcWYAkW9BmJcGcvyFkoWMc/XiNV3aVqn1n2SMqqEoVsepXHK

        XTkgWhUgkKytSpPhtvCEIG4JgXX5IJ7/wnraPL3LAXX8B7TJP7uAldJAjmgXiCdT

        OXZhb+n+Qw6SxuLUdOD2GnxF+7JEZA1bXG+DUEarvxsAPl4GG0CoiyHogctplrPh

        rxR3++XFEU9M7uTFFz4ff6SgBCnstvH4FDoRtrmIkH+AsAy/gkvzHfoUziF2FENm

        GCtMG1mGTFUZYXSFiCdZrh7HoDmV2d4XgYXJMMdjST9G2b39pk93BIj7SGQUTbVL

        ragQ8JvcMPKxoUwkRWl/NW+s8uxeoGx3jCRUdHGOcltcB3ltTErvtn1SrKyAwrWz

        4Xdn1MGxFGWQoNCHg+M9v3f7dL2IrjH36w7f6Bwt2Q/VIzs+S4pRWpzKLdLQ1MKT

        9NTE9/bKYPar7ZJGWvrB/jDcAPvgwIMuhGZTvS/d9F2lQhzeAjpNukq28ef0rgOO

        50ZveA7mXjmt+/tYwFT7RXdwTEoSpWMotnbhffaIhAazgVXggSTvuNsfX5FN6Aai

        W6uU3w==

        =D+lB

        -----END PGP PUBLIC KEY BLOCK-----

        "

         

         

        thanks

        • Re: String var in swift
          phalverson Level 1 Level 1 (0 points)

          i want so save this string in my string var.

          How can i do it?

           

          Swift doesn't provide a "continuation" character to break long strings across multiple lines without adding newlines, so you have to do it through literal string concatenation.

          let myKey =
             "-----BEGIN PGP PUBLIC KEY BLOCK-----\n"+
             "Version: GnuPG v2\n\n"+
             "/pOXFtKERULHI3B3vpYGTw/CMY917YBkjini/M8D\n"+
            ...
             "=D+IB\n"+
              "-----END PGP PUBLIC KEY BLOCK-----"

           

          Note that the leading and trailing newlines are not necessary.

           

          That said, I would not recommend hardcoding a public key in your code as a String constant. It's far more maintainable to put large blocks of text like this in separate resource files.

           

          peter