简体   繁体   English

我应该使用哪种类型?

[英]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.

相关问题 适用于 iOS 的 Ensembles:我应该使用什么类型的 iCloud 后端? - Ensembles for iOS: what type of iCloud backend should I use? 我应该为OpenGL-es顶点使用哪种数据类型? - What data type should I use for OpenGL-es vertices? 我应该在 ios 的日记应用程序中使用什么类型的数据库? - What type of database should I use in diary app in ios? 我应该在这个简单的iPhone应用程序中使用哪种类型的ViewController - What type of ViewController should I use in this simple iPhone app 我应该为我的ios应用程序使用什么类型的数据存储? - What type of data store should I use for my ios app? 我应该使用什么数据类型在Core Data中存储GUID? - What data type should I use to store a GUID in Core Data? 在 Swift 中,我应该使用什么数据类型来存储 13 位整数? - In Swift, what data type should I use to store Integers of 13 digits? 将字节数组从Swift转换为Objective-C时应使用哪种数据类型 - What data type should I use when converting a byte array from Swift to Objective-C 我应该使用哪种类型的Web服务来供iOS / Android应用程序使用? - What type of web service should I use for consumption by iOS/Android apps? 我应该在CoreData中使用什么Objective-C类型来获取大量内容? - What Objective-C type should I use in CoreData for large amounts of content?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM