Static JSON crash in 2.4.0 & 2.5.0



Still having trouble with presenting static JSON of tweets, which worked in 2.2.0, but crashes in 2.4.0 or 2.5.0. It looks like nothing has changed in the twitter json API, so I think it must be a twitter SDK thing. Here is the static trace inside of twitter’s code:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid entity type found'
*** First throw call stack:
	0   CoreFoundation                      0x0000000107b8b34b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x00000001075ec21e objc_exception_throw + 48
	2   CoreFoundation                      0x0000000107bf4265 +[NSException raise:format:] + 197
	3   Sifftr                              0x000000010338db8b -[TWTRTweetPresenter entityRangesForTweet:types:] + 407
	4   Sifftr                              0x00000001033aa29a -[TWTRTweetLabel setTextFromTweet:] + 153
	5   Sifftr                              0x00000001033c07b7 -[TWTRTweetView configureWithTweet:] + 320

Anyone know how to fix this? (iOS10)


As a work around, I started using the TWTRAPIClient method .loadTweets(withIDs: tweetIds), but I get the same error. Stack trace below:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid entity type found'
*** First throw call stack:
	0   CoreFoundation                      0x000000010bd5934b __exceptionPreprocess + 171
	1   libobjc.A.dylib                     0x000000010b7ba21e objc_exception_throw + 48
	2   CoreFoundation                      0x000000010bdc2265 +[NSException raise:format:] + 197
	3   Sifftr                              0x0000000107556bfb -[TWTRTweetPresenter entityRangesForTweet:types:] + 407
	4   Sifftr                              0x000000010757330a -[TWTRTweetLabel setTextFromTweet:] + 153
	5   Sifftr                              0x0000000107589827 -[TWTRTweetView configureWithTweet:] + 320


also getting the crash when i load a single tweet at a time. : (

using the twitter client’s load Tweet with id method


What’s weird is that the Tweet loads fine. It’s only when I configure a TweetView with a tweet that the crash happens.


I’ve isolated it further. When I load tweets in the iPhone-facing (i.e. ‘normal’) ios project, loadTweetWithId works fine.

When I load tweets inside of a dynamic framework, I get that weird crash, as noted above.


Thanks for reaching out on this @danramteke and for your updates! Can you share the static JSON that you’re getting back when this happens or the specific tweet you’re trying to load? Would love to dig in more.


Hey @bonnell! Thanks for reaching out!! I would like to highlight that this used to work in 2.2.0, but doesn’t work any more in 2.4.0 and 2.5.0

I narrowed it down to it being about frameworks, and you can replicate this using TwitterClient’s loadTweetWithId method. No static JSON needed!

I’ll start with the architecture of my app, I’ll give two examples of the crash: one with static json, and one using only methods available in TwitterKit. I’ll share my current workaround. I’ll also share some workarounds that didn’t work. And then close.

App Architecture

Here’s an overview of my app’s architecture: I have a framework of shared logic (because my app has a share extension, etc). The framework has all my models for Posts and Users, etc. And because the framework has all the models, I put in all my network loading code in there as well.

My Podfile has TwitterKit as a dependency of the framework. And the main app has the framework as a dependency in Xcode. TwitterKit is only in my main app at all because of this transitive dependency.

Static Json Example

So if I get some json from my server in the framework, and in the framework I initialize a tweet: TWTRTweet(jsonDictionary: tweetJson). And when I pass that TWTRTweet back to my main app, and configure a TWTRTweetView with it self.tweetView.configure(with: tweet), I now get a crash. exception 'NSInvalidArgumentException', reason: 'Invalid entity type found'

TwitterKit Native Example

So if i get a tweet ID from my server in the framework, and in the framework I call twitterClient.loadTweetWithId:tweetId, and then pass that loaded tweet back into my main app, and configure a TWTRTweetView with it, then I get the same exact crash. exception 'NSInvalidArgumentException', reason: 'Invalid entity type found'

Current work around

Currently, I get tweet json from my server in the framework. I pass the raw json from the framework to my main app, and then create the tweet TWTRTweet(jsonDictionary: tweetJson) in my main app, outside of the framework. And this works. I’m not happy with this workaround because I want my framework to handle all the data loading.

Failed work arounds

Because of this transitive dependency of my app on the framework, and the the framework on the Cocoapods framework, one of the things I tried was to put in the Fabric info.plist information in the info.plist of the framework. But TwitterKit did not pick up that info.

Another thing I tried was to instantiate Twitter() with the secret and consumer key inside of my framework, but I got the same crash.


In closing I would like to repeat that this used to work without a crash in 2.2.0, but crashes in 2.4.0 and 2.5.0 with exception 'NSInvalidArgumentException', reason: 'Invalid entity type found'


Thanks for the huge amount of detail @danramteke, may I ask for one more bit of info to make this easier to try and reproduce. What’s a tweet ID you’re specifically seeing this issue on?


pretty much any tweet id


Is this still an issue for you?


I am also having this problem with nearly every tweet…
One example tweet ID is 839269941610233858


Jacob, are you also seeing this issue inside of a Dynamic Framework dependency? Or are there other factors at play?