From 6f7fc5c4f52afb65ce15be45a46e84b6c7b9913e Mon Sep 17 00:00:00 2001 From: Gil Date: Wed, 23 May 2018 13:11:20 -0700 Subject: Fix Objective-C logging (#1322) --- .../src/firebase/firestore/util/string_format.h | 37 ++++++++++++++++++---- 1 file changed, 31 insertions(+), 6 deletions(-) (limited to 'Firestore/core/src/firebase') diff --git a/Firestore/core/src/firebase/firestore/util/string_format.h b/Firestore/core/src/firebase/firestore/util/string_format.h index f8da785..d691984 100644 --- a/Firestore/core/src/firebase/firestore/util/string_format.h +++ b/Firestore/core/src/firebase/firestore/util/string_format.h @@ -67,12 +67,6 @@ class FormatArg : public absl::AlphaNum { : FormatArg{std::forward(value), internal::FormatChoice<0>{}} { } -#if __OBJC__ - FormatArg(NSObject* object) // NOLINT(runtime/explicit) - : AlphaNum{MakeStringView([object description])} { - } -#endif - private: /** * Creates a FormatArg from a boolean value, representing the string @@ -87,6 +81,37 @@ class FormatArg : public absl::AlphaNum { : AlphaNum{bool_value ? "true" : "false"} { } +#if __OBJC__ + /** + * Creates a FormatArg from any pointer to an object derived from NSObject. + */ + template < + typename T, + typename = typename std::enable_if{}>::type> + FormatArg(T* object, internal::FormatChoice<0>) + : AlphaNum{MakeStringView([object description])} { + } + + /** + * Creates a FormatArg from any Objective-C Class type. Objective-C Class + * types are a special struct that aren't of a type derived from NSObject. + */ + FormatArg(Class object, internal::FormatChoice<0>) + : AlphaNum{MakeStringView(NSStringFromClass(object))} { + } + + /** + * Creates a FormatArg from any id pointer. Note that instances of `id` + * (which means "pointer conforming to the protocol Foo") do not match this + * without first casting to type `id`. There's no way to express a template of + * `id` since `id` isn't actually a C++ template and `id` isn't a + * parameterized C++ class. + */ + FormatArg(id object, internal::FormatChoice<0>) + : AlphaNum{MakeStringView([object description])} { + } +#endif + /** * Creates a FormatArg from a character string literal. This is * handled specially to avoid ambiguity with generic pointers, which are -- cgit v1.2.3