0

I am using a Swift based project and have imported some Objective C files. Now I want my Swift code to work back in ObjC files. All goes well but unfortunately, Int, Float and Double attributes of classes are not available to Objective C class. Any idea why is this not being open to Objective C?

Swift Class:

class Station: NSObject, NSCoding {

    var Id : Int!
    var placeId : Int!
    var name : String!
    var stationDescription : String!
    var uuid : String!
    var major : Int?
    var minor : Int?
    var coordinates: CLLocationCoordinate2D!
    var geoFenceRadius : Float?
    var questions : [Question]?


    }

Swift-Interface Generated Class:

@interface Station : NSObject <NSCoding>
@property (nonatomic, copy) NSString * _Null_unspecified name;
@property (nonatomic, copy) NSString * _Null_unspecified stationDescription;
@property (nonatomic, copy) NSString * _Null_unspecified uuid;
@property (nonatomic, copy) NSArray<Question *> * _Nullable questions;
- (BOOL)isEqual:(id _Nullable)object;
- (nonnull instancetype)init OBJC_DESIGNATED_INITIALIZER;
- (nonnull instancetype)initWithCoder:(NSCoder * _Nonnull)aDecoder OBJC_DESIGNATED_INITIALIZER;
- (void)encodeWithCoder:(NSCoder * _Nonnull)aCoder;
+ (Station * _Nullable)stationWithDictionary:(NSDictionary<NSString *, id> * _Nonnull)dict placeUUID:(NSString * _Nullable)placeUUID;
+ (NSArray<Station *> * _Nullable)parseListFromDictionariesList:(NSArray<NSDictionary<NSString *, id> *> * _Nonnull)dicts placeUUID:(NSString * _Nullable)placeUUID;
@end

This is the error while Id of object is Accessed. Error while accessing Id of object

Poles
  • 3,585
  • 9
  • 43
  • 91
Saad
  • 8,857
  • 2
  • 41
  • 51

1 Answers1

1

I just tried it and my ints are imported as NSInteger's (using Xcode 8.2.1 and Swift 3.0.1). Anyway, I think it is a bad idea to use Id as a variable name, for two reasons: 1) in Swift, you should use non-capitalized variable names; and 2) Id is very similar to an Obj-C reserved keyword id. Try to rename your variable to something like itemID. Also remove the ! after the variable names and initialized them with 0 like this:

class Station: NSObject, NSCoding {

var itemID : Int = 0
var placeId : Int = 0
var name : String!
var stationDescription : String!
var uuid : String!
var major : Int = 0
var minor : Int = 0
var coordinates: CLLocationCoordinate2D!
var geoFenceRadius : Float = 0.0
var questions : [Question]?


}

This is causing all your problems, as Martin pointed out earlier.

jvarela
  • 3,744
  • 1
  • 22
  • 43