Repository: vapor/vapor
File: Sources/Vapor/HTTP/Headers/HTTPHeaders+ContentRange.swift (Swift)

Code before:
            if contains(name: .contentRange) {
                remove(name: .contentRange)
            }
            if newValue == nil {
                return
            }
            add(name: .contentRange, value: newValue!.serialize())
        }
    }
    
    /// Convenience for accessing the `Range` request header.
    ///
    /// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
    public var range: Range? {
        get {
            return HTTPHeaders.Range(directives: self.parseDirectives(name: .range).flatMap { $0 })
        }
        set {
            if contains(name: .range) {
                remove(name: .range)
            }
            if newValue == nil {
                return
            }
            add(name: .range, value: newValue!.serialize())
        }
    }
}

extension HTTPHeaders.Range {
    /// Represents one value of the `Range` request header.
    ///
    /// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
    public enum Value: Equatable {
        ///Integer with single trailing dash, e.g. `25-`
        case start(value: Int)
        ///Integer with single leading dash, e.g. `-25`
        case tail(value: Int)
        ///Two integers with single dash in between, e.g. `20-25`
        case within(start: Int, end: Int)
        
        ///Parses a string representing a requested range in one of the following formats:
        ///
        ///- `<range-start>-<range-end>`
        ///- `-<range-end>`
        ///- `<range-start>-`
        ///
        /// - parameters:
        ///     - requestStr: String representing a requested range
        /// - returns: A `HTTPHeaders.Range.Value` if the `requestStr` is valid, `nil` otherwise.
        public static func from<T>(requestStr: T) -> HTTPHeaders.Range.Value? where T: StringProtocol {

Review comment (suggestion):
- Add a couple of selfs to be in compliance with the style guide
- use guard to avoid force unwrap
```suggestion
        get {
            return HTTPHeaders.Range(directives: self.parseDirectives(name: .range).flatMap { $0 })
        }
        set {
            if self.contains(name: .range) {
                self.remove(name: .range)
            }
            guard let newValue == newValue else {
                return
            }
            self.add(name: .range, value: newValue.serialize())
        }
```

Code after:
                self.remove(name: .contentRange)
            }
            guard let newValue = newValue else {
                return
            }
            self.add(name: .contentRange, value: newValue.serialize())
        }
    }
    
    /// Convenience for accessing the `Range` request header.
    ///
    /// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
    public var range: Range? {
        get {
            return HTTPHeaders.Range(directives: self.parseDirectives(name: .range).flatMap { $0 })
        }
        set {
            if self.contains(name: .range) {
                self.remove(name: .range)
            }
            guard let newValue = newValue else {
                return
            }
            self.add(name: .range, value: newValue.serialize())
        }
    }
}

extension HTTPHeaders.Range {
    /// Represents one value of the `Range` request header.
    ///
    /// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Range
    public enum Value: Equatable {
        ///Integer with single trailing dash, e.g. `25-`
        case start(value: Int)
        ///Integer with single leading dash, e.g. `-25`
        case tail(value: Int)
        ///Two integers with single dash in between, e.g. `20-25`
        case within(start: Int, end: Int)
        
        ///Parses a string representing a requested range in one of the following formats:
        ///
        ///- `<range-start>-<range-end>`
        ///- `-<range-end>`
        ///- `<range-start>-`
        ///
        /// - parameters:
        ///     - requestStr: String representing a requested range
        /// - returns: A `HTTPHeaders.Range.Value` if the `requestStr` is valid, `nil` otherwise.
        public static func from<T>(requestStr: T) -> HTTPHeaders.Range.Value? where T: StringProtocol {
            let ranges = requestStr.split(separator: "-", omittingEmptySubsequences: false)