Hi,
i am working a project where Im stuck on making a loop that uses either a chosenWords[String] or countHelp()
to cycle through a text and look for §§§ and then replace it with words from chosenwords array.
My app keeps freezing so I assume its the loop thats not working as intended. I have tried modifying the loop to count either chosenWords.count > 1 or getCount > 1 but none of them work as intended.
any help will be appreciated
import UIKit
import Foundation
class GameVC: UIViewController {
@IBOutlet weak var storyLabel: UILabel!
var getCount = Int()
override func viewDidLoad() {
super.viewDidLoad()
if let Path = Bundle.main.url(forResource: "fortelling2", withExtension: "rtf") {
do {
let attributedStringWithRtf: NSAttributedString = try NSAttributedString(url: Path, options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.rtf], documentAttributes: nil)
self.storyLabel.attributedText = attributedStringWithRtf
self.storyLabel.font = UIFont(name: "TimesNewRomanPS-BoldItalicMT",
size: 30.0)
} catch let error {
print("Got an error \(error)")
}
do {
let replace = storyLabel.text?.range(of: "§§§")
storyLabel.text?.replaceSubrange(replace!, with: chosenWords.removeFirst())
print(getCount)
while (storyLabel.text?.contains("§§§"))! {
}
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}