swift Uilable error thread 1 breakpoint 2.4 - ios

var lastnumber: String = ""
#IBOutlet var anserField : UILabel Thread 1: breakpoint 2.4
#IBOutlet var operatorLable: UILabel
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func buttonTapped(TheButton: UIButton) {
if anserField.text == "0" {
anserField.text = TheButton.titleLabel.text
} else {
anserField.text = anserField.text + TheButton.titleLabel.text
}
println(TheButton.titleLabel.text);
}
#IBAction func plusTapped(TheButton: UIButton) {
println("plus tapped")
if operatorLable.text == "" {
operatorLable.text = "+"
lastnumber = anserField.text
anserField.text = "0"
}else {
enterTapped(nil)
operatorLable.text = "+"
}
}
#IBAction func minusTapped(TheButton: UIButton) {
println("minus tapped")
if operatorLable.text == "" {
operatorLable.text = "-"
lastnumber = anserField.text
anserField.text = "0"
}else {
enterTapped(nil)
operatorLable.text = "-"
}
}
#IBAction func cleartapped(AnyObject) {
anserField.text = "0"
operatorLable.text = ""
lastnumber = ""
}
#IBAction func enterTapped(AnyObject?) {
var num1 = lastnumber.toInt()
var num2 = anserField.text.toInt()
if !num1 || !num2 {
ShowError()
return
}
var anser = 0
if operatorLable.text == "-" {
anser = num1! - num2!
} else if operatorLable.text == "+" {
anser = num1! + num2!
} else {
ShowError()
return
}
println(anser)
}
func ShowError(){
// to do this
println("there was a error")
}
}
I need help i am new to swift and coding and i am not to god to be honest i can't figure out what is won't with my code please help! (error is at the top just look on the right)
I am coding a calculator(don't know if that helps but why not) and it is a error that i just can't fix i have tried many things but none of it is working it is a single view application for the iPhone 5s and this code is from the viewcontroler. swift this is the decoder and self things if they useful
aDecoder Swift.ImplicitlyUnwrappedOptional<Foundation.NSCoder> 0x00007f829b04fe00 0x00007f829b04fe00
Some UINibDecoder * 0x00007f829b04fe00 0x00007f829b04fe00
[0] UINibDecoder
self calculater.ViewController 0x00007f829a58a980 0x00007f829a58a980
UIKit.UIViewController UIKit.UIViewController
UIKit.UIResponder UIKit.UIResponder
ObjectiveC.NSObject ObjectiveC.NSObject
lastnumber Swift.String unable to read data
core Swift._StringCore
_baseAddress Swift.COpaquePointer 0x00000001078bd538 0x00000001078bd538 calculater.__TEXT.__ustring + 40
value Builtin.RawPointer 0x1078bd538 0x00000001078bd538 calculater.__TEXT.__ustring + 40
_countAndFlags Swift.UWord 9223372036854775808 -9223372036854775808
value Builtin.Word -9223372036854775808 -9223372036854775808
_owner Swift.Optional<AnyObject> nil None
anserField #sil_weak Swift.ImplicitlyUnwrappedOptional<UIKit.UILabel>
Some UIKit.UILabel
UIKit.UIView UIKit.UIView
UIKit.UIResponder UIKit.UIResponder
ObjectiveC.NSObject ObjectiveC.NSObject
operatorLable #sil_weak Swift.ImplicitlyUnwrappedOptional<UIKit.UILabel>
Some UIKit.UILabel
UIKit.UIView UIKit.UIView
UIKit.UIResponder UIKit.UIResponder
ObjectiveC.NSObject ObjectiveC.NSObject
please put in the comment if you need anything else to figure out the problem
this is what hapend when i turned off the breakpoints and i pressed certain buttons
(more info in comments)
2014-08-22 23:39:05.613 calculater[6307:2641435] -[_TtC10calculater14ViewController plusTapped:]: unrecognized selector sent to instance 0x7faad9dbd150
2014-08-22 23:39:05.617 calculater[6307:2641435] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtC10calculater14ViewController plusTapped:]: unrecognized selector sent to instance 0x7faad9dbd150'
* First throw call stack:
(
0 CoreFoundation 0x00000001070f5055 exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108bafa1c objc_exception_throw + 45
2 CoreFoundation 0x00000001070fbf1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000107054dbc ___forwarding_ + 988
4 CoreFoundation 0x0000000107054958 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000107974196 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x0000000107a78c80 -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x0000000107a7804f -[UIControl touchesEnded:withEvent:] + 522
8 UIKit 0x00000001079b9368 -[UIWindow _sendTouchesForEvent:] + 735
9 UIKit 0x00000001079b9c93 -[UIWindow sendEvent:] + 683
10 UIKit 0x0000000107986f51 -[UIApplication sendEvent:] + 246
11 UIKit 0x0000000107993ec6 _UIApplicationHandleEventFromQueueEvent + 17699
12 UIKit 0x000000010796fcd9 _UIApplicationHandleEventQueue + 1967
13 CoreFoundation 0x000000010702b0b1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
14 CoreFoundation 0x000000010702099d __CFRunLoopDoSources0 + 269
15 CoreFoundation 0x000000010701ffd4 __CFRunLoopRun + 868
16 CoreFoundation 0x000000010701fa06 CFRunLoopRunSpecific + 470
17 GraphicsServices 0x000000010adbeabf GSEventRunModal + 161
18 UIKit 0x0000000107972cf8 UIApplicationMain + 1282
19 calculater 0x0000000106c7f6ed top_level_code + 77
20 calculater 0x0000000106c7f72a main + 42
21 libdyld.dylib 0x0000000109120145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Related

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000***

During few days I am seeing a firebase crash analytic issue (given below) in my console. I am surfing a log but didn't get any solution. I am not sure the crush Mocking line-1 and line-2 (inside the self.addTransferOperation() function). If it is 'addOperation' related issue (line-2), what will its solution then. How it is possible to become the operation (transferOperation) nil. Advance thanks for your help.
line-1:
_ = self.addTransferOperation(device: device, deviceIndex:index, dataTransferCategory:OMVitalDataTransferCategory.bloodPressure)
Line-2:
func addTransferOperation(device: ConnectedDevice, deviceIndex:Int, dataTransferCategory:OMVitalDataTransferCategory = OMVitalDataTransferCategory.all) -> ConnectivityTransferOperation {
let transferOperation = ConnectivityTransferOperation()
// transferOperation.isUserNotify = device == sortedDeviceList.last ? notifyUser : false
let connectedDevice = ConnectedDevice(value : device)
transferOperation.device = ConnectedDevice(value : device)
transferOperation.transferDataType = dataTransferCategory
transferOperation.completionBlock = {
LogManager.shared.addLog(logString: "completion of transfer operation",localName: connectedDevice.deviceLocalName, uuid: connectedDevice.uuid)
// Remove first item
if !self.pendingOperations.syncInProgress.isEmpty {
self.pendingOperations.syncInProgress.removeAll(where: {$0 == transferOperation})
}
// Empty queue
if self.pendingOperations.syncInProgress.isEmpty {
// update autosync timer if Manual sync
if (self.isManualSync) {
self.updateSyncTimer()
}
}
// Reset bluetooth state
self.resetBluetoothState()
DispatchQueue.main.async {
// Set error from transfer operation and set flag to check if it happened in transfer operation
let transferOperationDetails: [String : Any] = [ConnectivityConfiguration.error: transferOperation.error,
ConnectivityConfiguration.isTransferOperation:true]
// post notification for stop data transfer with transfer error operation object
NotificationCenter.default.post(name: .dataTransferStop,
object: transferOperationDetails)
}
}
LogManager.shared.addLog(logString: "Add transfer operation for device \(device.displayName)",localName: connectedDevice.deviceLocalName, uuid: connectedDevice.uuid)
// Add operation and start
self.pendingOperations.syncInProgress.append(transferOperation)
if deviceIndex > 0 {
// add dependency
transferOperation.addDependency(self.pendingOperations.syncInProgress[deviceIndex-1])
}
self.pendingOperations.syncQueue.addOperation(transferOperation)
return transferOperation
}
Crash:
Crashed: com.apple.main-thread
0 Foundation 0x114ea8 ____addOperations_block_invoke.567 + 680
1 Foundation 0x113858 __addOperations + 1288
2 GrandApp 0x7bd3d8 ConnectivityManager.addTransferOperation(device:deviceIndex:dataTransferCategory:) + 2411 (ConnectivityManager.swift:2411)
3 GrandApp 0x7bc3f0 ConnectivityManager.transferOperation(withDevices:notifyUser:isManualSync:) + 4313269232 (<compiler-generated>:4313269232)
4 GrandApp 0x7a6770 ConnectivityManager.startTransferOperation(notifyUser:device:syncAllData:isBeaconFlow:) + 4313180016 (<compiler-generated>:4313180016)
5 GrandApp 0x6c4aa4 closure #1 in DashboardViewController.refreshAction() + 1096 (DashboardViewController.swift:1096)
6 GrandApp 0x7cc37c specialized ConnectivityManager.isSyncing(withStop:completion:) + 4313334652 (<compiler-generated>:4313334652)
7 GrandApp 0x6c4218 DashboardViewController.refreshAction() + 4312252952 (<compiler-generated>:4312252952)
8 GrandApp 0x6c4aec #objc DashboardViewController.refreshAction() + 4312255212 (<compiler-generated>:4312255212)
9 UIKitCore 0x8be300 -[UIApplication sendAction:to:from:forEvent:] + 96
10 UIKitCore 0x367424 -[UIControl sendAction:to:forEvent:] + 80
11 UIKitCore 0x367744 -[UIControl _sendActionsForEvents:withEvent:] + 440
12 UIKitCore 0x3667b0 -[UIControl touchesEnded:withEvent:] + 568
13 UIKitCore 0x8f55c4 -[UIWindow _sendTouchesForEvent:] + 2108
14 UIKitCore 0x8f67ec -[UIWindow sendEvent:] + 3140
15 UIKitCore 0x8d685c -[UIApplication sendEvent:] + 340
16 UIKitCore 0x99c9d4 __dispatchPreprocessedEventFromEventQueue + 1768
17 UIKitCore 0x99f100 __handleEventQueueInternal + 4828
18 UIKitCore 0x998330 __handleHIDEventFetcherDrain + 15
19 CoreFoundation 0xaaf1c CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 24
20 CoreFoundation 0xaae9c __CFRunLoopDoSource0 + 88
21 CoreFoundation 0xaa784 __CFRunLoopDoSources0 + 176
22 CoreFoundation 0xa56c0 __CFRunLoopRun + 1004
23 CoreFoundation 0xa4fb4 CFRunLoopRunSpecific + 436
24 GraphicsServices 0xa79c GSEventRunModal + 104
25 UIKitCore 0x8bcc38 UIApplicationMain + 212
26 GrandApp 0x1db0c main + 19 (AppDelegate.swift:19)
27 libdyld.dylib 0x18e0 start + 4
ConnectivityTransferOperation.swift
import UIKit
import OMConnectivityLibrary
/// Transfer operation for connectivity
class ConnectivityTransferOperation : ConnectivityOperation {
override func main() {
guard isCancelled == false else {
finish(true)
return
}
self.executing(true)
}
override func end() {
// Super call
super.end()
}
}
ConnectivityOperation.swift
import UIKit
import OMConnectivityLibrary
class ConnectivityOperation: Operation {
/// Making operation queue async
override var isAsynchronous: Bool {
get {
return true
}
}
private var _executing = false {
willSet {
willChangeValue(forKey: "isExecuting")
}
didSet {
didChangeValue(forKey: "isExecuting")
}
}
private var _finished = false {
willSet {
willChangeValue(forKey: "isFinished")
}
didSet {
didChangeValue(forKey: "isFinished")
}
}
override var isExecuting: Bool {
return _executing
}
override var isFinished: Bool {
return _finished
}
func executing(_ executing: Bool) {
_executing = executing
}
func finish(_ finished: Bool) {
_finished = finished
}
func end() {
self.finish(true)
self.executing(false)
}
}

IGListKit - Crash on Load More, after network call, updating existing array

General information
IGListKit version: 3.4.0
iOS version(s): 12
CocoaPods/Carthage version: 1.5.3
Xcode version: 10.1
Devices/Simulators affected: All
Reproducible in the demo project? (Yes/No): No demo project
Hello.
I have this issue with IGList kit.
So in my project i have a "Loading more" functionality about images downloaded from my API, paginated.
So there is a class which holds the images
class ProfileImages: ListDiffable {
var nextMaxID: String?
var images: [Images]?
init(nextMaxID: String? = nil, images: [Images]? = []) {
self.images = images
self.nextMaxID = nextMaxID
}
func diffIdentifier() -> NSObjectProtocol {
return (nextMaxID ?? "ProfileImages") as NSObjectProtocol
}
func isEqual(toDiffableObject object: ListDiffable?) -> Bool {
guard self !== object else { return true }
guard let object = object as? ProfileImages else { return false }
return nextMaxID == object.nextMaxID
}
}
In my viewModel i have this function which gives me the above class but with the newest images array without the previous ones, since its paginated.
func updateUserImages(with userID: Int?, and nextMaxID: String, onSuccess: #escaping (ProfileImages) -> Void) {
userService.getUserImages(with: userID, nextMaxId: nextMaxID) { (feedResponse) in
let newProfileImages = ProfileImages(nextMaxID: feedResponse.nextMaxId, images: feedResponse.items)
onSuccess(newProfileImages)
}
}
And in my View Controller, in the scroll delegate of adapter, I have your paradigm from LoadMoreSectionController
extension ProfileViewController: UIScrollViewDelegate {
func scrollViewWillEndDragging(_ scrollView: UIScrollView,
withVelocity velocity: CGPoint,
targetContentOffset: UnsafeMutablePointer<CGPoint>) {
guard let object = self.profileViewModel.viewData.value[1] as? ProfileImages,
let nextMaxID = object.nextMaxID,
var oldImages = object.images else { return }
let distance = scrollView.contentSize.height - (targetContentOffset.pointee.y + scrollView.bounds.height)
if !loading && distance < 200 {
loading = true
adapter.performUpdates(animated: true, completion: nil)
DispatchQueue.global(qos: .default).async {
DispatchQueue.main.async {
self.profileViewModel.updateUserImages(with: self.userService.user.pk, and: nextMaxID, onSuccess: { profileImages in
self.loading = false
oldImages.append(contentsOf: profileImages.images ?? []) // here i update the previews array by appending the new arrays
object.images = oldImages // and here i replace the previews array with the new one which has all the images.
object.nextMaxID = profileImages.nextMaxID
self.adapter.performUpdates(animated: true, completion: nil) // Although if i use `self.adapter.reloadData()` its not crashing although i read on the docs that it's not a proper way to reload stuff.
})
}
}
}
}
}
And when i scroll down it crashes.
2019-02-03 15:31:00.520794+0200 ProjectName [20694:7628667] *** Assertion failure in -[IGListAdapter _visibleSectionControllersFromLayoutAttributes](), /Users/trypow-mac/Desktop/ProjectName/Pods/IGListKit/Source/IGListAdapter.m:515
2019-02-03 15:31:00.527576+0200 ProjectName[20694:7628667] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Section controller nil for cell in section 1'
*** First throw call stack:
(
0 CoreFoundation 0x000000010a3161bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x00000001098b4735 objc_exception_throw + 48
2 CoreFoundation 0x000000010a315f42 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000104fdf940 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
4 IGListKit 0x000000010568eb99 -[IGListAdapter _visibleSectionControllersFromLayoutAttributes] + 1273
5 IGListKit 0x000000010568e67c -[IGListAdapter visibleSectionControllers] + 540
6 IGListKit 0x00000001056935a4 -[IGListAdapter scrollViewDidScroll:] + 196
7 UIKitCore 0x000000011333ba5b -[UIScrollView(UIScrollViewInternal) _notifyDidScroll] + 66
8 UIKitCore 0x00000001133220ef -[UIScrollView setContentOffset:] + 1007
9 UIKitCore 0x00000001133337e5 -[UIScrollView _smoothScrollWithUpdateTime:] + 2967
10 UIKitCore 0x0000000113333bb6 -[UIScrollView _smoothScrollDisplayLink:] + 379
11 QuartzCore 0x00000001063300a2 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 818
12 QuartzCore 0x00000001063fcbb9 _ZL22display_timer_callbackP12__CFMachPortPvlS1_ + 297
13 CoreFoundation 0x000000010a24f5a6 __CFMachPortPerform + 150
14 CoreFoundation 0x000000010a27bf69 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 41
15 CoreFoundation 0x000000010a27b5bb __CFRunLoopDoSource1 + 459
16 CoreFoundation 0x000000010a275b2e __CFRunLoopRun + 2526
17 CoreFoundation 0x000000010a274e11 CFRunLoopRunSpecific + 625
18 GraphicsServices 0x000000010cef51dd GSEventRunModal + 62
19 UIKitCore 0x0000000112ec181d UIApplicationMain + 140
20 ProjectName 0x0000000102022424 main + 68
21 libdyld.dylib 0x000000010b3ee575 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Am I missing something ?

'NSInvalidArgumentException', reason: '-[BanGuayaPrototype.ViewController getTextId:]: unrecognized selector sent to instance 0x7fe5f69027d0'

I am a bit new in the development of native apps for iOS. I am working on Swift 4 and when trying to move to another screen from my login, I am generating the following error:
BanGuayaPrototype[11289:1143773] -[BanGuayaPrototype.ViewController getTextId:]: unrecognized selector sent to instance 0x7fe5f69027d0 2018-01-10 14:40:06.213350-0500
BanGuayaPrototype[11289:1143773] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[BanGuayaPrototype.ViewController getTextId:]: unrecognized selector sent to instance 0x7fe5f69027d0'
* First throw call stack: (
0 CoreFoundation 0x000000010d42512b exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000108ce3f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010d4a6024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKit 0x0000000109a52f51 -[UIResponder doesNotRecognizeSelector:] + 295
4 CoreFoundation 0x000000010d3a7f78 ___forwarding_ + 1432
5 CoreFoundation 0x000000010d3a7958 _CF_forwarding_prep_0 + 120
6 UIKit 0x0000000109820972 -[UIApplication sendAction:to:from:forEvent:] + 83
7 UIKit 0x000000010999fc3c -[UIControl sendAction:to:forEvent:] + 67
8 UIKit 0x000000010999ff59 -[UIControl _sendActionsForEvents:withEvent:] + 450
9 UIKit 0x000000010a548407 -[UITextField _resignFirstResponder] + 155
10 UIKit 0x0000000109a52939 -[UIResponder _finishResignFirstResponder] + 286
11 UIKit 0x000000010a548026 -[UITextField _finishResignFirstResponder] + 48
12 UIKit 0x0000000109a529e8 -[UIResponder resignFirstResponder] + 140
13 UIKit 0x000000010a547ef6 -[UITextField resignFirstResponder] + 135
14 UIKit 0x00000001098d6463 -[UIView(Hierarchy) _removeFirstResponderFromSubtree] + 167
15 UIKit 0x00000001098d6a73 UIViewWillBeRemovedFromSuperview + 72
16 UIKit 0x00000001098d685d -[UIView(Hierarchy) removeFromSuperview] + 95
17 UIKit 0x000000010999b591 __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke.674 + 858
18 UIKit 0x0000000109994b5b -[UIPresentationController transitionDidFinish:] + 111
19 UIKit 0x0000000109c1cc1e -[_UICurrentContextPresentationController transitionDidFinish:] + 44
20 UIKit 0x0000000109998f4f __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 183
21 UIKit 0x000000010a58d088 -[_UIViewControllerTransitionContext completeTransition:] + 102
22 UIKit 0x0000000109991dba -[UITransitionView notifyDidCompleteTransition:] + 251
23 UIKit 0x0000000109991a31 -[UITransitionView _didCompleteTransition:] + 1397
24 UIKit 0x00000001099940c8 -[UITransitionView _transitionDidStop:finished:] + 104
25 UIKit 0x00000001098b56c4 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 343
26 UIKit 0x00000001098b5d23 -[UIViewAnimationState animationDidStop:finished:] + 293
27 UIKit 0x00000001098b5dd7 -[UIViewAnimationState animationDidStop:finished:] + 473
28 QuartzCore 0x00000001096696bd _ZN2CA5Layer23run_animation_callbacksEPv + 323
29 libdispatch.dylib 0x000000010e54733d _dispatch_client_callout + 8
30 libdispatch.dylib 0x000000010e5525f9 _dispatch_main_queue_callback_4CF + 628
31 CoreFoundation 0x000000010d3e7e39 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9
32 CoreFoundation 0x000000010d3ac462 __CFRunLoopRun + 2402
33 CoreFoundation 0x000000010d3ab889 CFRunLoopRunSpecific + 409
34 GraphicsServices 0x0000000110ff39c6 GSEventRunModal + 62
35 UIKit 0x000000010981f5d6 UIApplicationMain + 159
36 BanGuayaPrototype 0x00000001083a31d7 main + 55
37 libdyld.dylib 0x000000010e5c3d81 start + 1
38 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
Below are the classes involved:
ViewController.swift
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var getText: UITextField!
var cliente = Cliente()
#IBAction func onGoButtonLH(_ sender: Any) {
let idTxt:String? = getText.text
if idTxt == "1234" {
self.performSegue(withIdentifier: "LoginToComercial", sender: self)
}else{
let urlString = "http://localhost:8080/RestServiceBgPrototype/cognitiva/clientService/"+idTxt!
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url) { (data, response, error) in
if error != nil {
print(error!.localizedDescription)
}
guard let data = data else { return }
//Implement JSON decoding and parsing
do {
let decoder = JSONDecoder()
self.cliente = try! decoder.decode(Cliente.self, from: data)
OperationQueue.main.addOperation{
self.performSegue(withIdentifier: "LoginToHome", sender: self.cliente)
}
}
}.resume()
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "LoginToHome") {
let homeViewController = segue.destination as? HomeViewController
let cliente = sender as! Cliente
homeViewController?.cliente = cliente
}
}
}
HomeViewController.swift
class HomeViewController: UIViewController {
#IBOutlet weak var userLabel: UILabel!
var cliente = Cliente()
override func viewDidLoad() {
super.viewDidLoad()
let nombreCliente:String = cliente.nombre
let fullNameArr = nombreCliente.components(separatedBy:(" "))
let nombre = fullNameArr[2]
let apellido = fullNameArr[0]
self.userLabel.text = "Hola, "+nombre.capitalized+" "+apellido.capitalized
}
}
Any idea why I get this error?
To debug crash while it's happening and inspect what is the reason.
You can do this:
In your Breakpoint navigator at the bottom click plus button and add exception breakpoint
That will add to your project all exception break point.
It means when ever your app crashes is will stop on a line which generate crash.
Then we can figure out what to do next.
However, you are using force unwrap a lot, for instance:
let cliente = sender as! Cliente
if error != nil {
print(error!.localizedDescription)
}
It's better to do like this
if let error = error {
print(error.localizedDescription)
}
Please try not to use !. In case if your application encounter nil instead of object program will crash.
To answer your question. Your application do crash trying to send message getTextId to an object of type BanGuayaPrototype.ViewController.
This selector is not recognised. That's the root of your crash.
How did that happen?
For now what I can think. You have an object:
let obj: BanGuayaPrototype
and what are you trying to do is to call a method getTextId on this object.
This type of error is common in ObjectiveC. Occurs when you can try to send message to an object. If given object are unable to handle message program is crashing.

