CGPoint Run-Time Error iOS Swift - swift

I'm receiving a run-time error on the following statement inside of my ViewController class. This seems so straightforward, but tons of searching and videos later, I can't figure out what I did wrong.
class ViewController: UIViewController {
// Main image view controller
#IBOutlet var drawing_ImageView: UIImageView!
// store a point coordinate value based on screen touch
var start = CGPoint(x: 0, y:0)
}
The var start = CGPoint(x: 0, y:0) line throws the error. I also tried:
var start: CGPoint
but that also throws an error. What am I missing? No build or compile errors are thrown.
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Related

EXC_BAD_ACCESS on a non-nil UIView

EDIT: This appears to be a Swift or Cocoapods bug. The LinePlot is defined in a Cocoapod. When I inject my framework code directly into my project, everything is normal.
EDIT 2: At configure, my plotPoints array only has one value(seen in debugger)! What could be happening? Again, copy-pasting my framework code and using that new object works fine, my array has its values.
I get a bad access when calling a method on a custom UIView (LinePlot). The view is presented O.K. and is allocated O.K., but calling this method produces the error.
I have tried using the debugger and examining the tableViewCell's instance data.
let customView = LinePlot()
public func configure<ViewDataModel>(model withViewData: ViewDataModel) {
guard let viewData = withViewData as? StockPlotViewData else {
fatalError("Wrong type sent to StockPlotCell")
}
contentView.addSubview(customView)
backgroundColor = .blue
setupCustomView()
let plotPoints: [CGPoint] = viewData.points.map { (doublePoint) -> CGPoint in
let (x,y) = doublePoint
return CGPoint(x: x, y: y)
}
customView.configure(withViewData: plotPoints, fillColor: .clear, graphLineWidth: 5.0)
}
I expect the 'LinePlot' to be allocated and its methods able to be safely called. However, I get the following error:
Thread 1: EXC_BAD_ACCESS (code=2, address=0x10c35e750)
on line
customView.configure(withViewData: plotPoints, fillColor: .clear, graphLineWidth: 5.0)

Swift: animating uilayoutconstraints and changing alpha causes crash

Why is this code causing a SIGABT error?
#IBAction func showDial(_ sender: Any) {
var dialBottom:CGFloat = lcDialBottom!.constant
if dialBottom == -600 {
//move up
dialBottom = -400
} else {
//move down
dialBottom = -600
}
UIView.animate(withDuration: 0.3,
animations: {
self.lcDialBottom.constant = dialBottom
self.view.layoutIfNeeded()
self.view.updateConstraintsIfNeeded()
self.btnShowDial.alpha = 0.0
})
}
Error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSLayoutConstraint setAlpha:]: unrecognized selector sent to instance 0x600002ff8d70'
I understand what the error is saying, NSLayoutConstraint does not have a setAlpha method, but I'm not calling it on a NSLC, I'm calling set alpha on a UIButton, which does have a setAlpha.
Here's my properties:
#IBOutlet weak var btnShowDial: UIButton!
#IBOutlet weak var lcDialBottom: NSLayoutConstraint!
Check connection of btnShowDial in storyboard. Maybe you connected this IBOutlet with layout constraint.

The program crashes with the following and "lldb" in the debugger - Swift 4 [duplicate]

This question already has answers here:
What does "Fatal error: Unexpectedly found nil while unwrapping an Optional value" mean?
(16 answers)
Closed 4 years ago.
this is a code for a program that behaves like this : When the user presses the button , the UIImage called " The Character" goes up (It changes its y axis). But when I run the program , it doesn't crash but when I press the button called "characterGoesUp" , the program crashes and I get the following in the debugger : "lldb".Why?
Code :
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var TheCharacter: UIImageView!
#IBAction func characterGoesUp(_ sender: Any) {
let xPos = TheCharacter.frame.origin.x
let yPos = TheCharacter.frame.origin.y - 225
let heightCharacter = TheCharacter.frame.size.height
let widthCharacter = TheCharacter.frame.size.width
UIView.animate(withDuration: 1.0, animations: {
self.TheCharacter.frame = CGRect(x: xPos, y: yPos, width: widthCharacter, height: heightCharacter)
}) { (finished) in
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
}
Xcode version : 9.3
EDIT:
The error is this :
"Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"
Your problem is that the imageView TheCharacter is not properly connected to IB , and because of !
#IBOutlet weak var TheCharacter: UIImageView!
in declaration it crashes as it's nil
//
Open the assistant editor and drag from the image to the ViewController's imageView

LBBlurredImage NSInvalidArgumentException

I'm using the following library:
https://github.com/lukabernardi/LBBlurredImage
This is the code I'm using to blur my background image that I'm adding to a ViewController:
var background = UIImage(named: "bg")
var backgroundImageView = UIImageView(image: background)
backgroundImageView.contentMode = .ScaleAspectFill;
backgroundImageView.setImageToBlur(background, blurRadius: 10, completionBlock: { () -> Void in
println("The blurred image has been set")
})
self.view.addSubview(backgroundImageView)
I'm getting the following error and I'm not sure why:
-[UIImageView setImageToBlur:blurRadius:completionBlock:]: unrecognized selector sent to instance 0x7ff08a802390
2015-01-27 10:50:44.326 TestApp[9289:66346] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImageView setImageToBlur:blurRadius:completionBlock:]: unrecognized selector sent to instance 0x7ff08a802390'
UPDATE:
Looks like I'm not the only one to receive the error.
Exception was that the image I was passing was nil and in turn it was violating NSParameterAssert(image);
var background = UIImage(named: "bg")
Instead of this try to specify the full path of the image.
It worked for me and I am pretty sure it will work for you too.
You can also try this path with your code
var background = UIImage(named: "Images/bg");

init var with swift using SpriteKit?

How to correctly init with swift using SpriteKit?
This compiles but I get a error once the simulator starts running. "swift_reportUnimplementedInitializer"
import SpriteKit
class GameScene: SKScene {
var paddlePositionUpdate:CGPoint
init(paddlePositionUpdate:CGPoint){
self.paddlePositionUpdate = CGPoint.zeroPoint
super.init()
}
}
The designated inititaliser for SKScene is init(size) where size is the size of your scene. You have attempted to use init() which does not exist.
You can see the exact method signature if you Cmd+click on SKScene...
EDIT: Try something like
class GameScene: SKScene {
var paddlePositionUpdate: CGPoint
init(size: CGSize, paddlePosition: CGPoint = CGPoint.zeroPoint){
paddlePositionUpdate = paddlePosition
super.init(size)
}
}
A scene should be initialised with a size...
I had a similar problem when replacing a scene with another one using
let gameScene = GameScene(size: self.size)
self.view.presentScene(gameScene)
And I kept getting 2 errors about initialization:
// Error #1
'GameScene' is not constructible with '(size: #lvalue CGSize)'
// Error #2
Class 'GameScene' has no initializers
To fix error #1, just replace GameScene(size: self.size) with GameScene.sceneWithSize(self.size)
Error #2 seems to be affected by how the property is initialized. For example, if I wrote:
class GameScene: SKScene {
var test: CGPoint
// ...
}
Error #2 was still there. But if I replaced var test: CGPoint with var test: CGPoint! , var test = CGPoint(0,0) , or any other lines may give test a certain value, Error #2 was gone. I searched the guide book but found lots of classes using lines like var test: CGPoint. And here I got confused.
It maybe a common problem for Swift beginners and I hope my temporary solution helps.