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:
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 } }
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
Post a Comment