Browse Source

Add the free methods `initialize`, `shutdown`, `version` and `gStandsFor` as static members to a `gRPC` class, to avoid namespace collision.

I figured this might help avoid confusion what a call to e.g. `initialize()` stands for, but YMMV. Feel free to reject if you think this is not a good idea.
Daniel Alm 7 years ago
parent
commit
749ceb8ae7
1 changed files with 26 additions and 22 deletions
  1. 26 22
      Sources/gRPC/gRPC.swift

+ 26 - 22
Sources/gRPC/gRPC.swift

@@ -18,28 +18,32 @@
 #endif
 import Foundation // for String.Encoding
 
-/// Initializes gRPC system
-public func initialize() {
-  grpc_init()
-}
-
-/// Shuts down gRPC system
-public func shutdown() {
-  grpc_shutdown()
-}
-
-/// Returns version of underlying gRPC library
-///
-/// Returns: gRPC version string
-public func version() -> String {
-  return String(cString: grpc_version_string(), encoding: String.Encoding.utf8)!
-}
-
-/// Returns name associated with gRPC version
-///
-/// Returns: gRPC version name
-public func gStandsFor() -> String {
-  return String(cString: grpc_g_stands_for(), encoding: String.Encoding.utf8)!
+public final class gRPC {
+  private init() { }  // Static members only.
+  
+  /// Initializes gRPC system
+  public static func initialize() {
+    grpc_init()
+  }
+  
+  /// Shuts down gRPC system
+  public static func shutdown() {
+    grpc_shutdown()
+  }
+  
+  /// Returns version of underlying gRPC library
+  ///
+  /// Returns: gRPC version string
+  public static var version: String {
+    return String(cString: grpc_version_string(), encoding: String.Encoding.utf8)!
+  }
+  
+  /// Returns name associated with gRPC version
+  ///
+  /// Returns: gRPC version name
+  public static var gStandsFor: String {
+    return String(cString: grpc_g_stands_for(), encoding: String.Encoding.utf8)!
+  }
 }
 
 /// Status codes for gRPC operations (replicated from status_code_enum.h)