evermeer / AlamofireJsonToObjects

An Alamofire extension which converts JSON response data into swift objects using EVReflection
Other
161 stars 28 forks source link

Could not create an instance for type "Forecast" #29

Closed BeBetter7 closed 8 years ago

BeBetter7 commented 8 years ago

Hi. I used your library my old project and it was very helpful for me. Thank you.

Now I'm using your library again. But I faced a problem this time. I suspected my model class and because of that I used your example for the test.

I got this error "Could not create an instance for type Forecast".

now my versions :
xcode : 7.3.1 pod version : 1.0.1 imported some pods : Alamofire (3.5.0) AlamofireJsonToObjects (1.6.0) EVReflection (2.46.0)

I think this is about versions but I dont know. Do you have any idea about that? Thanks.

evermeer commented 8 years ago

Hi, one question, are you using a framework to hold your data models? If so, then you should initialise it by calling a function like: EVReflection.setBundleIdentifier(Forecast) P.S. You could also add multiple frameworks

BeBetter7 commented 8 years ago

Hi. I just use EVReflection and AlamofireJsonToObjects. Do I have to do this?

BeBetter7 commented 8 years ago

Hi again. I'm testing your test class and I'm getting error in that. I imported Alamofire,EVReflection and AlamofireJsonToObjects pods in TestClass. And My pod file like this, platform :ios, '9.0' use_frameworks! target 'ProjectA' do pod 'Alamofire', '3.5.0' pod 'AlamofireJsonToObjects' pod 'EVReflection' pod 'ObjectMapper', '1.4.0' pod 'SwiftEventBus' pod 'AlamofireObjectMapper', '3.0.2' pod 'Kingfisher', '~> 1.8' pod 'Player', '~> 0.1.3' pod 'SCLAlertView' pod 'MBProgressHUD' pod 'Fabric' pod 'TwitterKit' pod 'TwitterCore' pod 'MobilePlayer' pod 'PureLayout' pod 'SwiftyJSON', '~> 2.0' pod 'SwiftKeychainWrapper' pod 'KeyClip' end

target 'ProjectATests' do pod 'Alamofire', '3.5.0' pod 'AlamofireJsonToObjects' pod 'EVReflection' pod 'ObjectMapper', '1.4.0' pod 'SwiftEventBus' pod 'AlamofireObjectMapper', '3.0.2' pod 'Kingfisher', '~> 1.8' pod 'Player', '~> 0.1.3' pod 'SCLAlertView' pod 'MBProgressHUD' pod 'Fabric' pod 'TwitterKit' pod 'TwitterCore' pod 'MobilePlayer' pod 'PureLayout' pod 'SwiftyJSON', '~> 2.0' pod 'SwiftKeychainWrapper' pod 'KeyClip' end `

and versions Using Alamofire (3.5.0) Using AlamofireJsonToObjects (1.6.0) Using AlamofireObjectMapper (3.0.2) Using EVReflection (2.46.0) Using Fabric (1.6.8) Using KeyClip (1.3.3) Using Kingfisher (1.9.3) Using MBProgressHUD (1.0.0) Using MobilePlayer (1.1.5) Using ObjectMapper (1.4.0) Using Player (0.1.3) Using PureLayout (3.0.2) Using SCLAlertView (0.6.0) Using SwiftEventBus (1.1.0) Using SwiftKeychainWrapper (2.0.0) Using SwiftyJSON (2.4.0) Using TwitterCore (2.4.0) Using TwitterKit (2.4.0)

And now I'm getting following error in Evreflection. I couldn't solved this problem. Please help me.

screen shot 2016-09-26 at 15 38 08

evermeer commented 8 years ago

The most common cause of this error is one of these:

There is a workaround available for that. You have to implement the EVArrayConvertable protocol. This means that you have to implement the function: func convertArray(_ key: String, array: Any) -> NSArray For a sample see: https://github.com/evermeer/EVReflection/blob/Swift3/EVReflection/EVReflectionTests/EVReflectionWorkaroundsTests.swift#L180

If it's not this, then I need more information for solving this. Usually the class structures plus a json will be enough.

BeBetter7 commented 8 years ago

First of all, I really thank you for your interest and quick answers. Secondly now I am just using your test class, models and json but I'm getting this error.

evermeer commented 8 years ago

That's strange... Then that could only happen when there is a bundle identifier mis match. Usually this could be corrected by using: EVReflection.setBundleIdentifier(YourClassHere)

I do use code for fixing bundle identifier names with special characters. Maybe you are using unhandled special characters. What do you get if you print this: print(Bundle(for: type(of: YourClassHere())).infoDictionary?[kCFBundleNameKey as String] as? String ?? "") print(Bundle(for: type(of: YourClassHere())).bundleIdentifier)

BeBetter7 commented 8 years ago

Hey. I changed versions and remove some pods . As a result I solved my problem in Unit Test class. But in ViewController class I'm still getting "Could not create an instance for type Forecast" error. In ViewController class I added "EVReflection.setBundleIdentifier(Forecast)" before request call but nothing is changed. This is same error I got when I removed EVReflection.setBundleIdentifier(Forecast) from unit test.

evermeer commented 8 years ago

are you sure that the name of your bundle does not have any special characters? what is the CFBundleName in your .plist? Is it set to $(PRODUCT_NAME) ? What do you have in your targets display name?

evermeer commented 8 years ago

Is this still an issue?

BeBetter7 commented 8 years ago

I created a completely new project and moved my files to that one. Same settings and it worked. Sorry for the late answer.