iphone - Assigning a protocol to an NSMutableDIctionary? -


I am using singleton backbone in my application to handle the errors After fixing the error, They will be handled in a singleton and will be broadcast during an app notification. Anyway, this is not what my question is about, but when I pass a new error in such a single object

  [[Singleton Shareholders Shareholder] addError: ErrorDictionary_ here];   

I should have a NSMutableDictionary protected errorDictionary_ here in my code given by @protocol , so whenever I send my code to other people I give my team warnings about the wrong information that they may have forgotten to enter the dictionary.

This is also possible for beginners because it is to connect the protocols of the setter and one gateer is very easy.

  - (NSMutableArray  * GetmyError {}  

I hope someone can help me.

I'm not the only one to apply the search for objects (read class insenses) instead of dictionary. A protocol has been applied to my dictionary only.

itemprop = "text">

If I think what you are asking for, you have a lot of trouble Should be able to do without In your Singleton Class Singleton Entertainers, you must have:

  @interface singleton errors: NSObject {// some definitions ... // current array of all errors if you like NSMutableArray * sharedErrors So it can also be NSMutableSet; // more definitions ...} // Some properties ... @protecti (non-constructive, retaining) NSMutableDictionary & lt; ErrorTrotocol> Shared Partners; // More properties ... - (zero) addError: (NSMutableDictionary & lt; ErrorProtocol> *) newError; @end  

You must create a protocol to implement in this sample protocol, suppose you want to provide a single method to check that the object is valid - that is, all in the dictionary Related information is

  @protocol errorprotocol - (BOOL) is correct; @end  

You will then need the NSMutableDictionary sub-class so that your class can implement the ErrorProtocol protocol:

  @interface MyMutableDictionary: NSMutableDictionary & lt; ErrorProtocol> {} @end @implementationMyMutableDictionary - (BOOL) is validated {// Checking your validity here Return yes to; // Clear this line clearly} @end  

Then, whenever you throw an error, you can pass a new instance of MyMutableDictionary to Singleton Arter, And select it at isValid MyMutableDictionary, because it is assured that dictionary errors will be consistent with protocol and isValid :

 - (Zero) addError :( NSMutableDictionary & lt; ErrorProtocol> *) newError {if ([newError isValid]) {// Add new error to current array of errors [self.sharedErro Rs addObject: newError]; // To get "broadcast" error, other code goes here} and {// error is added by adding error to some code}}    

Overall, what is this

  • Each error is an NSMutableDictionary that corresponds to ErrorProtocol
  • The object that we use is each error MyMutableDictionary, a subclass of NSMutableDictionary
  • Protocol error protocol Valid defines a method that checks to fix the error or O
  • SingletonErrors object call isValid Method and error appropriately connects

  • Comments