How to assaign a Color Type to a class variable in Swift?

Viewed 119

I want to assign a color to each instance of the "Subject" class but it seems like I can't assign a type "Color" or "UIColor" to the variable "color",

import Foundation

class Subject {

var name: String
var color: NSObject

init(name: String, color: NSObject) {
    self.name = name
    self.color = color
}

I worked around the problem by using NSObject but in the future i would like to add a Realm database to my application and i can't use NSObject

1 Answers

For using UIColor in your class you must import UIKit framework. Just write import UIKit at the start of the file.

Related