Skip to content

Commit c1f090b

Browse files
committed
Improve MMMTypeName() and make it available for ObjC
1 parent 95cff73 commit c1f090b

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

MMMCommonCore.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
Pod::Spec.new do |s|
77

88
s.name = "MMMCommonCore"
9-
s.version = "1.14.0"
9+
s.version = "1.15.0"
1010
s.summary = "Small bits and pieces reused in many pods from MMMTemple"
1111
s.description = s.summary
1212
s.homepage = "https://github.com/mediamonks/#{s.name}"
@@ -15,9 +15,8 @@ Pod::Spec.new do |s|
1515
s.source = { :git => "https://github.com/mediamonks/#{s.name}.git", :tag => s.version.to_s }
1616

1717
s.ios.deployment_target = '11.0'
18-
s.watchos.deployment_target = '2.0'
18+
s.watchos.deployment_target = '4.0'
1919
s.tvos.deployment_target = '9.0'
20-
s.osx.deployment_target = '10.10'
2120

2221
s.subspec 'ObjC' do |ss|
2322
ss.source_files = [ "Sources/#{s.name}ObjC/*.{h,m}" ]

Sources/MMMCommonCore/CommonCore.swift

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,23 @@ extension NSErrorFriendly {
173173
/// The name of the value's type suitable for logs or NSError domains: without the name of the module
174174
/// and/or private contexts.
175175
public func MMMTypeName(_ value: Any) -> String {
176+
176177
// To avoid "Something.Type" when the type is passed as value.
177178
let name = type(of: value) is AnyClass
178179
? String(reflecting: type(of: value))
179180
: 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: ".")
187193
}
188194

189195
extension NSError {
@@ -357,16 +363,16 @@ public func MMMBestMatchingLanguage(in languages: [String], preferredLanguages:
357363
)
358364
}
359365

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`")
362367
@objc public final class MMMBestMatching: NSObject {
363368

369+
/// See ``MMMBestMatchingLanguage(in:preferredLanguage:mode:)`` for more info.
364370
@objc public class func language(
365371
in languages: [String],
366372
preferredLanguage: String,
367373
mode: LanguageMatchingMode
368374
) -> String? {
369-
return MMMBestMatchingLanguage(in: languages, preferredLanguage: preferredLanguage, mode: mode)
375+
MMMBestMatchingLanguage(in: languages, preferredLanguage: preferredLanguage, mode: mode)
370376
}
371377
}
372378

@@ -429,3 +435,24 @@ extension Sequence {
429435
return result
430436
}
431437
}
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

Comments
 (0)