@@ -173,17 +173,23 @@ extension NSErrorFriendly {
173
173
/// The name of the value's type suitable for logs or NSError domains: without the name of the module
174
174
/// and/or private contexts.
175
175
public func MMMTypeName( _ value: Any ) -> String {
176
+
176
177
// To avoid "Something.Type" when the type is passed as value.
177
178
let name = type ( of: value) is AnyClass
178
179
? String ( reflecting: type ( of: value) )
179
180
: String ( reflecting: value)
180
- return name
181
- . split ( separator: " . " )
182
- // Skip "(unknown context at $...)" added for private types.
183
- . filter { !( $0. hasPrefix ( " ( " ) && $0. hasSuffix ( " ) " ) ) }
184
- // Ignore module names as it's the main module most of the time.
185
- . dropFirst ( )
186
- . joined ( separator: " . " )
181
+
182
+ var components = name. split ( separator: " . " )
183
+
184
+ // Skip "(unknown context at $...)" added for private types.
185
+ components = components. filter { !( $0. hasPrefix ( " ( " ) && $0. hasSuffix ( " ) " ) ) }
186
+
187
+ // Ignore module names, if any, as it's the main module most of the time.
188
+ if components. count > 1 {
189
+ components. removeFirst ( )
190
+ }
191
+
192
+ return components. joined ( separator: " . " )
187
193
}
188
194
189
195
extension NSError {
@@ -357,16 +363,16 @@ public func MMMBestMatchingLanguage(in languages: [String], preferredLanguages:
357
363
)
358
364
}
359
365
360
- /// Objective-C bridge for MMMBestMatchingLanguage, since top-level functions are not supported.
361
- /// Look at ``MMMBestMatchingLanguage(in:preferredLanguage:mode:)`` for more info.
366
+ @available ( * , deprecated, message: " Use the corresponding function in `MMMCommonCoreHelpers` " )
362
367
@objc public final class MMMBestMatching : NSObject {
363
368
369
+ /// See ``MMMBestMatchingLanguage(in:preferredLanguage:mode:)`` for more info.
364
370
@objc public class func language(
365
371
in languages: [ String ] ,
366
372
preferredLanguage: String ,
367
373
mode: LanguageMatchingMode
368
374
) -> String ? {
369
- return MMMBestMatchingLanguage ( in: languages, preferredLanguage: preferredLanguage, mode: mode)
375
+ MMMBestMatchingLanguage ( in: languages, preferredLanguage: preferredLanguage, mode: mode)
370
376
}
371
377
}
372
378
@@ -429,3 +435,24 @@ extension Sequence {
429
435
return result
430
436
}
431
437
}
438
+
439
+ // MARK: -
440
+
441
+ /// This is to expose some of the functions back to ObjC.
442
+ @objc public class MMMCommonCoreHelpers : NSObject {
443
+
444
+ /// Obj-C alias for ``MMMTypeName``.
445
+ @objc public static func typeName( _ value: Any ) -> String {
446
+ MMMTypeName ( value)
447
+ }
448
+
449
+ /// Obj-C alias for ``MMMBestMatchingLanguage(in:preferredLanguage:mode:)``.
450
+ @objc public class func language(
451
+ in languages: [ String ] ,
452
+ preferredLanguage: String ,
453
+ mode: LanguageMatchingMode
454
+ ) -> String ? {
455
+ MMMBestMatchingLanguage ( in: languages, preferredLanguage: preferredLanguage, mode: mode)
456
+ }
457
+ }
458
+
0 commit comments