This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
let searchTerm = "Lorem" | |
let targetString = "Lorem Ipsum is ... 😀" | |
let expectedResult = "L̲o̲r̲e̲m̲ Ipsum is ... 😀" | |
let attributedString = NSMutableAttributedString.generateAttributedString(with: searchTerm, targetString: targetString) | |
// Convert attributed string to Unicode text. | |
let mockUnderlineUnicodeText = generateUnderlineUnicodeText(from: attributedString!, by: NSAttributedString.Key.font) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func generateUnderlineUnicodeText(from attributedString: NSAttributedString, by key: NSAttributedString.Key) -> String { | |
var keyRanges = [NSRange]() | |
// Find all attributes by difference (key) and take ranges | |
attributedString.enumerateAttributes(in: NSRange(location: 0, length: attributedString.length)) { (attributes, range, _) in | |
attributes.forEach { (key, value) in | |
switch key { | |
case key: keyRanges.append(range) | |
default: print("Unknown attribute found in the attributed string")} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension NSMutableAttributedString { | |
static func generateAttributedString(with searchTerm: String, targetString: String) -> NSMutableAttributedString? { | |
let attributedString = NSMutableAttributedString(string: targetString) | |
do { | |
// Your more complicated expressions here | |
let regex = try NSRegularExpression(pattern: searchTerm, options: .caseInsensitive) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
init<S: Sequence>(unicodeScalars ucs: S) where S.Iterator.Element == UnicodeScalar { | |
var s = "" | |
s.unicodeScalars.append(contentsOf: ucs) | |
self = s | |
} | |
var underlineUnicode: String? { | |
let underlineUnicode: UInt32 = 818 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let startTime = CFAbsoluteTimeGetCurrent() | |
// to do smth | |
let endTime = CFAbsoluteTimeGetCurrent() | |
let elapsedTime = (endTime - startTime) * 1000 | |
print("It took \(elapsedTime) ms") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SourceEditorCommand: NSObject, XCSourceEditorCommand { | |
func perform(with invocation: XCSourceEditorCommandInvocation, completionHandler: @escaping (Error?) -> Swift.Void ) { | |
... | |
} | |
func handle(range: XCSourceTextRange, inBuffer buffer: XCSourceTextBuffer) -> () { | |
... | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public extension String { | |
func camelize() -> String { | |
let source = removeFirstSpaces(clean(with: " ", allOf: "-", "_", ".")) | |
if source.characters.contains(" ") { | |
let first = source[self.startIndex...self.index(after: startIndex)].lowercased() | |
let cammel = source.capitalized.replacingOccurrences(of: " ", with: "") | |
let rest = String(cammel.characters.dropFirst()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
let isPhone = UIDevice.current.userInterfaceIdiom == .phone ? true : false | |
... | |
class RootRouter { | |
var panelScreen : PanelModuleInput? | |
func setupRouter(window: UIWindow) { | |
panelScreen = PanelAssembly.createModule() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PanelAssembly { | |
class func createModule() -> PanelModuleInput { | |
let presenter = PanelPresenter() | |
let interactorMidi = PanelInteractorMidi() | |
let interactorInstrument = PanelInteractorInstrument() | |
let router = PanelRouter() | |
let soundManager = SoundManager() | |