Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Chinwendu Opara
Courses Plus Student 1,734 PointsAlso I am creating a fact app that I want to generate strings in my array in the exact order that I have typed them, in
Also I am creating a fact app that I want to generate strings in my array in the exact order that I have typed them, in each time my funFactLabel.text button is pressed I want the new fact to appear in the order it is typed. I have also created a struct to store my array properly. Can someone tell me what is wrong with my code please!
Swift
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var funFactLabel: UILabel!
let factBook = FactBook()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
funFactLabel.text = factBook.factsArray[0]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func showFunFact() {
funFactLabel.text = sortInPlace factBook.factsArray[1]
}
1 Answer
Nils Garland
18,416 PointsTry this, it should start at [1] for you.
funFactLabel.text = factBook.factsArray.sortInPlace()
Chinwendu Opara
Courses Plus Student 1,734 PointsChinwendu Opara
Courses Plus Student 1,734 PointsHello! Tank you so much for assisting me! These are the errors I am receiving after implenting the code you just suggested.
import UIKit
class ViewControllervarIViewController { @IBOutlet weak var funFactLabel: UILabel! let factBook = FactBook()
! override func didReceiveMemoryWarning() { (METHOD DOES NOT OVERRIDE ANY METHOD FROM ITS SUPERCLASS) ! super.didReceiveMemoryWarning() ('SUPER' METHODS CANNOT BE REFERENCED IN A ROOT CLASS) // Dispose of any resources that can be recreated. }
}
Nils Garland
18,416 PointsNils Garland
18,416 PointsHave you simply tried to do this? I have never used sorting before as I am new to iOS but I am trying to help out with the best of my knowledge.
factBook.factsArray.sort()