ios - Cannot convert return expression of type 'Array<AboutMe>' to return type '[About me]' -


i have data model

struct aboutme {     private(set) public var name: string      init(name: string) {         self.name = name     } } 

and data service this

struct dataservice {     static let instance = dataservice()      private let sections = [         [aboutme(name: "rate app on app store")],         [aboutme(name: "facebook")],         [aboutme(name: "twitter")],         [aboutme(name: "linkeden")],         [aboutme(name: "instagram")],         [aboutme(name: "email feedback")]                             ]      func getsections() -> [aboutme] {         return sections     } } 

however wen try return sections of type me, won't let me, says can't convert return expression one. how can fix this.

sections (implicitly) declared [[aboutme]] return value of getsections() [aboutme] that's classic type mismatch.

solutions:

  1. change body of sections

    struct dataservice {     static let instance = dataservice()      private let sections = [         aboutme(name: "rate app on app store"),         aboutme(name: "facebook"),         aboutme(name: "twitter"),         aboutme(name: "linkeden"),         aboutme(name: "instagram"),         aboutme(name: "email feedback")                         ]      func getsections() -> [aboutme] {         return sections     } } 
  2. change return type of getsections()

    struct dataservice {     static let instance = dataservice()      private let sections = [         [aboutme(name: "rate app on app store")],         [aboutme(name: "facebook")],         [aboutme(name: "twitter")],         [aboutme(name: "linkeden")],         [aboutme(name: "instagram")],         [aboutme(name: "email feedback")]                             ]      func getsections() -> [[aboutme]] {         return sections     } } 

as sections constant anyway function getsections() redundant , not needed @ all.


and why not simply

struct aboutme {     let name: string } 

?

you initializer free , name intended constant.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -