3

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)?

Community
  • 1
  • 1
DarkLeafyGreen
  • 69,338
  • 131
  • 383
  • 601
  • What do you mean? `-performSelector:…` can accept any selector. – kennytm Mar 30 '11 at 08:13
  • I mean when I let xcode complete the code, then it shows just the modelDIdStartLoad and modelDIdCancle load. So can I use modelDidCHange and modelDidFinishLoad? – DarkLeafyGreen Mar 30 '11 at 08:18
  • What's the type of `_delegates`? Why not use `[_delegates modelDidChange:self]` directly? Also, "cancel", not "cancle". – kennytm Mar 30 '11 at 08:20
  • Xcode4 is not necessarily perfect. Have you considered the idea that the code sense simply isn't working properly? i.e. try typing out your selector name and seeing if it works. – JeremyP Mar 30 '11 at 08:55
  • I updated my question with more information – DarkLeafyGreen Mar 30 '11 at 09:12

4 Answers4

5

_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];
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005
  • @Art: The class is OK. So the problem would be you added a TTPickerTextField to `.delegates`. – kennytm Mar 30 '11 at 09:52
  • actually this is from this answer: http://stackoverflow.com/questions/5374684/how-to-use-three20-ttmessagecontroller, it works but gives me a lot of warnings, that the method "perform" is unknown. However the solutions here make the app crash – DarkLeafyGreen Mar 30 '11 at 10:02
  • I just provide AdressBookDataSource to my TTMessageController, it handles writing the contact to the TTPickerTextField. strange, I am not sure how to solve that... – DarkLeafyGreen Mar 30 '11 at 11:14
2

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).

Roman Kishchenko
  • 1,894
  • 1
  • 15
  • 12
1

Reading between the lines, it looks like you want the objects that are in your _delegates array to all perform a particular selector. You need to call -makeObjectsPerformSelector:withObject: like this:

[_delegates makeObjectsPerformSelector: @selector(modelDidCancelLoad:) withObject: self];
0

You are mistyping modelDidCancleLoad: should be modelDidCancelLoad:

'NSInvalidArgumentException', reason:
'-[__NSCFArray modelDidCancleLoad:]: unrecognized selector
 sent to instance 0x24f480'

Make sure your _delegates is what you are expecting it to be. It seems to be an NSArray.

unexpectedvalue
  • 6,079
  • 3
  • 38
  • 62