title: iOS 8 works but iOS 7 crashes with -[NSNull length]: unrecognized selector sent to instance
body: <p>I've been searching for answers for this but still haven't been able to solve how to correct the problem.  This <a href="https://stackoverflow.com/questions/24738421/nsnull-length-unrecognized-selector-sent-to-instance">-[NSNull length]: unrecognized selector sent to instance</a> and this <a href="https://stackoverflow.com/questions/25672754/nsnull-length-unrecognized-selector-sent-to-instance-0x43fe068">[NSNull length]: unrecognized selector sent to instance 0x43fe068</a> did not help.</p>
  
  <p>I'm working on a chat app with a Parse back-end and I was having a timestamp problem with a chat message showing up out of order so I deleted the rows that were out of order from my Parse database using the Databrowser.  When I tested the app, that seemed to fix the problem on my iPhone 6 Plus and on the iPhone 6 simulator both running iOS 8.  However, when opening up the same chat room on my iPhone 5s running iOS 7, the app crashes consistently with the following error. </p>
  
  <p><code>-[NSNull length]: unrecognized selector sent to instance</code></p>
  
  <p>I have no idea why deleting a row would cause this to happen and why only on iOS 7?  I set an All Exceptions Breakpoint and here is the offending line along with a screenshot.</p>
  
  <pre><code>    self.lastMessageLabel.textColor = [UIColor redColor];
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xvJs8.png" alt="enter image description here"></p>
  
  <p>I still get the <code>NSNull length</code> crash even when I comment out the above line, but it breaks at the generic main.m.</p>
  
  <p>Any suggestions on how to solve this would be appreciated.  Thanks.</p>
  
  <p><strong>EDIT 1:</strong> Here's the code from my ChatView.m that's being loaded by my PrivateInbox.</p>
  
  <pre><code>- (void)loadMessages {
  
      if (isLoading == NO)
      {
          isLoading = YES;
          JSQMessage *message_last = [messages lastObject];
  
          PFQuery *query = [PFQuery queryWithClassName:PF_CHAT_CLASS_NAME];
          [query whereKey:PF_CHAT_ROOM equalTo:chatroomId];
  
          if (message_last != nil) {
              [query whereKey:PF_CHAT_SENTDATE greaterThan:[self.dateFormatter stringFromDate:message_last.date]];
          }
  
          [query includeKey:PF_CHAT_USER];
          [query orderByAscending:PF_CHAT_SENTDATE];
          [query addAscendingOrder:PF_CHAT_CREATEDAT];
          [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error)
          {
              if (error == nil)
              {
                  for (PFObject *object in objects)
                  {
                      PFUser *user = object[PF_CHAT_USER];
                      [users addObject:user];
  
                      if(![object[PF_CHAT_TEXT] isKindOfClass:[NSNull class]]) {
  
                          NSDate* sentDate;
                          if(object[PF_CHAT_SENTDATE] != nil)
                              sentDate = [self.dateFormatter dateFromString:object[PF_CHAT_SENTDATE]];
                          else
                              sentDate = object.createdAt;
  
                          JSQTextMessage *message = [[JSQTextMessage alloc] initWithSenderId:user.objectId senderDisplayName:user.objectId date:sentDate text:object[PF_CHAT_TEXT]];
                          [messages addObject:message];
  
                      } else if(object[PF_CHAT_PHOTO] != nil) {
  
                          NSDate* sentDate;
                          if(object[PF_CHAT_SENTDATE] != nil)
                              sentDate = [self.dateFormatter dateFromString:object[PF_CHAT_SENTDATE]];
                          else
                              sentDate = object.createdAt;
  
                          PFFile* photoFile = object[PF_CHAT_PHOTO];
                          JSQPhotoMediaItem *photoItem = [[JSQPhotoMediaItem alloc] init];
                          JSQMediaMessage *photoMessage = [[JSQMediaMessage alloc] initWithSenderId:user.objectId
                                                                                  senderDisplayName:user.objectId
                                                                                               date:sentDate
                                                                                              media:photoItem];
                          [messages addObject:photoMessage];
  
                          {
                              [photoFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
                                  photoItem.image = [UIImage imageWithData:data];
                                  [self.collectionView reloadItemsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForItem:[messages indexOfObject:photoMessage] inSection:0], nil]];
                              }];
                          }
  
                      } else if(object[PF_CHAT_VIDEO] != nil) {
  
                          NSDate* sentDate;
                          if(object[PF_CHAT_SENTDATE] != nil)
                              sentDate = [self.dateFormatter dateFromString:object[PF_CHAT_SENTDATE]];
                          else
                              sentDate = object.createdAt;
  
                          PFFile* videoFile = object[PF_CHAT_VIDEO];
                          JSQVideoMediaitem *videoItem = [[JSQVideoMediaitem alloc] initWithFileURL:[NSURL URLWithString:[videoFile url]] isReadyToPlay:YES];
                          JSQMediaMessage *videoMessage = [[JSQMediaMessage alloc] initWithSenderId:user.objectId
                                                                                   senderDisplayName:user.objectId
                                                                                       date:sentDate
                                                                                         media:videoItem];
                          [messages addObject:videoMessage];
                      }
                  }
  
                  if ([objects count] != 0) {
                      [JSQSystemSoundPlayer jsq_playMessageReceivedSound];                    
                      [self resetUnreadCount];
                      [self finishReceivingMessage];
                  }
              }
              else [ProgressHUD showError:@"Network error."];
              isLoading = NO;
          }];
      }
  }
  </code></pre>
  
  <p><strong>EDIT 2:</strong> I tried NSNullSafe from Nick Lockwood <a href="https://github.com/nicklockwood/NullSafe" rel="nofollow noreferrer">https://github.com/nicklockwood/NullSafe</a> and that allowed the Private Inbox to open without crashing and gets me past the NSNull Length error but I think that just masks the problem and I still don't know why it didn't crash on iOS 8 but did crash on iOS 7.</p>