Skip to content

Commit

Permalink
Move deprecations to a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
yvbeek committed Nov 9, 2018
1 parent 4c4990c commit 1f0cce5
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 123 deletions.
127 changes: 127 additions & 0 deletions Sources/Helpers/Deprecations.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
//
// Deprecations.swift
// Telegraph
//
// Created by Yvo van Beek on 11/9/18.
// Copyright © 2018 Building42. All rights reserved.
//

import Foundation

// MARK: - DateFormatter

public extension DateFormatter {
@available(*, deprecated, message: "use DateFormatter.rfc1123 or Date's rfc1123 variable")
public var rfc7231: DateFormatter {
return .rfc1123
}
}

// MARK: - DispatchTimer

public extension DispatchTimer {
/// Creates and starts a timer that runs after a while, optionally repeating with a specific interval.
@available(*, deprecated, message: "no longer supported, use start(at:) to run the timer at a later time")
static func run(after: TimeInterval, interval: TimeInterval = 0, queue: DispatchQueue, execute block: @escaping () -> Void) -> DispatchTimer {
let timer = DispatchTimer(interval: interval, queue: queue, execute: block)
timer.start(at: Date() + after)
return timer
}

/// (Re)starts the timer, next run will be after the specified interval.
@available(*, deprecated, message: "no longer supported, use start(at:) to run the timer at a later time")
public func start(after: TimeInterval) {
start(at: Date() + after)
}
}

// MARK: - HTTPHeader

@available(*, deprecated, message: "use HTTPHeaderName")
typealias HTTPHeader = HTTPHeaderName

@available(*, deprecated, message: "use Dictionary")
typealias CustomKeyIndexable = Dictionary

// MARK: - HTTPMethod

public extension HTTPMethod {
@available(*, deprecated, message: "use HTTPMethod.GET")
static var get = HTTPMethod.GET

@available(*, deprecated, message: "use HTTPMethod.HEAD")
static var head = HTTPMethod.HEAD

@available(*, deprecated, message: "use HTTPMethod.DELETE")
static var delete = HTTPMethod.DELETE

@available(*, deprecated, message: "use HTTPMethod.OPTIONS")
static var options = HTTPMethod.OPTIONS

@available(*, deprecated, message: "use HTTPMethod.POST")
static var post = HTTPMethod.POST

@available(*, deprecated, message: "use HTTPMethod.PUT")
static var put = HTTPMethod.PUT

@available(*, deprecated, message: "use HTTPMethod(name:)")
init(rawValue: String) {
self.init(name: rawValue.uppercased())
}

@available(*, deprecated, message: "use HTTPMethod(name:)")
static func method(_ name: String) -> HTTPMethod {
return HTTPMethod(name: name)
}
}

// MARK: - HTTPReponse

extension HTTPResponse {
@available(*, deprecated, message: "use DateFormatter.rfc1123 or Date's rfc1123 variable")
public static let dateFormatter = DateFormatter.rfc1123

@available(*, deprecated, message: "data: has been renamed to body:")
public convenience init(_ status: HTTPStatus = .ok, data: Data) {
self.init(status, body: data)
}

@available(*, deprecated, message: "use keepAlive instead, this setter only handles true properly")
public var closeAfterWrite: Bool {
get { return !keepAlive }
set { if newValue { headers.connection = "close" } }
}
}

// MARK: - HTTPVersion

public extension HTTPVersion {
@available(*, deprecated, message: "use HTTPVersion(major:, minor:)")
public init(_ major: UInt, _ minor: UInt) {
self.init(major: major, minor: minor)
}
}

// MARK: - Server

extension Server {
@available(*, deprecated, message: "use start(port:)")
open func start(onPort port: UInt16) throws {
try start(port: Int(port))
}

@available(*, deprecated, message: "use start(port:interface:)")
open func start(onInterface interface: String?, port: UInt16 = 0) throws {
try start(port: Int(port), interface: interface)
}
}

// MARK: - URI

extension URI {
@available(*, deprecated, message: "fragment should not be used, it is only relevant for URLs")
public var fragment: String? {
get { return nil }
set { }
}
}
18 changes: 0 additions & 18 deletions Sources/Helpers/DispatchTimer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,3 @@ private extension DispatchWallTime {
self.init(timespec: wallTime)
}
}

// MARK: Deprecated

