swift - Scope and method passing -


i have defined within class:

class tableviewcontroller: uitableviewcontroller {      let sections = ["design", "development", "mobile"]     var blogpost1 = ["title" : "stackoverflow", "author" : "john doe"]     var blogpost2 = ["getting started" : "title", "john" : "author"]     var posts = [blogpost1, blogpost2]      override func viewdidload() {          super.viewdidload()          var blogposts = [blogpost1, blogpost2]     } } 

i dont understand why able create blogposts variable within viewdidload not inside class under blogpost2? if try, xcode won't autocomplete , return error says viewcontroller doesn't have member named "blogpost1". can create within viewdidload() not know how use within other functions.

second issue:

i have tableviewcontroller. within cellforrowatindexpath, trying send message:

 var posts = blogposts.objectatindex(indexpath.row) 

but objectatindex not suggested in autocomplete. i'm sure it's rookie mistake lost. idea?

for second issue, objectatindex method of nsarray class, whereas variable blogposts created type of array (of swift).

just use subscript syntax:

var posts = blogposts[indexpath.row] 

Comments

Popular posts from this blog

.htaccess - htaccess convert request to clean url and add slash at the end of the url -

php - facebook and github login HWIOAuthBundle and FOSUserBundle in Symfony2.1 -

hadoop - Sqoop installation export and import from postgresql -