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:
- Click onto right side, Shift+Command+O, paste the class name you
expect to open. Ex: GenericCollectionReusableView - As image below, you can click onto anywhere in red rectangle, this will show popup for you direct to your expected file.
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)
- To get line start point and create a
CALayer
in stateUIGestureRecognizerState.began
.
case .began:
panGestureStartPoint = currentPanPoint
self.view.layer.addSublayer(lineShape)
- Get line end point in state
UIGestureRecognizerState.changed
and create aUIBezierPath
, assign theCGPath
ofUIBezierPath
toCALayer
to draw the line.
case .changed:
let linePath = UIBezierPath()
linePath.move(to: panGestureStartPoint)
linePath.addLine(to: currentPanPoint)
lineShape.path = linePath.cgPath
- 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
How to Compare Two Strings to Check If They Have Same Characters Swift 4
How to Get All Text from a PDF in Swift
Simple Swift Class Does Not Compile
Passing Unknown Number of Arguments in a Function
Unexpected Non-Void Return Value in Void Function Swift 4 Using JSON Serialisation
Swift: How to Get Information for an Application Which Is Not Running
Equivalent of Skaction Scaletox for a Given Duration in Unity
Why Do We Need to Specify Init Method
Swift Switch Char{ Case "\U{E2}:
How to Run the Simulator the Operation Couldn't Be Completed. (Launchserviceserror Error 0.)
How to Make Struct Lazylist in Swiftui
Can't Use 'Shape' as Type in Swiftui
Swift 2: Multiline Mkpointannotation
Is There Any Particular Use of Closure in Swift? and What's the Benefit
Swift Access Array with Index Gives Following Error. Any Idea Why