How to draw a line in Sprite-kit

Using SKShapeNode you can draw line or any shape.

SKShapeNode *yourline = [SKShapeNode node];
CGMutablePathRef pathToDraw = CGPathCreateMutable();
CGPathMoveToPoint(pathToDraw, NULL, 100.0, 100.0);
CGPathAddLineToPoint(pathToDraw, NULL, 50.0, 50.0);
yourline.path = pathToDraw;
[yourline setStrokeColor:[SKColor redColor]];
[self addChild:yourline];

Equivalent for Swift 4:

var yourline = SKShapeNode()
var pathToDraw = CGMutablePath()
pathToDraw.move(to: CGPoint(x: 100.0, y: 100.0))
pathToDraw.addLine(to: CGPoint(x: 50.0, y: 50.0))
yourline.path = pathToDraw
yourline.strokeColor = SKColor.red
addChild(yourline)

Using SKShapeNode I was able to do this.

// enter code here
SKShapeNode *line = [SKShapeNode node];

CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path, NULL, 50.0, 40.0);
CGPathAddLineToPoint(path, NULL, 120.0, 400.0);

line.path = path;
[line setStrokeColor:[UIColor whiteColor]];

[self addChild:line];

If you only want a line, sort of how people use UIViews for lines (only), then you can just use a SKSpriteNode

SKSpriteNode* line = [SKSpriteNode spriteNodeWithColor:[SKColor blackColor] size:CGSizeMake(160.0, 2.0)];
[line setPosition:CGPointMake(136.0, 50.0))];
[self addChild:line];

Swift 3 for drawing line via SKShapeNode:

            // Define start & end point for line
            let startPoint = CGPoint.zero
            let endPoint = CGPoint.zero

            // Create line with SKShapeNode
            let line = SKShapeNode()
            let path = UIBezierPath()
            path.move(to: startPoint)
            path.addLine(to: endPoint)
            line.path = path.cgPath
            line.strokeColor = UIColor.white
            line.lineWidth = 2