Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MainMenu.xib を翻訳してみた

MainMenu.xib を翻訳してみた

Swift 愛好会 2022/4/25

Megabits_mzq

April 25, 2022
Tweet

More Decks by Megabits_mzq

Other Decks in Programming

Transcript

  1. 前回の続き WKWebView のめんどくさいお友達がまた増えた! let script2 = """ class NotificationOverride {

    static get permission() { window.webkit.messageHandlers.notifyRequest.postMessage(true); return "granted"; } static requestPermission (callback) { callback("granted"); window.webkit.messageHandlers.notifyRequest.postMessage(true); } constructor (title, options) { window.webkit.messageHandlers.notify.postMessage({ title: title, body: options.body }); } } window.Notification = NotificationOverride; """ let userScript2 = WKUserScript(source: script2, injectionTime: .atDocumentStart, forMainFrameOnly: true) webView.configuration.userContentController.addUserScript(userScript2) webView.configuration.userContentController.add(self, name: "notify") webView.configuration.userContentController.add(self, name: "notifyRequest")
  2. extension UInt8 { var printableAscii : String { switch self

    { case 32..<128: return String(bytes: [self], encoding:.ascii)! default: if String(bytes: [(self & 127)], encoding:.ascii)! == "b" { return "…" } else { return "/" } } } }   func XibKeysFrom(stringArray: [String]) -> [XibKey]? { var keyArray = [String : String]() var count = stringArray.count while count > 1 { let item = stringArray[stringArray.count - count] if item.hasSuffix(".title") { let source = stringArray[stringArray.count - count + 1] if !source.hasSuffix(".title") { count -= 1 keyArray[item] = source } } count -= 1 } if keyArray.isEmpty { return nil } return keyArray.map({XibKey(key: $0.key, source: $0.value)}) }