0

I am facing a weird crash after updating the Xcode to 10.2. I have an Objective-C class method as below

@interface Car: NSObject 

+ (NSDictionary<NSString *, Class>  *) carMapping;

@end

which returns dictionary of type NSDictionary<NSString *, Class> as below

@implementation Car

+ (NSDictionary<NSString *, Class>  *) carMapping {
    return @{
        @"BMW": [BMWCar class],
        @"Mercedes": [MercedesCar class],
        @"Toyota": [ToyotaCar class],
        @"Tesla": [TeslaCar class]
        };
}

@end

I use this Objective-C method in Swift as

let carMapping = Car.carMapping()
print(carMapping)

which works perfectly fine with Xcode 10.1.

But after updating the Xcode to 10.2, app crashes saying Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) in line 1. I do not have any clue.

I do not have control over the class Car. How would I handle the situation?

Cœur
  • 37,241
  • 25
  • 195
  • 267
iOS
  • 3,526
  • 3
  • 37
  • 82
  • Actually that function signature says it returns a dictionary, not an array of dictionaries. You should post the body of your `carMapping()` method, along with the whole interface to your `Car` class. – Duncan C Apr 02 '19 at 13:06
  • @DuncanC, Sorry! my bad while writing the question. Corrected – iOS Apr 02 '19 at 13:09
  • How did you call carMapping in Objective-c? Did you clean the project and rebuild it? – E.Coms Apr 02 '19 at 13:46
  • @E.Coms Yes. Tried everything I could do. I did not call carMapping in Objective C, I do that in a Swift class. – iOS Apr 02 '19 at 13:57
  • That is still not an array of dictionaries. Your function returns a dictionary of type `[String: Class]`. – Duncan C Apr 02 '19 at 16:49

1 Answers1

1

If you want to use the class in swift without most hassles, just change the signature in the interface from Class to id. In the implementation, you don't need to change.

 @interface Car : NSObject
 + (NSDictionary<NSString *, id>  *) carMapping ;
 @end
E.Coms
  • 11,065
  • 2
  • 23
  • 35