Search code examples
swiftiboutletcollection

Swift outlet collection - 'IBOutlet' property cannot be an array of non-'@objc' class type


I'm trying to setup an outlet collection in swift. The problem is I am getting the following error :

'IBOutlet' property cannot be an array of non-'@objc' class type '[Badge]'

Here is my code :

import UIKit

class BadgeModuleCell: UITableViewCell
{
    @IBOutlet var badges: [Badge]!
}

Is there anything I am doing wrong ? This seems to be the same as in the Apple documentation (here).


Solution

  • I figured out what was going wrong. I initially had a class called "Badge" that was a custom UIView. All was fine. Then I renamed it into "BadgeView" to allow me declare a new class called "Badge" from scratched. So here my outlet collection was supposed to contain object that are not outlet, which has no sense. I renamed @IBOutlet var badges: [Badge]! to @IBOutlet var badges: [BadgeView]! and all is working now.