user5273262
user5273262

Reputation:

.swift file name containing plus sign

I opened an XCode project produced as a tutorial by Apple ("Auto Layout Cookbook"), when I found two files with a strange naming:

  1. Recipe+Loading.swift
  2. Recipe+Storyboards.swift

Both contain an extension called Recipe. I was not able to find any docs about this kind of naming.

Is there any reason why they named the files this way?

Upvotes: 7

Views: 3547

Answers (2)

Sulthan
Sulthan

Reputation: 130172

The naming comes from Objective-C where every extension for a class needed a name. For example, a class Recipe could have extension:

@interface Recipe (Loading)
@end

which contained methods related to "Loading". Such extensions were commonly put into files named Recipe+Loading.h (that is, class Recipe extended with Loading methods).

In Swift extensions don't have a name but old habits die hard. They used the same naming for files.

Upvotes: 10

David Berry
David Berry

Reputation: 41246

This is a common naming convention from Objective-C. As you surmised it basically contains extensions to Recipe that pertain to loading and storyboards respectively. It's primarily a way to break up large source files or label extensions to system classes (String, Array, etc.)

Upvotes: 0

Related Questions