Question

I had,

public class Contact: NSObject {        
    var sName : String?
    var sUserEmail : String?
    var sUserCellNo : String?
}

and respective code in ProductName-Swift.h,

SWIFT_CLASS("_NAME_")
@interface Contact : NSObject
@property (nonatomic, copy) NSString * sName;
@property (nonatomic, copy) NSString * sUserEmail;
@property (nonatomic, copy) NSString * sUserCellNo;
- (instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

so i can access all these properties in my other objective C well.

Now i had to add new property in my Contact class so it becomes,

public class Contact: NSObject {
    var iUserAddressID : Int? //newly added
    var sName : String?
    var sUserEmail : String?
    var sUserCellNo : String?
}

but after cleaning-building I get ProductName-Swift.h same as previous,

SWIFT_CLASS("_NAME_")
    @interface Contact : NSObject
    @property (nonatomic, copy) NSString * sName;
    @property (nonatomic, copy) NSString * sUserEmail;
    @property (nonatomic, copy) NSString * sUserCellNo;
    - (instancetype)init OBJC_DESIGNATED_INITIALIZER;
@end

So, I can not user newly added iUserAddressID. how to overcome this issue?

FYI : using xcode6 beta4

Was it helpful?

Solution

I would suspect that it's balking at translating Int? to ObjC. That doesn't have an obvious form in ObjC. It could be an NSNumber or it could be an NSInteger*. Neither is a particularly common approach for this kind of problem in ObjC (it's more common to use a "magic value" like NSNotFound or -1). You can probably address this by making it an NSNumber? rather than an Int?. Swift callers should automatically bridge for you.

If you're not getting any warnings, I would open a radar about that. You should probably get some indication if an NSObject subclass cannot be converted all the way to ObjC.

This feels like you're trying to create foreign keys in an object data structure. If so, the better solution would be to create a UserAddress class and make your variable point to that rather than to an Int (then optionals will work fine).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top