OSDN Git Service

不要となっていたプロパティを削除
[kcd/KCD.git] / KCD / StrokeTextFieldCell.swift
index 6f06618..2870fd1 100644 (file)
@@ -12,14 +12,11 @@ final class StrokeTextFieldCell: NSTextFieldCell {
     
     private static let boarderWidth: CGFloat = 2.0
     
-    private let layoutManager: NSLayoutManager
-    private let textContainer: NSTextContainer
+    private let layoutManager = NSLayoutManager()
+    private let textContainer = NSTextContainer()
     
     required init(coder: NSCoder) {
-        
-        layoutManager = NSLayoutManager()
-        textContainer = NSTextContainer()
-        
+                
         super.init(coder: coder)
         
         layoutManager.addTextContainer(textContainer)
@@ -38,18 +35,22 @@ final class StrokeTextFieldCell: NSTextFieldCell {
         
         let attribute = attributedString.attributes(at: 0, effectiveRange: nil)
         
-        guard let forgroundColor = attribute[NSForegroundColorAttributeName] as? NSColor
-            else { return }
+        guard let forgroundColor = attribute[.foregroundColor] as? NSColor else {
+            
+            return
+        }
         
-        if forgroundColor == NSColor.controlTextColor {
+        if forgroundColor == .controlTextColor {
             
             super.drawInterior(withFrame: cellFrame, in: controlView)
             
             return
         }
         
-        guard let font = attribute[NSFontAttributeName] as? NSFont
-            else { return }
+        guard let font = attribute[.font] as? NSFont else {
+            
+            return
+        }
         
         let textStorage = NSTextStorage(string: attributedString.string, attributes: attribute)
         textStorage.addLayoutManager(layoutManager)
@@ -70,11 +71,7 @@ final class StrokeTextFieldCell: NSTextFieldCell {
         
         let nsGlyph = UnsafeMutablePointer<NSGlyph>.allocate(capacity: range.length)
         
-        // TODO: use forEach
-        for i in 0...range.length {
-            
-            nsGlyph[i] = NSGlyph(glyph[i])
-        }
+        (0..<range.length).forEach { nsGlyph[$0] = NSGlyph(glyph[$0]) }
         
         let path = NSBezierPath()
         path.move(to: point)