NSInvalidArgumentException Using UISegmentedControl

I am creating an application and receiving an NSInvalidArgumentException. The error occurs when I run my application on the iOS emulator and click on one of the items in the UISegmentedControl.
I believe it relates to my "mapTypeChanged" method but I wanted to confirm:
Code:
import UIKit
import MapKit
class MapViewController : UIViewController {
var mapView: MKMapView!
//called if the view property of a ViewController is nill
override func loadView() {
//Create a map view
mapView = MKMapView()
//Set it as the "View" of the ViewController
view = mapView
let segmentedControl = UISegmentedControl(items: ["Standard", "Hybrid", "Satellite"])
segmentedControl.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.5)
segmentedControl.selectedSegmentIndex = 0
segmentedControl.addTarget(self, action: "mapTypeChanged:", forControlEvents: .ValueChanged)
segmentedControl.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(segmentedControl)
let topConstraint = segmentedControl.topAnchor.constraintEqualToAnchor(topLayoutGuide.bottomAnchor, constant: 8)
let margins = view.layoutMarginsGuide
let leadingConstraint = segmentedControl.leadingAnchor.constraintEqualToAnchor(margins.leadingAnchor)
let trailingConstraint = segmentedControl.trailingAnchor.constraintEqualToAnchor(margins.trailingAnchor)
topConstraint.active = true
leadingConstraint.active = true
trailingConstraint.active = true
}
func mapTypedChanged(segControl: UISegmentedControl){
switch segControl.selectedSegmentIndex{
case 0:
mapView.mapType = .Standard
case 1:
mapView.mapType = .Hybrid
case 2:
mapView.mapType = .Satellite
default:
break
}
}
override func viewDidLoad() {
super.viewDidLoad()
print("MapViewController loaded its view")
}
}
Error:
ConversionViewController loaded its view
MapViewController loaded its view
2016-04-26 13:54:56.341 WorldTrotter[1530:865418] -[WorldTrotter.MapViewController mapTypeChanged:]: unrecognized selector sent to instance 0x7fb883c8dce0
2016-04-26 13:54:56.344 WorldTrotter[1530:865418] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WorldTrotter.MapViewController mapTypeChanged:]: unrecognized selector sent to instance 0x7fb883c8dce0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102281f45 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000103fa5deb objc_exception_throw + 48
2 CoreFoundation 0x000000010228a56d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00000001021d7eea ___forwarding___ + 970
4 CoreFoundation 0x00000001021d7a98 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000102a9fe91 -[UIApplication sendAction:to:from:forEvent:] + 92
6 UIKit 0x0000000102c0b4d8 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000102c0b7a4 -[UIControl _sendActionsForEvents:withEvent:] + 311
8 UIKit 0x0000000102cb8661 -[UISegmentedControl _setSelectedSegmentIndex:notify:animate:] + 690
9 UIKit 0x0000000102cbad35 -[UISegmentedControl touchesEnded:withEvent:] + 232
10 UIKit 0x0000000102b0ded1 -[UIWindow _sendTouchesForEvent:] + 835
11 UIKit 0x0000000102b0ec06 -[UIWindow sendEvent:] + 865
12 UIKit 0x0000000102abe2fa -[UIApplication sendEvent:] + 263
13 UIKit 0x0000000102a98abf _UIApplicationHandleEventQueue + 6844
14 CoreFoundation 0x00000001021ae011 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x00000001021a3f3c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x00000001021a33f3 __CFRunLoopRun + 867
17 CoreFoundation 0x00000001021a2e08 CFRunLoopRunSpecific + 488
18 GraphicsServices 0x0000000106b11ad2 GSEventRunModal + 161
19 UIKit 0x0000000102a9e30d UIApplicationMain + 171
20 WorldTrotter 0x0000000101debdcd main + 109
21 libdyld.dylib 0x00000001073e592d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
In addTarget you wrote mapTypeChanged, but the function is called mapTypedChanged (notice "Type" vs "Typed").
Instead of
func mapTypedChanged(segControl: UISegmentedControl)
, use the correct
func mapTypeChanged(segControl: UISegmentedControl)

