Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How "id" type understands the receiver of method without casting?

After merging master to my working branch I got compiler error on the line, which wasn't be changed. The error looks like

id test;
[test count];

Multiple methods named 'count' found with mismatched result.

At first it looks clear, because compiler doesn't know which concrete type the "test" variable is. But I don't understand why it worked before.

  1. If I create a new file this line works, assuming that is a NSArray's method. Why compiler doesn't show error in this case?

  2. While showing error message, there is several possible receivers of count method are shown. (NSArray, NSDictionary, NSSet) Does it search all classes that can receive that message and show error if there are multiple?

  3. I noticed that error occurs when I import "-Swift.h" file. How it depends?

like image 444
iamirzhan Avatar asked Oct 05 '18 09:10

iamirzhan


People also ask

What is a broadcast receiver how system broadcast will be received by applications?

Broadcast in android is the system-wide events that can occur when the device starts, when a message is received on the device or when incoming calls are received, or when a device goes to airplane mode, etc. Broadcast Receivers are used to respond to these system-wide events.

What are the types of broadcast receivers in Android?

There are two types of broadcast receivers: Static receivers, which you register in the Android manifest file. Dynamic receivers, which you register using a context.

How do you use a broadcast receiver?

Creating a BroadcastReceiver The onReceiver() method is first called on the registered Broadcast Receivers when any event occurs. The intent object is passed with all the additional data. A Context object is also available and is used to start an activity or service using context. startActivity(myIntent); or context.

What is the role of the onReceive () method in the BroadcastReceiver?

The implementing class for a receiver extends the BroadcastReceiver class. If the event for which the broadcast receiver has registered happens, the onReceive() method of the receiver is called by the Android system.


1 Answers

Compiler doesn't cast or check your id type. It just provides you all possible selectors. You said that this issue connected with importing "-Swift.h" file. In this case check you Swift code, probably you have count function visible for Objective C which returns something else than Int.

Also, you can check the issue in Issue navigator, select it and it will show all count calls visible in Objective C. Check them all, most of them will return NSUInteger, but there should be one that returns something else, for example:

SWIFT_CLASS("_TtC3dev19YourClass")
@interface YourClass : NSObject
- (int32_t)count SWIFT_WARN_UNUSED_RESULT;
@end

like image 200
lobstah Avatar answered Nov 03 '22 00:11

lobstah