Subsequent to my initial question: Maybe I should have asked how do I convert the .cav file into an Array and list it all in the Struct? Not sure if I can have the .csv and Array in a non App file with no code?
Post
Replies
Boosts
Views
Activity
Thank you for your time 🙏🏻
This is what I have done in Playgrounds...
var printCards = "" // "No" required if "NOT" printing the cards
// Imported .csv file pasted in (var gameImport) below ////////////////
var gameImport =
"24,exam.dwindled.span,Short for examination,Reduced gradually in size,The total length of something from end to end,_ _ _ _ . _ w _ _ d _ _ d . _ _ _ n,16,///cracked.shadowed.private,The Vase was (?) when it toppled over,A part of the house is (?) by a tree every day,We like to talk in (?) when we want to keep it : secret,_ _ _ _ _ _ . _ _ _ _ _ _ . _ _ _ a t e,98,///spilling.dances.backbone,Causing or allowing liquid to flow over the edge : of its container,A series of steps that match the speed and : rhythm of a piece of music,The column of bones in the back which sustains : and gives firmness to the frame,_ p _ l l _ n . a _ c _ s._ a _ _ b _ n ,93,///inwards.habitat.buttered,Toward the centre or interior,Place where anything is commonly found,Covered or spread with butter, _ _ w _ r _ . a b t _ t._ u _ _ e _ e d, a e m x , d i l e n , p a s , d r a c c k e , d s a d o w e h , v r p i , g i s i , n d e , k o b c e , n s i a d , i h a , t b r t"
///////////////////////////////////////////////////////////////
var redTeam = " : RED TEAM :"
var blueTeam = " : BLUE TEAM :"
var cardDivider = "......................................................................"
var start = "Card Position : Start"
var positionOne = "Card Position : Position One"
var positionTwo = "Card Position : Position Two"
var positionThree = "Card Position : Position Three"
func printCardsPlease() {
if printCards == "No" {
start = ""
positionOne = ""
positionTwo = ""
positionThree = ""
redTeam = ""
blueTeam = ""
}
}
let lineSpace = "" // print(lineSpace) to insert a blank line
// Red Team Variables
var redFirstCardNumber = ""// Red 1st Clue Card
var redFirstCardWhat3Words = ""
var redFirstCardFirstWordClue = ""
var redFirstCardSecondWordClue = ""
var redFirstCardThirdWordClue = ""
var redFirstCardClueForm = ""
var redSecondCardNumber = ""// Red 2nd Clue Card
var redSecondCardWhat3Words = ""
var redSecondCardFirstWordClue = ""
var redSecondCardSecondWordClue = ""
var redSecondCardThirdWordClue = ""
var redSecondCardClueForm = ""
var redThirdCardNumber = ""// Red 3rd Clue Card
var redThirdCardWhat3Words = ""
var redThirdCardFirstWordClue = ""
var redThirdCardSecondWordClue = ""
var redThirdCardThirdWordClue = ""
var redThirdCardClueForm = ""
var redFourthCardNumber = ""// Red 4th Clue Card
var redFourthCardWhat3Words = ""
var redFourthCardFirstWordClue = ""
var redFourthCardSecondWorcClue = ""
var redFourthCardThirdWordClue = ""
var redFourthCardClueForm = ""
var redFirstCardFirstWordLetters = "" // Red 1st Card Letters
var redFirstCardSecondWordLetters = ""
var redFirstCardThirdWordLetters = ""
var redSecondCardFirstWordLetters = "" // Red 2nd Card Letters
var redSecondCardSecondWordLetters = ""
var redSecondCardThirdWordLetters = ""
var redThirdCardFirstWordLetters = "" // Red 3rd Card Letters
var redThirdCardSecondWordLetters = ""
var redThirdCardThirdWordLetters = ""
var redFourthCardFirstWordLetters = "" // Red 4th Card Letters
var redFourthCardSecondWordLetters = ""
var redFourthCardThirdWordLetters = ""
// etc
// Convert (gameImport) to an Array (gameImportArray)
let gameImportArray = gameImport.components(separatedBy: ",")
printCardsPlease()
// RED TEAM
// First Card
print (" : RED TEAM :")
print (start)
redFirstCardNumber = gameImportArray [0]
print ("Card Number : (redFirstCardNumber)")
redFirstCardWhat3Words = gameImportArray [1]
// print("What3Word : (redFirstCardWhat3Words)")
redFirstCardFirstWordClue = gameImportArray [2]
print("First Word Clue : (redFirstCardFirstWordClue)")
redFirstCardSecondWordClue = gameImportArray [3]
print("Second Word Clue : (redFirstCardSecondWordClue)")
redFirstCardThirdWordClue = gameImportArray [4]
print("Third Word Clue : (redFirstCardThirdWordClue)")
print (lineSpace)
redFirstCardClueForm = gameImportArray [5]
print("Answer : (redFirstCardClueForm)")
print (lineSpace)
redFirstCardFirstWordLetters = gameImportArray [24]
print("First Word Letters : (redFirstCardFirstWordLetters)")
redFirstCardSecondWordLetters = gameImportArray [25]
print("Second Word Letters : (redFirstCardSecondWordLetters)")
redFirstCardThirdWordLetters = gameImportArray [26]
print("Third Word Letters : (redFirstCardThirdWordLetters)")
print (cardDivider)
// etc
Sorry this might be better than the previous post...
var gameImport = "24,exam.dwindled.span,Short for examination,Reduced gradually in size,The total length of something from end to end,_ _ _ _ . _ w _ _ d _ _ d . _ _ _ n,16,///cracked.shadowed.private,The Vase was (?) when it toppled over,A part of the house is (?) by a tree every day,We like to talk in (?) when we want to keep it : secret,_ _ _ _ _ _ . _ _ _ _ _ _ . _ _ _ a t e,98,///spilling.dances.backbone,Causing or allowing liquid to flow over the edge : of its container,A series of steps that match the speed and : rhythm of a piece of music,The column of bones in the back which sustains : and gives firmness to the frame,_ p _ l l _ n . a _ c _ s._ a _ _ b _ n ,93,///inwards.habitat.buttered,Toward the centre or interior,Place where anything is commonly found,Covered or spread with butter, _ _ w _ r _ . a b t _ t._ u _ _ e _ e d, a e m x , d i l e n , p a s , d r a c c k e , d s a d o w e h , v r p i , g i s i , n d e , k o b c e , n s i a d , i h a , t b r t"
// Convert (gameImport) to an Array
let gameImportArray = gameImport.components(separatedBy: ",")
redFirstCardNumber = gameImportArray [0] print ("Card Number (redFirstCardNumber)")
redFirstCardWhat3Words = gameImportArray [1]
print("What3Word (redFirstCardWhat3Words)") redFirstCardFirstWordClue = gameImportArray [2]
print("First Word Clue : (redFirstCardFirstWordClue)") redFirstCardSecondWordClue = gameImportArray [3]
print("Second Word Clue : (redFirstCardSecondWordClue)") redFirstCardThirdWordClue = gameImportArray [4]
print("Third Word Clue : (redFirstCardThirdWordClue)")
print (lineSpace)
redFirstCardClueForm = gameImportArray [5]
print("Answer : (redFirstCardClueForm)") print (lineSpace) redFirstCardFirstWordLetters = gameImportArray [24]
print("First Word Letters : (redFirstCardFirstWordLetters)") redFirstCardSecondWordLetters = gameImportArray [25]
print("Second Word Letters : (redFirstCardSecondWordLetters)") redFirstCardThirdWordLetters = gameImportArray [26]
print("Third Word Letters : (redFirstCardThirdWordLetters)")
// etc.
I am so sorry about this!
I did come to realise there was a problem when I copied and pasted into Playgrounds to test what I had posted and saw the absolute mess!!
I am not aware of the use of the code format rtool.
I will have to find this tool and learn how to use it for the next time.
As for the error that might have been a copy and paste error on my part, sorry again.
I am so grateful for you taking the time to help with this and hope I don’t use up all your patience in the process. 🙏🏻
I would love to know….
With building an App rather than what I have managed to do in Playgrounds in mind…
Where to put my .csv file (some time down the track I envisage building it within the App and/ or being able to download it from Dropbox or similar
Where to put put the code to convert the .csv file to an array
The code needed to do this
Print on screen rather than the Console selected items from the array
I acknowledge this is asking a lot but these pointers will I hope be enough to get me out of the mud I find myself in!
Thanks in advance
That happened to me today and in my case it was obvious.
I was attempting to join a large number of String Variables together to create one.
I figured a solution was to break the process up into smaller chunks and then join the chunks together.
The above error disappeared, hopefully never to return!
Regards
Guy MacDonald
Firstly, thanks once again for taking your time to help me.
Unfortunately I won’t be able to show the code for a while (on the road with an iPhone 6).
The difference I see between your example and what I am trying to do is, I am trying to remove any accidental stray “ and/or a deliberate “any text“ that maybe put in a Form TextField.
I know I tested the stray “ and “””” and they didn’t work but I am pretty sure I didn’t try a normal input like your example.
When I am able I will check all three examples and report back.
Thanks again and a Happy New Year to you and yours.
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!
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!
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 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?
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)
EDIT: The above works okay WITHOUT errors.
Thanks again for your help.
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.
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)