<!--
{
  "availability" : [
    "iOS: 3.0.0 -",
    "iPadOS: 3.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "QuartzCore",
  "identifier" : "/documentation/QuartzCore/CAShapeLayer/lineDashPattern",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Core Animation"
    ],
    "preciseIdentifier" : "c:objc(cs)CAShapeLayer(py)lineDashPattern"
  },
  "title" : "lineDashPattern"
}
-->

# lineDashPattern

The dash pattern applied to the shape’s path when stroked.

```
var lineDashPattern: [NSNumber]? { get set }
```

## Discussion

The dash pattern is specified as an array of `NSNumber` objects that specify the lengths of the painted segments and unpainted segments, respectively, of the dash pattern.

For example, passing an array with the values `[2,3]` sets a dash pattern that alternates between a 2-user-space-unit-long painted segment and a 3-user-space-unit-long unpainted segment. Passing the values `[10,5,5,5]` sets the pattern to a 10-unit painted segment, a 5-unit unpainted segment, a 5-unit painted segment, and a 5-unit unpainted segment.

Default is `nil`, a solid line.

The following code shows how how you can create three shape layers using the dash patterns described above. Each shape layer contains a simple path that describes a horizontal line.

```swift
let layer = CALayer()
      
let lineDashPatterns: [[NSNumber]?]  = [nil, [2,3], [10, 5, 5, 5]]
     
for (index, lineDashPattern) in lineDashPatterns.enumerated() {
    
    let shapeLayer = CAShapeLayer()
    shapeLayer.strokeColor = UIColor.black.cgColor
    shapeLayer.lineWidth = 5
    shapeLayer.lineDashPattern = lineDashPattern
    
    let path = CGMutablePath()
    let y = CGFloat(index * 50)
    path.addLines(between: [CGPoint(x: 0, y: y),
                            CGPoint(x: 640, y: y)])
    
    shapeLayer.path = path
    
    layer.addSublayer(shapeLayer)
}
```

The following figure shows three shape layers created with the code above. The top solid line has a `nil` [`lineDashPattern`](/documentation/QuartzCore/CAShapeLayer/lineDashPattern), the middle has `[2,3]` and the bottom has `[10,5,5,5]`.

![The effects of different line dash patterns](images/com.apple.quartzcore/media-2825198@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)