Null passed to a callee that requires a non-null argument

Hi everyone,


just have a problem with my rss newsfeed that doesn't work anymore due to:


savedFeeds = [[NSMutableArray alloc] initWithObjects:nil];


I get the error "null passed to a callee that requires a non-null argument"


Can anyone help how to fix this?

Thank you very much in advance

Accepted Answer

As far as I tested, the message is just a waning and your app should work as expected. And the message must have been:

warning: null passed to a callee that requires a non-null argument


But ignoring non-null warning is not a good habit, so, if you want to avoid that, you need to see your original code is just creating an empty mutable array.

Write:

savedFeeds = [[NSMutableArray alloc] init];

or:

savedFeeds = [NSMutableArray array];

Thanks for the answer, and sorry for the error in the message!


No it is not just a warning, I tested it on the simulator as well as on my device. The feeds are not popping up anymore.

Also your two solutions did not change anything. Same result, the feeds are not shown on the iphone.

Thanks again

I say these three lines have the same effect.

    savedFeeds = [[NSMutableArray alloc] initWithObjects:nil];
    savedFeeds = [[NSMutableArray alloc] init];
    savedFeeds = [NSMutableArray array];

So, if your app does not show your RSS feed with the first line, neither the second nor the the third.


I guess you have mistakenly modified your code and the original working code was a little bit different than:

    savedFeeds = [[NSMutableArray alloc] initWithObjects:nil];

Or you may modified other part of your code that I cannot see.

Just had a look in an older version of the app, and also in the actual version on app store (where it is still working). Really no changes at all in the code. With xCode 7.1 I get this error for the first time and the rss feed is not working anymore. Really true.

Thanks again

A really odd behavior, but we need to see the fact. Some odd things may happen according to the changes of SDKs.

But as for now, I have no clue what is causing your issue.

If you can show more info which may contain some clues, I (or many other developers) will gladly find what's causing the problem with you.

One thing I can advise to you is that you should be free from the line generating the message. Odd things are good at playing hide and seek.

Ok, I have to admit that I am not a profi in Xcode, so I can add the whole code here, maybe this helps.

This is my AppMasterViewController. The error, new in Xcode 7.1 is in line 41. Maybe this helps.


//
//  APPMasterViewController.m
//  meviva
//
//  Created by on 10/03/2014.
//  Copyright (c) 2014 Thomas. All rights reserved.
//

#import "APPMasterViewController.h"
#import "APPDetailViewController.h"
//#import "MainTabBarController.h"
#import "RSSObject.h"
@interface APPMasterViewController () {
    NSXMLParser *parser;
    NSMutableArray *feeds;
    NSMutableDictionary *item;
    NSMutableString *title;
    NSMutableString *link;
    NSString *element;

    NSMutableArray *currentFeeds;
    RSSObject *tempRssObj;
    NSMutableArray *savedFeeds;

}
@end

@implementation APPMasterViewController

- (void)awakeFromNib
{
    [super awakeFromNib];
}

- (void)viewDidLoad {

    self.tableView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg_home.png"]];

    [super viewDidLoad];
    currentFeeds = [[NSMutableArray alloc] init];
    savedFeeds = [[NSMutableArray alloc] initWithObjects:nil];
    [self loadSavedFeeds];

    feeds = [[NSMutableArray alloc] init];
    NSURL *url = [NSURL URLWithString:@"http://xxxxxxxxxxxxxx.blogspot.com/feeds/posts/default?alt=rss"];
    parser = [[NSXMLParser alloc] initWithContentsOfURL:url];
    [parser setDelegate:self];
    [parser setShouldResolveExternalEntities:NO];
    [parser parse];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table View

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return feeds.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
    RSSObject * rssObj = [[RSSObject alloc] init];
    rssObj = [currentFeeds objectAtIndex:indexPath.row];
    if(!rssObj.isNewFeed)
        cell.textLabel.textColor = [UIColor grayColor];
    else
        cell.textLabel.textColor = [UIColor blackColor];
    cell.textLabel.text = [[feeds objectAtIndex:indexPath.row] objectForKey: @"title"];
    return cell;
}

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {

    element = elementName;

    if ([element isEqualToString:@"item"]) {
     
        item    = [[NSMutableDictionary alloc] init];
        title   = [[NSMutableString alloc] init];
        link    = [[NSMutableString alloc] init];
     
        tempRssObj    = [[RSSObject alloc] init];//thuan add
     
    }

}

- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {

    if ([elementName isEqualToString:@"item"]) {
     
        [item setObject:title forKey:@"title"];
        [item setObject:link forKey:@"link"];
     
        [feeds addObject:[item copy]];
     
        tempRssObj.link = link;
        tempRssObj.title = title;
        tempRssObj.isNewFeed = TRUE;
        [currentFeeds addObject: tempRssObj];
    }

}

- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {

    if ([element isEqualToString:@"title"]) {
        [title appendString:string];
    } else if ([element isEqualToString:@"link"]) {
        [link appendString:string];
    }

}

- (void)parserDidEndDocument:(NSXMLParser *)parser {

    [self.tableView reloadData];
    [self updateBadgeValue];

}