public extension DispatchTimer {
/// Creates and starts a timer that runs after a while, optionally repeating with a specific interval.
@available(*, deprecated, message: "no longer supported, use start(at:) to run the timer at a later time")
static func run(after: TimeInterval, interval: TimeInterval = 0, queue: DispatchQueue, execute block: @escaping () -> Void) -> DispatchTimer {
let timer = DispatchTimer(interval: interval, queue: queue, execute: block)
timer.start(at: Date() + after)
return timer
}

/// (Re)starts the timer, next run will be after the specified interval.
@available(*, deprecated, message: "no longer supported, use start(at:) to run the timer at a later time")
public func start(after: TimeInterval) {
start(at: Date() + after)
}
}
9 changes: 0 additions & 9 deletions Sources/Helpers/RFC1123.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,3 @@ public extension Date {
return RFC1123.formatter.string(from: self)
}
}

// MARK: Deprecated

public extension DateFormatter {
@available(*, deprecated, message: "use DateFormatter.rfc1123 or Date's rfc1123 variable")
public var rfc7231: DateFormatter {
return .rfc1123
}
}
13 changes: 0 additions & 13 deletions Sources/Protocols/HTTP/Models/HTTPHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,3 @@ extension Dictionary where Key == HTTPHeaderName, Value == String {
set { self[.upgrade] = newValue }
}
}

// MARK: Deprecated

@available(*, deprecated, message: "use HTTPHeaderName")
typealias HTTPHeader = HTTPHeaderName

@available(*, deprecated, message: "use Dictionary")
typealias CustomKeyIndexable = Dictionary

public extension HTTPHeaderName {
@available(*, deprecated, message: "no longer available, test manually that name starts with x-")
public var isCustom: Bool { return name.hasPrefix("x-") }
}
32 changes: 0 additions & 32 deletions Sources/Protocols/HTTP/Models/HTTPMethod.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,35 +36,3 @@ extension HTTPMethod: ExpressibleByStringLiteral {
self.init(name: string)
}
}

// MARK: Deprecated

public extension HTTPMethod {
@available(*, deprecated, message: "use HTTPMethod.GET")
static var get = HTTPMethod.GET

@available(*, deprecated, message: "use HTTPMethod.HEAD")
static var head = HTTPMethod.HEAD

@available(*, deprecated, message: "use HTTPMethod.DELETE")
static var delete = HTTPMethod.DELETE

@available(*, deprecated, message: "use HTTPMethod.OPTIONS")
static var options = HTTPMethod.OPTIONS

@available(*, deprecated, message: "use HTTPMethod.POST")
static var post = HTTPMethod.POST

@available(*, deprecated, message: "use HTTPMethod.PUT")
static var put = HTTPMethod.PUT

@available(*, deprecated, message: "use HTTPMethod(name:)")
init(rawValue: String) {
self.init(name: rawValue.uppercased())
}

@available(*, deprecated, message: "use HTTPMethod(name:)")
static func method(_ name: String) -> HTTPMethod {
return HTTPMethod(name: name)
}
}
18 changes: 0 additions & 18 deletions Sources/Protocols/HTTP/Models/HTTPResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,3 @@ extension HTTPResponse: CustomStringConvertible {
return "<\(typeName): \(version) \(status), headers: \(headers.count), body: \(body.count)>"
}
}

// MARK: Deprecated

extension HTTPResponse {
@available(*, deprecated, message: "use DateFormatter.rfc1123 or Date's rfc1123 variable")
public static let dateFormatter = DateFormatter.rfc1123

@available(*, deprecated, message: "data: has been renamed to body:")
public convenience init(_ status: HTTPStatus = .ok, data: Data) {
self.init(status, body: data)
}

@available(*, deprecated, message: "use keepAlive instead, this setter only handles true properly")
public var closeAfterWrite: Bool {
get { return !keepAlive }
set { if newValue { headers.connection = "close" } }
}
}
9 changes: 0 additions & 9 deletions Sources/Protocols/HTTP/Models/HTTPVersion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,3 @@ extension HTTPVersion: CustomStringConvertible {
return "HTTP/\(major).\(minor)"
}
}

// MARK: Deprecated

public extension HTTPVersion {
@available(*, deprecated, message: "use HTTPVersion(major:, minor:)")
public init(_ major: UInt, _ minor: UInt) {
self.init(major: major, minor: minor)
}
}
14 changes: 0 additions & 14 deletions Sources/Server/Server.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,17 +237,3 @@ extension Server: WebSocketConnectionDelegate {
}
}
}

// MARK: Deprecated

