How Assistant Model Works in Swift

Use Xcode's Test Classes Assistant Editor with Swift Classes

The shortcuts mentioned in other answers work great, but they don't make the assistant editor automatically work with test classes. Turns out it didn't work with swift code previously, but Apple just added support for this to Xcode 9:

A file with a base name of FooTest or FooTests is now considered a counterpart of a file with a base name of Foo for navigation and the Assistant Editor. (28981734)

So, with Xcode 9, the test target filename needs to have the same name as the main code file + either 'Test' or 'Tests' and the Xcode test classes assistant editor will work automatically.

Watson Assistant and Swift

I figured it out! I was not passing the correct input context, so it was like the conversation was starting anew every single time.

How to use the Watson Conversation inside iOS Swift?

The input parameter of the MessageRequest constructor takes an InputData object, which is easy to construct from a text string. Try

let input = InputData(text: text)
let request = MessageRequest(input: input, context: self.context)
self.conversation?.message(workspaceID: Credentials.ConversationWorkspaceID,
request: request,
failure: failure) {

Xcode unable to open proper class in Assistant Editor for class UICollectionReusableView

Try some ways below:

  1. Click onto right side, Shift+Command+O, paste the class name you
    expect to open. Ex: GenericCollectionReusableView
  2. As image below, you can click onto anywhere in red rectangle, this will show popup for you direct to your expected file.
    Sample Image

Draw a line that can stretch like the Xcode assistant editor in Swift

You can use UIPanGestureRecognizer to get gesture events and draw a CALayer with UIBezierPath.

UIPanGestureRecognizer has some gesture states, in this case, we need to handle three states to draw the line. Let's separate the whole action into small pieces for more easier to figure out what to do.

Before the start, there is one thing you have to know.

// We can get current touch position via gesture recognizer.
let currentPanPoint = panRecognizer.location(in: self.view)
  1. To get line start point and create a CALayer in state UIGestureRecognizerState.began.
case .began:
panGestureStartPoint = currentPanPoint
self.view.layer.addSublayer(lineShape)

  1. Get line end point in state UIGestureRecognizerState.changed and create a UIBezierPath, assign the CGPath of UIBezierPath to CALayer to draw the line.
case .changed:
let linePath = UIBezierPath()
linePath.move(to: panGestureStartPoint)
linePath.addLine(to: currentPanPoint)

lineShape.path = linePath.cgPath

  1. Remove the line from layout in state UIGestureRecognizerState.end.
case .ended:
lineShape.path = nil
lineShape.removeFromSuperlayer()

Combine the fragments above, here is the example code.

class ViewController: UIViewController {
@IBOutlet var dragFrom: UILabel!

private lazy var lineShape: CAShapeLayer = {
let lineShape = CAShapeLayer()
lineShape.strokeColor = UIColor.blue.cgColor
lineShape.lineWidth = 2.0

return lineShape
}()
private var panGestureStartPoint: CGPoint = .zero
private lazy var panRecognizer: UIPanGestureRecognizer = {
return UIPanGestureRecognizer(target: self, action: #selector(panGestureCalled(_:)))
}()

override func viewDidLoad() {
super.viewDidLoad()

self.dragFrom.addGestureRecognizer(panRecognizer)
}

// MARK: Selectors
func panGestureCalled(_: UIPanGestureRecognizer) {
let currentPanPoint = panRecognizer.location(in: self.view)
switch panRecognizer.state {
case .began:
panGestureStartPoint = currentPanPoint
self.view.layer.addSublayer(lineShape)

case .changed:
let linePath = UIBezierPath()
linePath.move(to: panGestureStartPoint)
linePath.addLine(to: currentPanPoint)

lineShape.path = linePath.cgPath
case .ended:
lineShape.path = nil
lineShape.removeFromSuperlayer()
default: break
}
}
}

And it works like this.
http://i.imgur.com/5JsFeoB.gifv

If you wanna learn more details, this is the tutorial in Apple's Developer guides. Learn how to draw shapes using Bezier Path

Xcode assistant editor doesn't show the auto option

I'm not sure what you mean by "auto" option... but what I think you might be looking for is Counterparts, which is there.



Related Topics



Leave a reply



Submit