Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is perform:withObject method not found?

I want to fix warnings in my application code. I have an AddressBookModel.h which implements the TTModel protocol.

You find both interface and implementation of the AdressBookModel in the answer of this question. This is exactly how I implemented it How to use Three20 TTMessageController?

However for

[_delegates perform:@selector(modelDidStartLoad:) withObject:self];

and some other similar selectors I get warnings like

Method -perform:withObject not found (return type defaults to id)

Since _delegates is an array

- (NSMutableArray*)delegates {
    if (!_delegates) {
        _delegates = TTCreateNonRetainingArray();
    }
    return _delegates;
}

some suggested to use makeObjectsPerformSelector but this gives me an unrecognized selector sent to instance exception.

Here is the TTModel source code: http://api.three20.info/protocol_t_t_model-p.php

Why is perform:withObject missing? Is performSelector:withObject an alternative (my app crashes using it)?

like image 749
UpCat Avatar asked Apr 11 '26 02:04

UpCat


2 Answers

_delegates is an array of delegates. It is not a true delegate, as signified from the name which is in plural form. An array does not respond to the -modelDidFinishLoad: method — its elements do.

You need to take each element out of the array and call the method of them, e.g.

for (id<TTModelDelegate> delegate in _delegates)
   [delegate modelDidFinishLoad:self];

or even easier, using NSArray's -makeObjectsPerformSelector:…:

[_delegates makeObjectsPerformSelector:@selector(modelDidFinishLoad:)
                            withObject:self];
like image 131
kennytm Avatar answered Apr 13 '26 18:04

kennytm


perform:withObject: method that produces this warning is defined in NSArray(TTCategory) category in NSArrayAdditions.h file in Three20 framework. You need to ensure that this header is imported/referenced properly by compiler, i.e. you need to look at importing this specific header or check your Three20 integration configuration.

You do not need to change this method to makeObjectsPerformSelector: since this is just an import problem (your code runs fine but just produces compile warnings).

like image 31
Roman Kishchenko Avatar answered Apr 13 '26 19:04

Roman Kishchenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!