Trace: • Objective-C Style
Table of Contents
All of our Objective-C classes use a standardized style.
Protocols
We use the following style for protocols:
- ProtocolTemplate
/* * Copyright 2018 SIB Visions GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * * History * * dd.MM.yyyy - [XX] - creation */ /*! @protocol Foo @abstract Protocol implemented by Bar. @discussion That's what they do. */ @protocol Foo #pragma mark - #pragma mark Required /*! @method requiredMethod: @abstract Validates the specified item. @param pItem The item to be validated. */ - (void)requiredMethod:(id) pItem; /*! @method anotherRequiredMethod: @abstract Applies validation rules. */ - (void)anotherRequiredMethod; #pragma mark - #pragma mark Optional @optional /*! @method anOptionalMethod: @abstract Checks optional things. */ - (void)anOptionalMethod; /*! @method anotherOptionalMethod: @abstract Checks another optional things. */ - (void)anotherOptionalMethod; @end
The following rules are defined by this template:
- First, all required methods are defined
- Then all optional methods
- Grouping using the #pragma mark …
- Important changes are documented in the header, including time stamp and author
- Documentation for the protocol declaration and all methods
Interfaces
We use the following style for interfaces (.h files):
- InterfaceTemplate
/* * Copyright 2018 SIB Visions GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * * History * * dd.MM.yyyy - [XX] - creation */ #import "Bar.h" /*! @class Foo @abstract Foo provides a UI element. @discussion A Foo object is a simple view that can do two things: Jump, Run. */ @interface Foo : Bar { #pragma mark - #pragma mark Instance variable declarations @private /*! @var value the value of foo. */ float value; } #pragma mark - #pragma mark Property declarations /*! @property value the value property. */ @property float value; #pragma mark - #pragma mark Initialization /*! @method initWithString: @abstract Creates a new foo with string representation of width and height. @param pString the width and height @result a new Foo instance. */ - (id)initWithString:(NSString *)pString; #pragma mark - #pragma mark Method declarations /*! @method concatWidth:height: @abstract Concatenates the width and height. @param pWidth the width. @param pHeight the height. @result the string representation. */ + (NSString *)concatWidth:(float)pWidth height:(float):pHeight; /*! @method setWidth:height: @abstract Sets the foo width and height. @param pWidth the width. @param pHeight the height. */ - (void)setWidth:(float)pWidth height:(float)pHeight; @end
The following rules are defined by this template:
- Grouping using the #pragma mark …
- Important changes are documented in the header, including time stamp and author
- Documentation for the class declaration, ALL methods, properties and variables
Classes
We use the following style for classes (.m files):
- ClassTemplate
/* * Copyright 2018 SIB Visions GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * * History * * dd.MM.yyyy - [XX] - creation */ #import "Foo.h"; @implementation Foo #pragma mark - #pragma mark Properties @synthesize value; #pragma mark - #pragma mark Initialization - (id)initWithString:(NSString *)pString { ... } #pragma mark - #pragma mark Method declarations + (NSString *)concatWidth:(float)pWidth height:(float):pHeight { ... } - (void)setWidth:(float)pWidth height:(float)pHeight { ... } @end
The following rules are defined by this template:
- Grouping using the #pragma mark …
- Important changes are documented in the header, including time stamp and author
Unit Tests
OCUnit is used as the testing framework.
We use the following style for unit tests:
- TestTemplate
/* * Copyright 2018 SIB Visions GmbH * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. * * * History * * dd.MM.yyyy - [XX] - creation */ #import "Foo.h" @implementation FooTest #pragma mark - #pragma mark Internal methods #pragma mark - #pragma mark Test methods /*! @abstract Tests the init method. */ - (void)testInit { ... } @end
The following rules are defined by this template:
- Grouping using the #pragma mark …
- Each test class ends with “Test”
- Each test method starts with “test”
- Important changes are documented in the header, including time stamp and author
- Documentation for the class declaration and all test methods