Why don't I use SelfB


(김찬홍) #1

This is my class...

class Human {
  static var singCount = 0
  func sing() {
    print("Lalala")
    type(of: self).singCount += 1
  }

I wanna use
   Self.singCount += 1
but I can't use it. Why compiler complain use of Self?


(Josh Parmenter) #2

self is lower case to reference the instance.
Hope that helps.
Josh

···

On Aug 25, 2016, at 8:10 AM, 김찬홍 via swift-users <swift-users@swift.org> wrote:

This is my class...

class Human {
  static var singCount = 0
  func sing() {
    print("Lalala")
    type(of: self).singCount += 1
  }

I wanna use
   Self.singCount += 1
but I can't use it. Why compiler complain use of Self?
_______________________________________________
swift-users mailing list
swift-users@swift.org
https://lists.swift.org/mailman/listinfo/swift-users