Questions tagged [objective-c-protocol]

Protocols declare methods that can be implemented by any class. They can be used to force the implementation of necessarily used methods to assure the proper execution.

Protocols declare methods that can be implemented by any class. Protocols are useful in at least three situations:

  • To declare methods that others are expected to implement
  • To declare the interface to an object while concealing its class
  • To capture similarities among classes that are not hierarchically related

Protocols can be made optional specifically, otherwise the implementation is required for compiling successfully.

Developer Documentation for further information and usage

48 questions
0
votes
1 answer

What will happen if my class conforms to two protocols having same property?

Let's say I have two protocols @protocol Playlist @property(nonatomic, copy) NSString *title; @property(nonatomic, assign) NSUInteger trackCount; @end and another as @protocol Album @property(nonatomic, copy) NSString…
Anoop Nyati
  • 339
  • 2
  • 11
0
votes
0 answers

Is there a way to force XCode to provide autocompletion of imports and/or classes in header files that are not included by an implementation file?

I've noticed that while editing header files, XCode does not auto-suggest header files to import or classes from imported files unless the file you are editing is itself imported by some file that is included in the target. I kind of get the reasons…
tacos_tacos_tacos
  • 10,277
  • 11
  • 73
  • 126
0
votes
2 answers

Checking protocol conformance when using factory methods in Objective-C

I have recently been learning how to use protocols in Objective-C (using Apple's official guide) and I've been having trouble understanding what seems to me to be an inconsistency. In the documentation it is stated that - By specifying the required…
0
votes
1 answer

Do protocol objects have static storage duration?

When you pass @protocol(SomeProtocol) as an argument to a method, can the resulting pointer be considered to have static storage duration? Now considering that the protocol is defined at compile time, in a .h file, would that mean that it's pointer…
unom
  • 11,438
  • 4
  • 34
  • 54
0
votes
1 answer

Can an Objective-C protocol have category?

Objective-C category can implement a protocol. Is the reverse true - can an Objective-C protocol have category?
Boon
  • 40,656
  • 60
  • 209
  • 315
0
votes
1 answer

Why do delegate methods work without declaring protocol conformance?

I have one UITextField, and I drag from it to its owner to set the delegate in storyboard. And in my controller.h file, I didn't declare the class as conforming to the UITextFieldDelegate protocol. But the - (BOOL)textField:(UITextField *)textField…
Puttin
  • 1,596
  • 23
  • 27
0
votes
1 answer

Category for a class that conforms to a protocol

I'm trying to implement a category for a UIViewController and I want to be certain that the object conforms to a certain protocol. Something like this: #import @interface UIViewController (Category) @end Is this…
0
votes
1 answer

Objective-C protocol as parameter in another protocol

I am trying to create a generic repository (pattern) that accesses my web api. I am having trouble understanding how protocols work in objective-c (I come from c# where interfaces are a bit different). What I am trying to do is have ProtocolA be a…
crizzwald
  • 1,037
  • 2
  • 14
  • 30
0
votes
1 answer

how to use buttons defined in one class that class inherits UINavigationController and appeared in every other class in objective c?

is it possible that i define a class which inherit UINavigationController and add buttons in this class.and when ever i use this class in another class buttons will be shown on navigation bar of each class..hope it is clear.Thanks in Advance
user1960279
  • 494
  • 1
  • 8
  • 24
0
votes
2 answers

Conforming to a list of Protocols

I have a condition where I want a view controller to conform to any of 4 protocols. Is there a way to check if it conforms to any of these 4 protocols without doing a bunch of or statements in my if? Can you make an array of protocols?
NMunro
  • 1,282
  • 4
  • 18
  • 33
0
votes
1 answer

Subclass implements its own protocol delegate

I am new to iOS, don't know if this is possible or not. Basically I have two classes Parent and Child. Parent has a delegate which conforms to ParentProtocol. However, the delegate in Child not only conforms to ParentProtocol, but also another…
PeterWong
  • 15,951
  • 9
  • 59
  • 68
0
votes
1 answer

Delegate is not calling method

So i have a question . Can someone Tell me the Problem with this line of code for calling(protocol) a Method [self.delegate poplogin]; poplogin is method name , its not working for some reason. its not calling the method poplogin for reference…
user1669730
  • 65
  • 1
  • 8
0
votes
3 answers

How to enumerate an arbitrary set that conforms to NSFastEnumeration

I am trying to enumerate over a bunch of objects which, depending on the situation, may be either an NSArray or an NSOrderedSet. Since both conform to NSFastEnumeration, I would expect this to work: id enumerableSet = (test)…
Sasha
  • 3,405
  • 4
  • 19
  • 21
0
votes
1 answer

creating CLLocationCoordinate2D on the fly while conforming to MKAnnotation protocol

I have MyClass that conforms to MKAnnotation protocol. according to documentation, class is required to implement coordinate property which should return CLLocationCoordinate2D instance. My first implementation was like…
peetonn
  • 2,942
  • 4
  • 32
  • 49
0
votes
1 answer

How to look for required methods in a protocol?

This is what I do. While looking up an apple documentation of protocol in Chrome or Xcode, I Cmd-F searching for "required". If result is zero, I conclude that all methods in that protocol are optional. Am I doing it right? Or is there any "formal"…