ios - Swift 3 Instance member type -
i have func savenotes() sub-class of nsobject
note.swift file
func savenotes() { var adictionaries:[nsdictionary] = [] i:int in 0 ..< allnotes.count { adictionaries.append(allnotes[i].dictionary()) } userdefaults.standard.set(adictionaries, forkey: kallnotes) }
when try run project error "instance member 'savenotes' cannot used on type 'note'; did mean use value of type instead.
code masterviewcontroler.swift
import uikit import foundation class masterviewcontroller: uitableviewcontroller { var objects = nsmutablearray() override func viewdidload() { note.loadnotes() print("allnotes: \(allnotes)") var n:note = note() note.savenotes()
not sure i'm doing wrong here. help.
the error of:
instance member 'savenotes' cannot used on type 'note'; did mean use value of type instead.
is shown compiler because trying call non-instance method directly class.
thus, have 2 approaches:
first: use declared n
instance call savenotes()
function:
note.loadnotes() print("allnotes: \(allnotes)") let n:note = note() n.savenotes()
second: if aiming call savenotes()
directly note
class, should declared static
method:
static func savenotes() { ... }
for more information, check swift documentation - method ("type methods" section).
Comments
Post a Comment