uncaught exception 'NSUnknownKeyException', class is not key value coding-compliant [duplicate]

This question already has answers here:
this class is not key value coding-compliant for the key view [duplicate]
(7 answers)
Closed 8 years ago.
I am learning iOS by following a online video class. I am unsure of why I am getting this error. I feel as thought I followed everything step by step and I ended up with this error:
Usually I would look at the error and traceback to try to find where the error occurred but I am new to iOS and I do not understand the output one bit.
2015-01-30 17:57:40.511 99RedBalloons[18322:1563170] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<_9RedBalloons.ViewController 0x7fb5d3e17750> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key backgroundimageView.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010ca3ff35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010e583bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010ca3fb79 -[NSException raise] + 9
3 Foundation 0x000000010ce577b3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x000000010c989e80 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x000000010d590c7d -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x000000010d3eff98 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x000000010d3f0588 -[UIViewController loadView] + 109
8 UIKit 0x000000010d3f07f9 -[UIViewController loadViewIfRequired] + 75
9 UIKit 0x000000010d3f0c8e -[UIViewController view] + 27
10 UIKit 0x000000010d30fca9 -[UIWindow addRootViewControllerViewIfPossible] + 58
11 UIKit 0x000000010d310041 -[UIWindow _setHidden:forced:] + 247
12 UIKit 0x000000010d31c72c -[UIWindow makeKeyAndVisible] + 42
13 UIKit 0x000000010d2c7061 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2628
14 UIKit 0x000000010d2c9d2c -[UIApplication _runWithMainScene:transitionContext:completion:] + 1350
15 UIKit 0x000000010d2c8bf2 -[UIApplication workspaceDidEndTransaction:] + 179
16 FrontBoardServices 0x00000001101102a3 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
17 CoreFoundation 0x000000010c97553c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
18 CoreFoundation 0x000000010c96b285 __CFRunLoopDoBlocks + 341
19 CoreFoundation 0x000000010c96aa43 __CFRunLoopRun + 851
20 CoreFoundation 0x000000010c96a486 CFRunLoopRunSpecific + 470
21 UIKit 0x000000010d2c8669 -[UIApplication _run] + 413
22 UIKit 0x000000010d2cb420 UIApplicationMain + 1282
23 99RedBalloons 0x000000010c4aacce top_level_code + 78
24 99RedBalloons 0x000000010c4aad0a main + 42
25 libdyld.dylib 0x000000010ed5d145 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I don't understand the Traceback one bit
code:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var balloonsLabel: UILabel!
#IBOutlet weak var backgroundImageView: UIImageView!
var balloons:[Balloon] = [];
var currentIndex = 0;
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.createBalloons()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func nextBalloonBarButtonItemPressed(sender: UIBarButtonItem) {
let balloon = balloons[currentIndex]
balloonsLabel.text = "\(balloon.number) balloon"
backgroundImageView.image = balloon.image
currentIndex += 1
}
func createBalloons() {
for var balloonCount = 0; balloonCount <= 99; ++balloonCount {
var balloon = Balloon();
balloon.number = balloonCount;
let randomNumber = Int(arc4random_uniform(UInt32(4)));
switch randomNumber {
case 1:
balloon.image = UIImage(named: "RedBalloon1.jpg")
case 2:
balloon.image = UIImage(named: "RedBalloon2.jpg")
case 3:
balloon.image = UIImage(named: "RedBalloon3.jpg")
default:
balloon.image = UIImage(named: "RedBalloon4.jpg")
}
self.balloons.append(balloon);
}
}
}
Balloon.swft:
import Foundation
import UIKit
struct Balloon {
var number = 0;
var image = UIImage(named: "");
}
The error is saying that it doesn't know the property, backgroundimageView -- notice the lowercase "i". Your property name is backgroundImageView with a capital "I". Somewhere in the storyboard or xib, you're using this property with incorrect spelling.

Resources