-(void) updateBadgeValue{
    [self markNewFeeds];
    int countNewFeeds = [self getCountNewFeeds];
    UINavigationController* parent = (UINavigationController*)[self parentViewController];
    if (countNewFeeds>0) {
        parent.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", countNewFeeds];
    }
    else
        parent.tabBarItem.badgeValue = nil;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([[segue identifier] isEqualToString:@"showDetail"]) {
     
        NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
        NSString *string = [feeds[indexPath.row] objectForKey: @"link"];
        [[segue destinationViewController] setUrl:string];
     
        RSSObject * rssObj = [[RSSObject alloc] init];
        rssObj = [currentFeeds objectAtIndex:indexPath.row];
        rssObj.isNewFeed = FALSE;
     
        if (![self checkExistObject:rssObj]) {
            [savedFeeds addObject:rssObj];
         
            [self saveFeeds];
            [self updateBadgeValue];
            [self loadSavedFeeds];
            [self.tableView reloadData];
        }
     
    }
}

-(int) getCountNewFeeds{
    int count = 0;

    for (int i=0; i< currentFeeds.count; i++) {
        tempRssObj = [currentFeeds objectAtIndex:i];
        if (tempRssObj.isNewFeed) {
            count ++;
        }
    }
    return count;
}


- (void)saveFeeds{
    RSSObject * temp =[[RSSObject alloc] init];
    temp.title =@"ABC";
    temp.link = @"link";
    temp.isNewFeed = TRUE;
    NSData *customObjectData = [NSKeyedArchiver archivedDataWithRootObject:savedFeeds];
    [[NSUserDefaults standardUserDefaults] setObject:customObjectData forKey:@"SAVED_FEEDS"];
    [[NSUserDefaults standardUserDefaults] synchronize];

}

- (void)loadSavedFeeds {
    //    RSSObject * temp;
    NSData *customObjectData = [[NSUserDefaults standardUserDefaults] objectForKey:@"SAVED_FEEDS"];
    if (customObjectData) {
        savedFeeds = [NSKeyedUnarchiver unarchiveObjectWithData:customObjectData];
    }

    //    //    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    //    savedFeeds = [defaults objectForKey:@"SAVED_FEEDS"];
}

-(void) markNewFeeds{
    RSSObject * currentObj = [[RSSObject alloc] init];
    RSSObject * savedObj = [[RSSObject alloc] init];

    for (int i=0; i< currentFeeds.count; i++) {
        currentObj = [currentFeeds objectAtIndex:i];
        for (int j=0; j<savedFeeds.count; j++) {
            savedObj = [savedFeeds objectAtIndex:j];
            if ([currentObj.link isEqualToString:savedObj.link] && [currentObj.title isEqualToString: savedObj.title]) {
                currentObj.isNewFeed = FALSE;
            }
        }
    }
}

-(BOOL) checkExistObject:(RSSObject *)rssObj{

    for (RSSObject * temp in savedFeeds) {
        if ([temp isEqual:rssObj]) {
            return TRUE;
        }
    }
    return FALSE;
}

@end


Next I have a View for the Details of each feed


#import "APPDetailViewController.h"

@implementation APPDetailViewController

#pragma mark - Managing the detail item

- (void)viewDidLoad {
    [super viewDidLoad];
    NSURL *myURL = [NSURL URLWithString: [self.url stringByAddingPercentEscapesUsingEncoding:
                                          NSUTF8StringEncoding]];
    NSURLRequest *request = [NSURLRequest requestWithURL:myURL];
    [self.webView loadRequest:request];
}

@end


And last but not least the RSSObject


#import "RSSObject.h"
#define RSS_LINK_KEY @"RSS_LINK_KEY"
#define RSS_TITLE_KEY @"RSS_TITLE_KEY"
#define RSS_IS_NEW_KEY @"RSS_IS_NEW_KEY"

@implementation RSSObject
@synthesize link;
@synthesize title;
@synthesize isNewFeed;
- (id)initWithCoder:(NSCoder *)decoder {
    self = [super init];
    if(self) {
        self.link = [decoder decodeObjectForKey:RSS_LINK_KEY];
        self.title = [decoder decodeObjectForKey:RSS_TITLE_KEY];
        self.isNewFeed = [decoder decodeBoolForKey:RSS_IS_NEW_KEY];
    }
    return self;
}

- (void)encodeWithCoder:(NSCoder *)encoder {
    [encoder encodeObject:self.link forKey:RSS_LINK_KEY];
    //dereferance the pointer to persist the value
    [encoder encodeObject:self.title forKey:RSS_TITLE_KEY];
    [encoder encodeBool:self.isNewFeed forKey:RSS_IS_NEW_KEY];
}
@end

I have the same warning with:


NSData *imgData = [bitmap representationUsingType: fileType properties: nil];


The Application still works with this code but I supressed the warning with:


NSDictionary *myDict = [NSDictionary dictionary]; //allocates an empty temporary dictionary

NSData *imgData = [bitmap representationUsingType: fileType properties: myDict];

If network related code suddenly quit working with the iOS 9 SDK my #1 suspect would be ATS (Application Transport Security).

Thank you so much! This was really one of the problems!! Thanks again.

Just FYI, modern versions of Objective-C make it really easy to get an empty dictionary.

NSData *imgData = [bitmap representationUsingType: fileType properties: @{}];

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Null passed to a callee that requires a non-null argument
 
 
Q