title: App crashes when trying to copy text on iPhone
body: <p>I program an &quot;encryption app&quot; that encrypts texts in a simple way. This is the code:</p>
  <pre><code>let smallLetters: String = &quot;abcdefghijklmnopqrstuvwxyz&quot;
  let bigLetters: String = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZ&quot;
  
  let input: String = encryptTextField.text!
      
      encryptTextField.text! = &quot;&quot;
      
      var value: String = &quot;&quot;
      
      for c in input {
          let otherChars: String = &quot; !§$%&amp;/()=?´`#+'*-_.:,;&lt;&gt;^°@€{}≠¿|][¢¶“¡≤≈ç√∫~µ@€öäüÜÖÄ&quot;
          
          for i in otherChars {
              if c == i {
                  value += String(i)
                  print(&quot;i&quot;)
              }
          }
          
          var dCount: Int = 0
          var eCount: Int = 0
          
          var dFound: Bool = false
          var eFound: Bool = false
          
          for d in smallLetters {
              if !dFound {
                  if c == d {
                      dFound.toggle()
                      
                      let y: Int = smallCount - dCount
                      var z: Int = 1
                      
                      for i in smallLetters {
                          if y == z {
                              print(&quot;[\(c) -&gt; \(i)]&quot;)
                              value += String(i)
                          }
                          
                          z += 1
                      }
                  } else {
                      dCount += 1
                  }
              }
          }
          for e in bigLetters {
              if !eFound {
                  
                  if c == e {
                      eFound.toggle()
                      
                      let y: Int = bigCount - eCount
                      var z: Int = 1
                      
                      for i in bigLetters {
                          if y == z {
                              print(&quot;[\(c) -&gt; \(i)]&quot;)
                              
                              value += String(i)
                          }
                          
                          z += 1
                      }
                  } else {
                      eCount += 1
                  }
              }
          }
      }
      
      let maximumChars: Int = 15
      
      var string: String = &quot;&quot;
      var i: Int = 1
      
      var b: Bool = false
      
      for c in value {
          if !b {
              if i &lt;= maximumChars {
                  string += String(c)
              } else {
                  string += &quot;...&quot;
                  b = true
              }
              
              i += 1
          }
      }
      
      let alert: UIAlertController = UIAlertController(title: &quot;Encoded!&quot;, message: &quot;Your input is now encrypted / decrypted.&quot;, preferredStyle: UIAlertController.Style.alert)
      let cancel: UIAlertAction = UIAlertAction(title: &quot;OK&quot;, style: UIAlertAction.Style.cancel, handler: { (alert: UIAlertAction!) in
          self.encryptTextField.text! = value
          print(&quot;OK&quot;)
          
          self.encryptTextField.placeholder = &quot;Enter a text to encrypt...&quot;
      })
      let copy: UIAlertAction = UIAlertAction(title: &quot;Copy!&quot;, style: UIAlertAction.Style.default, handler: { (alert: UIAlertAction!) in
          print(&quot;Copy!&quot;)
          
          let pasteboard: UIPasteboard = UIPasteboard.general
          pasteboard.string! = value
          
          self.encryptTextField.placeholder = &quot;'&quot; + string + &quot;' was copied!&quot;
      })
      
      alert.addAction(cancel)
      alert.addAction(copy)
      
      present(alert, animated: true, completion: nil)
  </code></pre>
  <p>So that I can quickly insert the encrypted text into another app (e.g. WhatsApp) I use this code (simplified):</p>
  <pre><code>let pasteboard: UIPasteboard = UIPasteboard.general
  pasteboard.string! = &quot;Hello World!&quot;
  </code></pre>
  <p>The code works in the simulator: The encrypted text is copied and I can paste it with a double click (see picture).</p>
  <p><a href="https://i.stack.imgur.com/oZamT.png" rel="nofollow noreferrer">Paste encrypted text with a double click</a></p>
  <p>But when I run the app on my mobile phone (iPhone 8), the app crashes at this point!</p>
  <p>Does anyone know a solution or at least know why?</p>