Did you see the encryption question?
You have three choices. I selected none of the above and it worked.
Having said all that I am not really sure if this is your problem but thought it worth a mention.
Post
Replies
Boosts
Views
Activity
I have managed to submit my App. The process is not easy for the first time user but once achieved it does become clearer and I have managed to upload version updates.
Thank you so much!
At the moment I will use let test = firstCardWords.split(separator: ".").map { String($0) } in my App because I understand it.
Until I understand how the extension works I won’t use it.
I want to understand every aspect of my App so that despite receiving some help in building it and without that help (from you, Claude31) I can feel comfortable I built it.
Thanks again
Guy
I think I have gone down the wrong path because although this works I haven’t been able to expand on it with suffix etc. (after the first full-stop (second word)) and it doesn’t address after the second full-stop (third word).
Back to the drawing board!
let threewords = cards.firstCardWords
var firstWord = ""
if let index = threewords.firstIndex(of: ".") {
firstWord = String(threewords.prefix(upTo: index))
}
if firstWord == "" {
cards.firstCardWords = "FIRST.WORD.MISSING"
}
I have just had a brainwave, I just need to work out how to code it!
The logic is as follows…
if the character before the first full-stop is nil then create an error message eg FIRST.WORD.MISSING
If the character before the second full-stop (optional: and after the first full-stop) is nil then create an error message eg SECOND.WORD.MISSING
If the character after the second full-stop is nil create an error message eg THIRD.WORD.MISSING
I may need help with this!
To better explain what I am trying to achieve…
I am wanting to trap this error eg. (hello.world.) before the cards.firstCardLettersResult = str.split(separator: ch).map { String($0) } line of code so not to crash the app.
My other traps do this for the other types of input error by making a message that is the correct format (contain three elements) for cards.firstCardLettersResult = str.split(separator: ch).map { String($0) } to handle.
Without a crash my code then shows another View with all the inputs and if any of the inputs are incorrect (typos) or contain any of the trap messages my code has a button in this View to return to the form so inputs can be edited. This method is not perfect because it overwrites the original input in the form with the error message so the error message has to be deleted and word has to be typed again.
So sorry to say but I am still getting the error.
In this example what is return supposed to do?
I understand it is hard to diagnose something when you only get a snippet and for that I am sorry.
In my app the code doesn’t return to the Form to make any corrections until all the functions have run and the app crashes if for instance hello.world. or hello..today is entered instead of hello.world.today ie. two elements instead of three.
Maybe I need to look at trapping errors at the input stage. Having said that it is not something I know how to do at this stage (more to learn).
Thank you again.
Regards
Guy
print("cards.firstCardFirstWordClue", cards.firstCardFirstWordClue) // cards.firstCardFirstWordClue A “form” of greeting “ “””
let removeQuotesFirstCardFirstWordClue = cards.firstCardFirstWordClue.replacingOccurrences(of: "\"", with: "")
cards.firstCardFirstWordClue = removeQuotesFirstCardFirstWordClue
print("removeQuotesFirstCardFirstWordClue", cards.firstCardFirstWordClue) // removeQuotesFirstCardFirstWordClue A “form” of greeting “ “””
let removeCommasFirstCardSecondWordClue = cards.firstCardSecondWordClue.replacingOccurrences(of: ",", with: "")
cards.firstCardSecondWordClue = removeCommasFirstCardSecondWordClue
print("removeCommasFirstCardSecondWordClue", cards.firstCardSecondWordClue)
After much experimenting I have concluded that despite of: """, with: "") working okay on a string as per your example it doesn’t work on a string constructed from a TextField.
I will try working on this at the TextField input level.
Thanks again for your help.
EDIT: The above works okay WITHOUT errors.
Thanks again for your help.
let removeQuotesFirstCardFirstWordClue = cards.firstCardFirstWordClue.replacingOccurrences(of: "\"", with: "")
cards.firstCardFirstWordClue = removeQuotesFirstCardFirstWordClue
print(cards.firstCardFirstWordClue)
let removeCommasFirstCardSecondWordClue = cards.firstCardSecondWordClue.replacingOccurrences(of: ",", with: "")
cards.firstCardSecondWordClue = removeCommasFirstCardSecondWordClue
print(cards.firstCardSecondWordClue)
TextField Input (cards.firstCardFirstWordClue) was… A “form” of greeting
Print (cards.firstCardFirstWordClue) result was… A “form” of greeting (quotes still enclosing the word form)
TextField Input (cards.firstCardSecondWordClue) was… Another word for, this planet
Print (cards.firstCardSecondWordClue) result was… Another word for this planet (comma removed after the word for)
let removeQuotesFirstCardFirstWordClue = cards.firstCardFirstWordClue.replacingOccurrences(of: "\"", with: "")
cards.firstCardFirstWordClue = removeQuotesFirstCardFirstWordClue
let removeCommasFirstCardSecondWordClue = cards.firstCardSecondWordClue.replacingOccurrences(of: ",", with: "")
cards.firstCardSecondWordClue = removeCommasFirstCardSecondWordClue
“\”” doesn’t work on the TextField input cards.firstCardFirstWordClue but "," does.
Maybe I need to prevent commas and quotes from being typed into the TextField if that is possible?
Apologies but I thought I had replied to this but while reviewing my posts discovered I hadn’t!
@ObservedObject var cards = CardsOne() was exactly what was needed to make things work.
Many thanks for your time and sharing your expertise.
let str = cards.firstCardFirstWordClue
let ch = Character(".")
cards.firstCardLettersResult = str.split(separator: ch).map { String($0) }
cards.firstCardFirstLetters = cards.firstCardLettersResult[0] as! String
cards.firstCardSecondLetters = cards.firstCardLettersResult[1] as! String
cards.firstCardThirdLetters = cards.firstCardLettersResult[2] as! String
makeSecondCardWordLetters()
The above works okay with errors. As you suggested I inserted .map. I still needed the as! String after each split.
Not sure if .map { subString in return String(subString) } is an alternative form of as! String but it works without it.
Thanks again for your help!
Hello and thanks again for taking the time to help me.
Unfortunately it will be some time before I am in a position to get back to this but wanted to reply without too much delay.
Yes you are right about me being unfamiliar with .map so I will study it.
I think without actually fully understanding the problem I suspected the issue was some kind of incompatibility that you are talking about. I thought by declaring var firstCardLetters = [String] () (which I did do) was enough to make it compatible with cards.firstCardLetters etc.
Going from memory (mine) the Playgrounds Compiler suggested as! String which worked (immediate error gone) until I ran the app and then the app crashed with a what it called an “Unknown Error”.
Until next year...
Thanks again and a Happy New Year to you and Yours!