[英]What type should I use?
I have a result coming from a method that is either of kind TWTweetComposeViewControllerResult or SLComposeViewControllerResult. 我有一个来自TWTweetComposeViewControllerResult或SLComposeViewControllerResult类型的方法的结果。
I need to pass this to a method. 我需要将此传递给方法。 Something like 就像是
[self doSomething:result];
How do I declare this method? 如何声明此方法?
- (void) doSomething:(SLComposeViewControllerResult) result ?
- (void) doSomething:(TWTweetComposeViewControllerResult) result ?
- (void) doSomething:(NSNumber *) result ?
Make two different methods that handle each. 制作两种分别处理的方法。 Each enum is a different type and should be treated as such. 每个枚举都是不同的类型,应该这样对待。 You can also forward the result on, using a boolean if you are just indicating success, or your own custom enum if you need more information. 您也可以使用boolean(如果您只是表示成功)来转发结果,如果需要更多信息,则可以使用自己的自定义枚举。
- (void)doSomethingSL:(SLComposeViewControllerResult) result
{
// made up, idk what the result enum would be be
[self doSomething:(result == SLComposeSuccess)];
}
- (void)doSomethingTweet:(TWTweetComposeViewControllerResult) result
{
// made up, idk what the result enum would be be
[self doSomething:(result == TWTweetSuccess)];
}
- (void)doSomething:(BOOL)success
{
}
If you are still convinced that you want to handle them in a uniform way and ignore types, you could always cast the results to an int in the method and forward them on. 如果仍然确信要以统一的方式处理它们并忽略类型,则可以始终将结果强制转换为方法中的int并继续进行转发。
Both SLComposeViewControllerResult and TWTweetComposeViewControllerResult are both enums, with 0 meaning cancelled and 1 meaning done. SLComposeViewControllerResult和TWTweetComposeViewControllerResult都是枚举,其中0表示取消,1表示完成。
So any of these should be OK: 因此,这些都应该可以:
- (void) doSomething:(SLComposeViewControllerResult) result;
- (void) doSomething:(TWTweetComposeViewControllerResult) result;
- (void) doSomething:(NSInteger) result;
[edit] Note this comment in TWTweetComposeViewController.h: [edit]请在TWTweetComposeViewController.h中注意以下注释:
// This class has been deprecated in iOS 6. Please use SLComposeViewController (in the Social framework) instead.
So you should just use the SLComposeViewControllerResult version. 因此,您应该只使用SLComposeViewControllerResult版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.