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?
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)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With