Is this a mistake or is there a subtle lesson here?
NSNumber *someNumber = @(1); [someNumber respondsToSelector:@selector(mutableCopy)]; // returns YES (!) [someNumber respondsToSelector:@selector(mutableCopyWithZone:)]; // returns NO
Apple LLVM 7.1 (iOS SDK 9.3)
This is because it NSObjectimplements itself -mutableCopy(for all objects, even those that do not match NSCopyingor NSMutableCopying), calling in -mutableCopyWithZone:(so that things implementing NSMutableCopyingwill get just done -mutableCopyWithZone:without repeating the implementation for -mutableCopy).
NSObject
-mutableCopy
NSCopying
NSMutableCopying
-mutableCopyWithZone:
Everything that inherits from NSObjectanswers to -mutableCopy, but if you actually call it, it will fail because it NSNumberdoes not respond to -mutableCopyWithZone:.
NSNumber
You can see it with
assert([NSObject instanceMethodForSelector:@selector(mutableCopy)] == [NSNumber instanceMethodForSelector:@selector(mutableCopy)])
bbum - , , .
. , -mutableCopy. ( , @(REALLYBIGNUMBERTHATISNEARMAX) ).
, respondsToSelector: . isKindOfClass:. , (NSArray vs. NSMutableArray, , - - , ).
respondsToSelector:
isKindOfClass:
NSArray
NSMutableArray
, . , @protocol, @optional.
@protocol
@optional
Source: https://habr.com/ru/post/1668957/More articles:Почему я не могу открыть свою службу Azure Bot в Visual Studio? - visual-studio-2015Как вы создаете фрагменты в VB.NET для Visual Studio 2015? - vb.netChange all columns except format from 1 to dollar - rAurelia Observer Does Not Shoot Array - aurelia.NET Core and .NET Standard projects do not perform incremental builds - c #Installing pygraphviz on Windows 7 x64 for Python 3.5 x32 with fatal error LNK1120: 1 unresolved external - pythonJenkins Pipeline: how to download artifacts with s3 plugin - amazon-s3Add a recursive function to a class as a member - functional-programminghttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1668961/downloading-a-bot-created-on-the-portal-leads-to-an-invalidunrunable-solution&usg=ALkJrhjs7vuYVBFZvkvBaeQ5x-CZqI-pHgFailed to get CallableThread in RejectionHandler - javaAll Articles