pkc
pkc

Reputation: 8516

Use of undeclared type Date

Which framework need to import to solve the below compile time error in swift :-

Use of undeclared type "Date'

enter image description here

Upvotes: 1

Views: 3379

Answers (3)

As you mentioned Swift 2.0 in your tags. So simply use this :

First import this framework in your class:

import Foundation

Than :

func hours(fromdate: NSDate) -> Int {
     // your code
}

Important note :

  • As i am also currently working with swift 2.0 so the above method is tried & tested of my code.

Hope it will guide you.

Upvotes: 4

Bhavin Ramani
Bhavin Ramani

Reputation: 3219

In Swift 3.0 apple removed the NS prefix ,if you are used Xcode8 with beta 4 and above you can use this

func hours(fromdate: Date) -> Int {
        // Your code
    }

If you are used in below Swift3 then we need to use NSxxx instead of all

func hours(fromdate: NSDate) -> Int {
        // Your code
    }

Upvotes: 4

Midhun MP
Midhun MP

Reputation: 107141

The Date class is introduced in Swift 3.0 & Xcode 8. So you won't get it in Swift 2.2 version. You need to use NSDate instead.

In Swift 3.0 apple removed the NS prefix from the classes.

  1. NSDate became Date
  2. NSCalendar became Calendar

Upvotes: 2

Related Questions