说明:源代码文件内,Ojbective-C++代码遵循你正在实现的函数/方法的风格。为了最小化Cocoa/Objective-C与C++之间命名风格的冲突,根据待实现的
函数/方法选 择编码风格。实现@implementation语句块时,使用Objective-C的命名规则;如果实现一个C++
iOS编程规范v1.0
.h
C/C++/Objective-C的头
文件
.m
Ojbective-C实现文件
.mm
Ojbective-C++的实现文
件
.cc
纯C++的实现文件
.c
纯C的实现文件
的类,就使用C++命名规则。 示例:// file: cross_platform_header.hclass CrossPlatformAPI { public:
…
int DoSomethingPlatformSpecific(); private:
int an_instance_var_;
};
// file: mac_implementation.mm
// impl on each platform
#include “cross_platform_header.h”
// A typical Objective-C class, using Objective-C naming. @interface
MyDelegate : NSObject {
@privateint instanceVar_; CrossPlatformAPI* backEndObject_;
}-(void)respondToSomething:(id)something;@end@implementation
MyDelegate- (void)respondToSomething:(id)something {
// bridge from Cocoa through our C++ backendinstanceVar_ =
backEndObject->DoSomethingPlatformSpecific(); NSString* tempString =
[NSString stringWithInt:instanceVar_]; NSLog(@”%@”, tempString);
} @end
// The platform-specific implementation of the C++ class, using // C++ naming.int
CrossPlatformAPI::DoSomethingPlatformSpecific() {
NSString* temp_string = [NSString stringWithInt:an_instance_var_];
NSLog(@”%@”, temp_string);return [temp_string intValue];
}