Skip to content

Code style (objc)

Thilo Molitor edited this page Sep 7, 2024 · 2 revisions

Tabs vs. Spaces

We currently use 4 spaces. Trailing whitespaces should be avoided.

if/else

if()
{
}
else if()
{
}
else
{
}

Switch

switch()
{
    case 0:
        break;
    case 1:
        break;
    default:
        unreachable(); // if the default case should never occur - MLConstants.h
}

Vars (camelCase)

Type* varName;

Defines (UPPER_CASE)

#define SHORT_PING 16.0

Functions

Use proper sounding names (should sound like a sentence with a lot of and and some with or having. To rename functions for swift export, use NS_SWIFT_NAME

-(NSNumber*) functionNameWithName1:(ParamType1) varName1 andName2:(ParamTypeWithPtr*) varName2
{
}

//this would be named isContactBlacklisted(forEncryption:) in Swift-land if we did not use NS_SWIFT_NAME to rename it
+(BOOL) isContactBlacklistedForEncryption:(MLContact*) contact NS_SWIFT_NAME(isContactBlacklistedForEncryption(_:));

Translations

NSLocalizedString(@"Some text that should be translated", @"a note for our translators");