From a2b637e8613b74215fb364e34a01ae20e3e98898 Mon Sep 17 00:00:00 2001 From: Stefan Fochler Date: Tue, 30 Oct 2018 12:32:53 +0100 Subject: [PATCH] =?UTF-8?q?Fix=20String+UniqueByIncrementing=E2=80=99s=20o?= =?UTF-8?q?bjc=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Strings/String+UniqueByIncrementing.swift | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/BXSwiftUtils/Strings/String+UniqueByIncrementing.swift b/BXSwiftUtils/Strings/String+UniqueByIncrementing.swift index e224319..896edff 100644 --- a/BXSwiftUtils/Strings/String+UniqueByIncrementing.swift +++ b/BXSwiftUtils/Strings/String+UniqueByIncrementing.swift @@ -75,7 +75,7 @@ extension String return composedString }) - .first(where: { !rejector($0)})! + .first(where: { !rejector($0) })! } /** @@ -118,15 +118,18 @@ extension String } } + +// The Objective C Methods are prefixed with objc_ to avoid an infitite recursion when calling the equally named swift +// method. Although this can be prevented by correctly converting all parameter types, it's super easy to miss... extension NSString { - @objc public func uniqueStringByIncrementing(rejectIf rejector: (_ suggestion: NSString) -> Bool, appendAnnotation: NSString? = nil, separator: NSString = " ") -> NSString + @objc public func objc_uniqueStringByIncrementing(rejectIf rejector: (_ suggestion: NSString) -> Bool, appendAnnotation: NSString? = nil, separator: NSString = " ") -> NSString { - return (self as String).uniqueStringByIncrementing(rejectIf: rejector, appendAnnotation: appendAnnotation, separator: separator) as NSString + return (self as String).uniqueStringByIncrementing(rejectIf: { rejector($0 as NSString) }, appendAnnotation: appendAnnotation as String?, separator: separator as String) as NSString } - @objc public func uniqueFilenameByIncrementing(rejectIf rejector: (_ suggestion: NSString) -> Bool, appendAnnotation: NSString? = nil, separator: NSString = " ") -> NSString + @objc public func objc_uniqueFilenameByIncrementing(rejectIf rejector: (_ suggestion: NSString) -> Bool, appendAnnotation: NSString? = nil, separator: NSString = " ") -> NSString { - return (self as String).uniqueFilenameByIncrementing(rejectIf: rejector, appendAnnotation: appendAnnotation, separator: separator) as NSString + return (self as String).uniqueFilenameByIncrementing(rejectIf: { rejector($0 as NSString) }, appendAnnotation: appendAnnotation as String?, separator: separator as String) as NSString } }