Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Swift framework in Swift: "Use of undeclared type 'MyCustomView'"

I have a Swift project where I added a framework target with a custom subclass of UIView so I can use the new live view in Interface Builder within Xcode 6. But when I try to add an @IBOutlet in my UIViewController subclass in my project I get a "Use of undeclared type 'MyCustomView'" error and I can't build my project.

Here's my code from the UIViewController subclass:

import UIKit
import MyCustomFramework


class MyViewController: UIViewController {

    @IBOutlet var myCustomView: MyCustomView?

}

And this is what 'MyCustomView.swift' within the 'MyCustomFramework' target looks like:

import UIKit

@IBDesignable class MyCustomView: UIView {

    @IBOutlet var imageView: UIImageView?

    init(coder aDecoder: NSCoder!) {
        super.init(coder: aDecoder)
    }
}

Anyone know what I forgot? Did I import it in a wrong way? Did I miss something?

like image 777
Jeehut Avatar asked Jul 25 '14 12:07

Jeehut


2 Answers

You should mark the class as public since it is part of different framework module

@IBDesignable public class MyCustomView: UIView {

}

By default classes and methods will be at internal access level. If you want to use that out side of that target you should mark it as public. Then only it will be the part of public interface(visible to outside of target)

like image 72
Anil Varghese Avatar answered Oct 06 '22 15:10

Anil Varghese


I faced the same error after importing my custom framework A inside another project B, even all my classes were public.

I solved it by changing the Building settings of my custom framework A at Build Active Architecture only to No instead of Yes, then clean compile, and reimport the framework again after deleting the old one.

Then everything compiled successfully.

like image 1
Hany Sakr Avatar answered Oct 06 '22 15:10

Hany Sakr