@IBInspectable uses cocoa objects, not native fast types. So, everything that is implicitly converted to a fast type should be cocoa. For Number or Bool you will need NSNumber . For something like Point , Size , Rect , etc. You need to use NSValue . However, for String you can directly use String ; you do not need to use NSString .
So, in your case, you need to use NSNumber instead of Int . Would I use NSNumber? instead of NSNumber! if no value is specified in your / xib storyboard.
@IBInspectable var moodValue: NSNumber?
Update
As @JakeLin and @Echelon noted, for Int like values, Xcode will only show an attribute in the Attributes Inspector if you declare it as Int? but then it will fail at runtime. Should you use NSNumber? , it will not be broken at run time, but the attribute will no longer be available in the Attributes Inspector; it will only appear in the attributes of the Runtime User Defined Runtime (this seems like an error in Xcode for me).
The error itself tells us how to get around this problem:
IBInspectable [66994: 58722469] Failed to set (moodValue) user-defined validation property (q25429792 ___ IBInspectable.ViewController): [setValue: forUndefinedKey:]: this class is not a key value compatible with the encoding for the key moodValue.
This means that the runtime cannot find an attribute compatible with key values ββfor the class for moodValue ( Int attributes do not meet the requirements associated with the key value), and that you can implement setValue:forUndefinedKey: to fix this.
In this case, the implementation may look something like this:
@IBInspectable var moodValue: Int? override func setValue(value: AnyObject?, forUndefinedKey key: String) { if let value = value as? Int? where key == "moodValue" { self.moodValue = value } }
So, if you really want the attribute to appear in the Attributes Inspector, and you do not mind adding an additional method, declare your property as Int? and implement setValue:forUndefinedKey: If you don't need an extra method, will you have to be content with using the NSNumber? attribute user interface NSNumber? and User Defined Runtime Attributes.