如何在 iPhone 中声明自定义协议
我想使用一个协议,我们如何在iPhone中实现它。
///在POCViewController.h
#导入
@协议BasicAPI -(NSString*)你好; @结尾 @interface HessianPOCViewController : UIViewController { idbasicAPI;
}
@结束
///
// 在 POCViewController.m 中 // 在某些方法中
NSURL* url = [NSURL URLWithString@"http://www.caucho.com/hessian/test/basic ”];
代理 ID = (id)[CWHessianConnection proxyWithURL:url 协议:@protocol(basicAPI)];
NSLog(@"hello: %@", [代理你好]);
////
请帮我如何实现上面的代码?
I want to use a protocol, how can we implement it in iPhone.
///In POCViewController.h
#import
@protocol BasicAPI
-(NSString*)hello;
@end
@interface HessianPOCViewController : UIViewController
{
idbasicAPI;}
@end
///
// In POCViewController.m
// In Some methodNSURL* url = [NSURL
URLWithString@"http://www.caucho.com/hessian/test/basic"];id proxy =
(id)[CWHessianConnection
proxyWithURL:url
protocol:@protocol(basicAPI)];NSLog(@"hello: %@", [proxy hello]);
////
Please help me how I can implement above code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在上面的代码片段中 - @protocol 块位于头文件中,位于已存在的 @end 声明下方。常见用例如下:
然后在实现文件中的某个方法体中,MyClass.m
In the above code snippet - the @protocol block goes in your header file, underneath the @end declaration that's already there. Common use case is something like:
Then in some method body in your implementation file, MyClass.m
我看到您给出的示例取自 Hessian Objective-C 实现<的文档/a>.它向您展示了如何从 Objective-C 客户端与 Hessian Web 服务进行交互。
您是否有想要与之对话的现有 Hessian Web 服务?如果是这样,您需要在
@protocol
块中声明该服务的接口。 这个问题的答案给出了一些很好的例子,说明了它如何在客户与服务器端。I see that the example you give is taken from the documentation for the Hessian Objective-C implementation. It's showing you how to interact with a Hessian web service from an Objective-C client.
Do you have an existing Hessian web service that you're trying to talk to? If so, you need to declare in your
@protocol
block the interface to that service. The answers to this question give some good examples of how this works on both the client & server side.