Getting a struct variable to show in the UITableView Cell? swift /xcode8 -


im trying struct variable, "title" display cell text label in uitableview, know if possible?

i have achieved before using string, i'm not sure how access 1 of struct variables in context

this have declared struct

import foundation  struct note {    var title: string    var text: string  }  class notes {      var notes:[note]      public static let sharedinstance = notes()      private init() {         self.notes = []     }      public func add(title1: string, text1: string) throws {         self.notes.append(note(title: title1, text: text1))      } } 

and controller class, trying add simple values struct , display value of "title" variable in struct

override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell {     let cell = tableview.dequeuereusablecell(withidentifier: "note1", for: indexpath)          let note1 = notes.sharedinstance         try? note1.add(title1: "hello", text1: "world")         print(note1)         if let label = cell.textlabel {         // i've been trying work on line         //label.text = note1.notes(get title here?)[indexpath.row]         }          return cell     } 

close! need pick out array element before trying title:

if let label = cell.textlabel {     label.text = note1.notes[indexpath.row].title } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -