ios - 最佳代码风格

标签 ios objective-c macos

<分区>

填充变量值的最佳方法是什么。该方法应该从存档中获取 NSData 类型的图片,如果有问题则写入错误。

- (void) svg:(void(^)(NSData *imData))image ByIndex:(NSInteger)index error:(NSError * __autoreleasing *)error;

- (void) svg:(NSData **imData)image ByIndex:(NSInteger)index error:(NSError * __autoreleasing *)error;

- (NSData *) imageByIndex:(NSInteger)index error:(NSError * __autoreleasing *)error;

或其他变体?

最佳答案

如果是同步的:

- (NSData *)dataForImageAtIndex:(NSInteger)index error:(NSError * __autoreleasing *)error;

或者,如果它是异步的:

- (void)requestDataForImageAtIndex:(NSInteger)index completionHandler:(void(^)(NSData *data, NSError *error)completionHandler;

或者,如果您想为了 Swift 互操作性而指定可空性:

- (NSData * __nullable)imageDataForIndex:(NSInteger)index error:(NSError * __nullable __autoreleasing * __nullable)error {

- (void)requestDataForImageAtIndex:(NSInteger)index completionHandler:(void (^ __nonnull)(NSData * __nullable data, NSError * __nullable error))completionHandler

关于ios - 最佳代码风格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31240170/

相关文章:

iOS 将 AVI 转换为 MP4

iOS 下载大量图片,最佳解决方案

ios - Game Center GKTurnBasedMatch 问题与 matchData 属性

objective-c - 在 Cocoa 中创建单选按钮矩阵

OS X 10.5 上带 Zend 调试器的 PHP

macos - 如何在Mac OSX下使用gcc设置可执行文件的运行时路径(-rpath)?

ios - 更改模态视图的演示类型?

ios - 类别中的自定义 NSManagedObject setter

ios - 如何在 UIViewController 网格之间进行管理和转换?

ios - .self 在 Swift 中的结构类型之后