Type does not have a member

前端 未结 2 754
别那么骄傲
别那么骄傲 2020-11-27 22:31

I\'m playing around with a Swift playground working on a new class. For some reason I keep getting an error that the class \"does not have a member type\" with the name of

2条回答
  •  一个人的身影
    2020-11-27 23:00

    I agree with @Antonio The other way might be to create struct if you don't want to use init:

    class DataModel {
    
        struct MyStruct {
            static var myCalendar:NSCalendar = NSCalendar.autoupdatingCurrentCalendar()
            static let now  = NSDate()
        }
    
        var myData = [NSDate : Float]()
    
        var components = MyStruct.myCalendar.components(.CalendarUnitYear | .CalendarUnitMonth, fromDate: MyStruct.now)
    }
    

    Test

    var model:DataModel = DataModel()
    var c = model.components.year  // 2014
    

提交回复
热议问题