11

I get this warning only on my first item on a table view once i go into the "drill down" view on a core data app.

anyone else got this warning?

-[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?

thanks

George Asda
  • 2,119
  • 2
  • 28
  • 54

3 Answers3

1

Xcode 7.2.1, iOS 9.2.1, ARC enabled

Check to see that the NSData object you are using to store data does not get released before it is accessed. You must check this at the place where the data is accessed, not in your view controller or else where.

-[NSKeyedUnarchiver initForReadingWithData:]: data is empty; did you forget to send -finishEncoding to the NSKeyedArchiver?

This warning is raised when the NSData object is empty. The sure way to check if it is or not, is to use [yourDataObject length] and make sure it is not zero.

Hope this helps! Cheers.

serge-k
  • 3,394
  • 2
  • 24
  • 55
  • 1
    Hope you solved this a long time ago, but I stumbled onto your post just now. I posted my answer and here is a helpful post to read: http://stackoverflow.com/q/15773440/4018041 – serge-k Mar 02 '16 at 19:04
  • Thank you. It's not relevant to my project any more but it could help someone else. I have since moved to a different model and swift. – George Asda Mar 02 '16 at 19:05
0

once I had met this problem, It's cause by...

NSString *str = @"ss";
NSString *temp = [str substringToIndex:4];

In iOS8.

now xCode8.1 will tell you

* Terminating app due to uncaught exception 'NSRangeException', reason: '* -[__NSCFConstantString substringToIndex:]: Index 4 out of bounds; string length 2'

Stark
  • 1,676
  • 1
  • 9
  • 8
-1

It seems that you are trying to read from an empty data object.

Maybe you initialize your data as [NSData data] before or your saved data is empty.

malex
  • 9,874
  • 3
  • 56
  • 77