0

I have a custom class called Message.

import UIKit

class Message {
    var sender: String
    var message: String

    init?(sender: String, message: String) {

        self.sender = sender
        self.message = message
    }
}

I also have a custom class called Chat that has a variable, called messageList, that is an array of the Message class.

class Chat {

    //MARK: Properties
    var name: String
    var image: UIImage?
    var animal: String
    var messageList = [Message]()

    //MARK: Initialisation
    init?(name: String, image: UIImage?, animal: String) {

        if name.isEmpty || animal.isEmpty {
            return nil
         }

        self.name = name
        self.image = image
        self.animal = animal
        let firstMessage = Message(sender: "animal", message: "Hi! Nice meeting you!")
        self.messageList.append(firstMessage)
    }

}

I have tried many different ways, but each time, I get an error when messageList is declared saying the following: "Property cannot be marked @NSManaged because its type cannot be represented in Objective-C" or "Property cannot be declared public because its type uses an internal type".

Thank you in advance,

Alex

1 Answer 1

1

Classes are declared as internal by default, so you have to add the public keyword to make them public.

import UIKit

public class Message {
    var sender: String
    var message: String

    init?(sender: String, message: String) {

        self.sender = sender
        self.message = message
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.