extension Server {
@available(*, deprecated, message: "use start(port:)")
open func start(onPort port: UInt16) throws {
try start(port: Int(port))
}

@available(*, deprecated, message: "use start(port:interface:)")
open func start(onInterface interface: String?, port: UInt16 = 0) throws {
try start(port: Int(port), interface: interface)
}
}
10 changes: 0 additions & 10 deletions Sources/Transport/URI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,3 @@ extension URI: CustomStringConvertible {
return components.description
}
}

// MARK: Deprecated

extension URI {
@available(*, deprecated, message: "fragment should not be used, it is only relevant for URLs")
public var fragment: String? {
get { return components.fragment }
set { components.fragment = newValue }
}
}
8 changes: 8 additions & 0 deletions Telegraph.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@
82D2AF04210D354600BF5BBA /* DataStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82D2AF03210D354600BF5BBA /* DataStream.swift */; };
82D2AF05210D354600BF5BBA /* DataStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82D2AF03210D354600BF5BBA /* DataStream.swift */; };
82D2AF06210D354600BF5BBA /* DataStream.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82D2AF03210D354600BF5BBA /* DataStream.swift */; };
82FB49BE2195BBFB00C4E574 /* Deprecations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82FB49BD2195BBFB00C4E574 /* Deprecations.swift */; };
82FB49BF2195BBFB00C4E574 /* Deprecations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82FB49BD2195BBFB00C4E574 /* Deprecations.swift */; };
82FB49C02195BBFB00C4E574 /* Deprecations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82FB49BD2195BBFB00C4E574 /* Deprecations.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -316,6 +319,7 @@
8284FF1C1ECE8C8E00303A00 /* HTTPFileHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = HTTPFileHandler.swift; sourceTree = "<group>"; };
82897602217402B60089D662 /* Endpoint.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Endpoint.swift; sourceTree = "<group>"; };
82D2AF03210D354600BF5BBA /* DataStream.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DataStream.swift; sourceTree = "<group>"; };
82FB49BD2195BBFB00C4E574 /* Deprecations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deprecations.swift; sourceTree = "<group>"; };
D9899DD31DF4A092008766B5 /* Telegraph Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Telegraph Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -613,6 +617,7 @@
isa = PBXGroup;
children = (
825A71C91ECD2E890043AC8D /* Extensions */,
82FB49BD2195BBFB00C4E574 /* Deprecations.swift */,
825A71CF1ECD2E890043AC8D /* DispatchTimer.swift */,
821FD9F0216BE58E00D0F486 /* RFC1123.swift */,
820EA1D920F9662F00CCCF6C /* SynchronizedSet.swift */,
Expand Down Expand Up @@ -990,6 +995,7 @@
825A72841ECD2E890043AC8D /* WebSocket.swift in Sources */,
821FD9F1216BE58E00D0F486 /* RFC1123.swift in Sources */,
825A72661ECD2E890043AC8D /* HTTPRoute.swift in Sources */,
82FB49BE2195BBFB00C4E574 /* Deprecations.swift in Sources */,
825A724B1ECD2E890043AC8D /* HTTPHeader.swift in Sources */,
825A72931ECD2E890043AC8D /* WebSocketMessage.swift in Sources */,
8280B07B2170383400BE42C3 /* WebSocketClientError.swift in Sources */,
Expand Down Expand Up @@ -1061,6 +1067,7 @@
825A72851ECD2E890043AC8D /* WebSocket.swift in Sources */,
821FD9F2216BE58E00D0F486 /* RFC1123.swift in Sources */,
825A72671ECD2E890043AC8D /* HTTPRoute.swift in Sources */,
82FB49BF2195BBFB00C4E574 /* Deprecations.swift in Sources */,
825A724C1ECD2E890043AC8D /* HTTPHeader.swift in Sources */,
825A72941ECD2E890043AC8D /* WebSocketMessage.swift in Sources */,
8280B07C2170383400BE42C3 /* WebSocketClientError.swift in Sources */,
Expand Down Expand Up @@ -1132,6 +1139,7 @@
825A72861ECD2E890043AC8D /* WebSocket.swift in Sources */,
821FD9F3216BE58E00D0F486 /* RFC1123.swift in Sources */,
825A72681ECD2E890043AC8D /* HTTPRoute.swift in Sources */,
82FB49C02195BBFB00C4E574 /* Deprecations.swift in Sources */,
825A724D1ECD2E890043AC8D /* HTTPHeader.swift in Sources */,
825A72951ECD2E890043AC8D /* WebSocketMessage.swift in Sources */,
8280B07D2170383400BE42C3 /* WebSocketClientError.swift in Sources */,
Expand Down

0 comments on commit 1f0cce5

Please sign in to comment.