Arrays and Sets - CaesarCipher.swift Project (Swift)

So, again, I was able to finish this project but the Option Challenge is hanging me up. The GitHub solution does not address the Optional Challenge so that is no help. ( I made an edit suggestion to the owner, I don’t know if they will do anything though.)

Anyways, my question is how to I make an Array (print) into a String? I did Google this question and looked around but I think the nature of the code for this particular project does not lend itself to the found solutions:

let stringArray = ["Bob", "Dan", "Bryan"]
let string = **stringArray.joined(separator: "")**

print(string) // prints: "BobDanBryan"

The code is below is the solution to the project:

var alphabet: [Character] = [“a”, “b”, “c”, “d”, “e”, “f”, “g”, “h”, “i”, “j”, “k”, “l”, “m”, “n”, “o”, “p”, “q”, “r”, “s”, “t”, “u”, “v”, “w”, “x”, “y”, “z”]
var secrectMessage = “HELLO”.lowercased()
var message = Array(secrectMessage)
for i in 0 …< message.count {
for j in 0 …< alphabet.count {
if message[i] == alphabet[j] {
message[i] = alphabet[(j+3)%26]
break
}
}
}

print(message)

How do I make the Array message print as a String?

FYI, not loving Arrays and Sets while learning coding/Swift. Did you all feel the same way?

So after getting help from @toastedpitabread for the Palindrome Project, I was able to find a way to make an Array into a String, albeit, I think this is unconventional and I would love to see if anyone has a ‘better’ solution. To be honest I do not know why using the .reversed function works while the .joined(separator: “,”) does not:

var alphabet: [Character] = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
var secrectMessage = "HELLO".lowercased()
var message = Array(secrectMessage)
for i in 0 ..< message.count {
  for j in 0 ..< alphabet.count {
    if message[i] == alphabet[j] {
      message[i] = alphabet[(j+3)%26]
      break
  }
  }
 }

var backwardmessageString = String(message.reversed())

var messageString = String(backwardmessageString.reversed())

print("This is Caesar's Cipher in String format: \(messageString)")

Would love some input.

This got me good too. In case you or anyone else lands here, my solution below!

Initially I found the joined() method, but because the message array data type was Character rather than String it threw errors for me…

But this works instead:

var stringMessage = String(message)
  • Create a new variable stringMessage and have it equal the output of String() with the message array passed as the argument.

Then you can just print(stringMessage and its all good!