Battman User Manual
Codes

Contributing Code

We welcome code contributions to Battman.

Before you start

Project Structure

Battman is written in Objective-C and C (no Swift). The main codebase is organized as follows:

Directory Layout

File Naming Conventions

Code Style Guidelines

Language and Architecture

Why No Xcode Assets and Storyboards?

Battman does not use Xcode Assets (.xcassets) or Storyboards/XIBs for the following reasons:

Why No Third-Party Dependencies?

Battman intentionally avoids third-party dependencies (CocoaPods, Swift Packages, external frameworks) for the following reasons:

If you need functionality that would typically come from a third-party library, please implement it directly in the codebase or adapt the necessary code to fit Battman's architecture (For example, we have completely rewritten Swift UberSegmentedControl in Objective-C).

Why No Swift Code?

Battman uses Objective-C and C exclusively, and does not accept Swift code submissions for the following reasons:

If you must use Swift, your Swift code must meet these requirements: - Your Swift code should have been compiled and tested on iOS 12 or earlier. - Your Swift code should be written in Swift 4 or older. - Your Swift code should at least be buildable with Procursus' Swift toolchain on iOS.

C / Objective-C Patterns

Singleton Pattern

+ (instancetype)sharedPrefs {
    static BattmanPrefs *shared = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        shared = [[self alloc] _init];
    });
    return shared;
}

iOS Version Checks

if (@available(iOS 13.0, *)) {
    // iOS 13+ code
} else {
    // Fallback code
}
if (__builtin_available(iOS 13.0, *)) {
    // iOS 13+ code
} else {
    // Fallback code
}

Debug Logging

// DBGLOG is based on NSLog()
DBGLOG(CFSTR("Debug message: %@"), value);
// DBGLOG is based on NSLog()
DBGLOG(@"Debug message: %@", value);

Localization

// For NSString
NSString *localized = _("String to localize");

// For C strings
const char *localized = _C("String to localize");

Static Initialization

static dispatch_once_t onceToken;
static bool value;

dispatch_once(&onceToken, ^{
    // One-time initialization
    value = compute_value();
});

Error Handling

Memory Management

Build System

Battman can be built with: - Xcode: Standard Xcode project - Makefile: Located in Battman/Makefile, supports Linux builds

Key build flags: - -fobjc-arc: Automatic Reference Counting - -target arm64-apple-ios12.0: iOS 12+ deployment target - -DDEBUG: Debug builds - -DUSE_GETTEXT: Optional gettext localization support

Typical workflow

  1. Fork the repository and create a feature branch.
  2. Make your changes with clear, focused commits.
  3. Prefer small, reviewable pull requests rather than large, mixed ones.
  4. Test on as many relevant iOS versions / devices as you can.
  5. Open a pull request and describe:
  6. What you changed.
  7. How you tested it.
  8. Any user‑visible behavior differences.

Code Review Guidelines

Please avoid introducing private information (such as personal certificates or keys) into the repository or build scripts.