Objective-C Coding Guide

2017-08-28  本文已影响50人  那山那海那段年华

Objective-C Coding Guide


版本: 1.1

修订: iOS茄子快传组

时间: 2017/08/28


总则: 英文单词拼写一定要正确、交流发音一定要准确、动名词使用一定要恰当


命名

正确:
- (void)resetBarAttribute:(UIColor *)normal highlight:(UIColor *)highlight font:(UIFont *)font
{
    for (UIButton *bar in self.bars) {
        [self setBar:bar :normal :highlight :font];
    }
}

不建议:
- (void)resetBarAttribute:(UIColor *)normal :(UIColor *)highlight :(UIFont *)font
{
    for (UIButton *bar in self.bars) {
        [self setBar:bar :normal :highlight :font];
    }
}


注释


项目结构


代码格式化

#define MAX_SIZE 30

static const NSUInteger kUsernameRow = 0;

不要出现下面这样:

/**用于获取每个section应当返回的cell个数*/
-(NSInteger)getSectionCount:(NSDictionary*)dict
{
    return (dict[kPhotos]==nil?0:[dict[kPhotos] count]+1)+(dict[kMusics]==nil?0:[dict[kMusics] count]+1)+(dict[kFiles]==nil?0:[dict[kFiles] count]+1)+(dict[kVideos]==nil?0:[dict[kVideos] count]+1)+(dict[kContacts]==nil?0:[dict[kContacts] count]+1)+(dict[kFloders]==nil?0:[dict[kFloders] count]+1);
}


代码组织

NSMutableArray *mediaItemsArrM = [NSMutableArray array];

字符串后     xxxStr/xxxStrM

集合后     xxxArray/xxxArrayM  xxxArr/xxxArrM

字典后     xxxDict/xxxDictM

NSMutableArray<ASMediaItem *> *mediaItemsArrM = [NSMutableArray array];

- (nonnull NSArray<NSArray<ASMediaItem *> *> *)selectMediaItemsArr;

- (void)saveWithMediaItemsArr:(nonnull NSArray<ASMediaItem *> *)mediaItemsArr;


[NSURL fileURLWithPath:nil];

[[NSFileManager defaultManager] createSymbolicLinkAtURL:nil withDestinationURL:nil error:nil];

[NSJSONSerialization dataWithJSONObject:nil options:0 error:nil];


@property (nonatomic, copy, readonly, nonnull) NSString *layerId;

CFStringRef FileBlockMD5HashCreateWithPath(NSString *filePath)

UpdateHash(&hashObject, fileHandle, startIndex, blockSize);

[[NSFileManager defaultManager] contentsOfDirectoryAtPath:[self accessToTheMainFilePath] error:&error];


其他

ASAdWrapper 类

+ (nonnull instancetype)wrapperWithLayerId:(nonnull NSString *)layerId fullAdId:(nonnull NSString *)fullAdId expiredDuration:(long long)expiredDuration;

ASAdInfo 类

+ (nonnull instancetype)infoWithLayerId:(nonnull NSString *)layerId fullAdId:(nullable NSString *)fullAdId;


ASAdWrapper 类

- (instancetype)initWithLayerId:(NSString *)layerId fullAdId:(NSString *)fullAdId expiredDuration:(long long)expiredDuration AdObject:(NSObject *)adObj adKeyword:(NSString *)adKeyword;

ASAdInfo 类

+ (instancetype)initWithLayerId:(NSString *)layerId fullAdId:(NSString *)fullAdId;

@protocol UITableViewDataSource

@required

//回调方法存在两个以上参数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;

@optional

//回调方法的参数只有类自己
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // Default is 1 if not implemented

@end

@protocol UITableViewDelegate

@optional

//使用did和will通知Delegate
- (nullable NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

@end

#import <UIKit/UIKit.h>

#import "MemberVariable.h"

@class ASUserInfo;

@interface DateilViewController : UIViewController
{
    //变量
    NSString *_dataString;
}


//属性
@property (nonatomic, strong) NSDictionary *supplyDateilDict;
@property (nonatomic, strong) NSMutableArray *supplyArray;

//方法
- (void)handleData;
- (void)createView;


@end

#import <Foundation/Foundation.h>
#import <uShareitSDK/AndyDictStore.h>
@class ASAdWrapper;
@class ASAdInfo;

@interface ASAdCache : NSObject

SingletonH(Cache);

- (void)pushToAdCacheWithAdWrappersArray:(nonnull NSArray<ASAdWrapper *> *)adWrappersArr;

- (nullable NSArray<ASAdWrapper *> *)popFromAdCacheWithAdInfo:(nonnull ASAdInfo *)adInfo;

- (nullable NSArray<ASAdWrapper *> *)popFromAdCacheWithAdInfo:(nonnull ASAdInfo *)adInfo supportUseMinCount:(BOOL)supportUseMinCount;

- (BOOL)hasAdCacheWithAdInfo:(nonnull ASAdInfo *)adInfo;

@end

@property (nonatomic, copy, readonly, nonnull) NSString *layerId; 

@property (nonatomic, copy, readonly, nullable) NSString *fullAdId;

@property (nonatomic, copy, readonly, nonnull) NSString *style; 

@property (nonatomic, copy, readonly, nullable) NSString *placementId; 

@property (nonatomic, strong, nonnull) NSMutableSet<NSString *> *excludeKeywordsSetM;

@property (nonatomic, assign, readonly) NSUInteger adPullCount; 

@property (nonatomic, assign, getter=isEditable) BOOL editable;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    //TODO:增加初始化
    return YES;
}

上一篇 下一篇

猜你喜欢

热点阅读