It’s possible to add extensions to existing Swift object types using extensions, as described in the language specification.
As a result, it’s possible to create extensions such as:
extension String {
var utf8data:NSData {
return self.dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)!
}
}
However, what’s the best naming practice for Swift source files containing such extensions?
In the past, the convention was to use extendedtype+categoryname.m
for the Objective-C
type as discussed in the Objective-C guide. But the Swift example doesn’t have a category name, and calling it String.swift
doesn’t seem appropriate.
So the question is: given the above String
extension, what should the swift source file be called?