Error on if command, object nil - ios

I have this code:
if (self.leadObject != nil) {
[result addObject:self.leadObject];
}
And sometimes app close with this error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM
insertObject:atIndex:]: object cannot be nil'
The execution pass if command and try to add the object self.leadObject inside of result array although this object is nil.
Can someone explain this??
Update:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM
insertObject:atIndex:]: object cannot be nil' *** First throw call
stack: (0x2ca8af87 0x3a1e9c77 0x2c9a6f29 0x1777ff 0x177a6f 0x177b7f
0x1779df 0x17446d 0xa1cdd 0xa7933 0x46cad3 0x46cabf 0x47051b
0x2ca50e61 0x2ca4f581 0x2c99cdb1 0x2c99cbc3 0x33d28051 0x2ff68a31
0xadb45 0x3a785aaf) libc++abi.dylib: terminating with uncaught
exception of type NSException

I suspect that you have not allocated your result object. Do so if you didn't and then Log the self.leadObject to make sure that it isn't an NSNull
if (self.leadObject) {
NSLog(#"%#", self.leadObject);
[result addObject:self.leadObject];
}

Related

Swift: nskeyedunarchiver fails and terminates app with 'NSInvalidArgumentException', reason: '-[__NSCFData count]

NSKeyedUnarchiver.UnarchivedArrayOfObjects() terminates app with 'NSInvalidArgumentException', reason: '-[__NSCFData count]
track conforms to NSManagedObject
However decodedTrackLocation is declared #Published public var decodedTrackLocation: [CLLocation] = [], as it is not persistent, but supposed to be in memory.
The below code works on certain 'saves', but sometimes it throws an exception and I can't figure out what to do about it.
It crashes at 'if let final =' and throws this exception:
2021-06-01 17:42:28.052628+0200 GeoTrack[12300:1124356] -[__NSCFData count]: unrecognized selector sent to instance 0x17a61df50
2021-06-01 17:42:28.061055+0200 GeoTrack[12300:1124356] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData count]: unrecognized selector sent to instance 0x17a61df50'
*** First throw call stack:
(0x1a9e27298 0x1bdb81480 0x1a9d362a8 0x1a9e298f4 0x1a9e2b89c 0x1ad67168c 0x1ad707e24 0x1026e5988 0x102704310 0x1b0345f94 0x1b0345fb0 0x1b0345f94 0x1b0737d74 0x1b0733e68 0x1b02225f4 0x1b088b190 0x1031f7ae8 0x102ee7ae8 0x102ee932c 0x102ef776c 0x1a9da62e0 0x1a9da0740 0x1a9d9f818 0x1c04a5570 0x1ac6cb0e8 0x1ac6d0664 0x1025696dc 0x1a9a7e140)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFData count]: unrecognized selector sent to instance 0x17a61df50'
terminating with uncaught exception of type NSException
The reason the NSKeyedUnarchiver fails is because I did something stupid, I stored the wrong Data. What I can't grasp is why the do-try-catch block this code lives in, doesn't work/catch.
Any help would be appreciated.
The code in Question:
do{
let out = try Data(referencing: NSData(data: track.trackLocation).decompressed(using: .lzma))
let archiver = try NSKeyedUnarchiver(forReadingFrom: out)
archiver.requiresSecureCoding = true
archiver.decodingFailurePolicy = .setErrorAndReturn
if let final = archiver.decodeArrayOfObjects(ofClass: CLLocation.self, forKey: NSKeyedArchiveRootObjectKey){
track.decodedTrackLocation = final
}
} catch {
print(error)
}
do{
let out = try Data(referencing: NSData(data: track.trackLocation).decompressed(using: .lzma))
if let final = try NSKeyedUnarchiver.unarchivedArrayOfObjects(ofClass: CLLocation.self, from: out){
track.decodedTrackLocation = final
}
} catch {
print(error)
}
Because it's not an Error that is thrown (throws), it's a NSInvalidArgumentException, a NSException, on Objective-C one. You can look for it :) - Larme
I learned something new!

React Native IOS: "Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'"

I have to experience this issue upon trying to build a release in a simulator.
**** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
terminating with uncaught exception of type NSException
CoreSimulator 732.18.6 - Device: iPhone 11*
The error is in:
_dispatch_once(dispatch_once_t *predicate,
DISPATCH_NOESCAPE dispatch_block_t block)
{
if (DISPATCH_EXPECT(*predicate, ~0l) != ~0l) {
dispatch_once(predicate, block); // Here is the Exception Thread 1: "data parameter is nil"
} else {
dispatch_compiler_barrier();
}
DISPATCH_COMPILER_CAN_ASSUME(*predicate == ~0l);
}```

'NSInvalidArgumentException', reason: '-[NSTaggedPointerString count]: unrecognized selector sent to instance 0x8000000000000000'

When I am trying to access array, ends up with this exception but when I add breakpoint on and try to print in the debugger log, array seems to have values and does not appeared to be wrong
oldDevices.forEach { (oldDevice) in
if(self.averageRssis.count > 0){
if(self.averageRssis[oldDevice.bluetoothId] != nil)
{
self.averageRssis[oldDevice.bluetoothId] = nil
DispatchQueue.main.async {
self.bluetoothManager.remove(device:
oldDevice)
}
}
}
}
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSTaggedPointerString count]: unrecognized selector sent to instance 0x8000000000000000'
* First throw call stack:
(0x1c19ca98c 0x1c0ba39f8 0x1c18e71c8 0x1c19d01d4 0x1c19d1e6c 0x1efc638a8 0x102ef9f44 0x102efa90c 0x102f00f40 0x1efd2f23c 0x102ef965c 0x102f21cf8 0x102eefaec 0x103004c78 0x103007ffc 0x10301a610 0x103015dc8 0x1030167ac 0x1c15ea1b4 0x1c15eccd4)
libc++abi.dylib: terminating with uncaught exception of type NSException

iOS Terminating app due to uncaught exception ' this class is not key value coding-compliant for the key success.'

In my code I have to get the value from NSDictionary but it crashes and the crash issue is,
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<__NSCFString 0x155000fa0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key success.'
Here I show the the code what I am trying.
NSLog(#"finalValNotify is: %#", finalValNotify);
if (finalValNotify) {
int successResult=[[finalValNotify valueForKey:#"success"]intValue]; ====>This line app crashed
if (successResult==1) {
NSLog(#"finalValNotify is: %d", successResult);
}
}
Here I show the printed NSDictionary value:
finalValNotify is: {"multicast_id":5704734283387573862,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1534486056437155%1dbdaa031dbdaa03"}]}
But I don't know the reason for why the crash was occur.
If finalValNotify is your NSDictionary then use as -
int successResult = [finalValNotify[#"success"] intValue];

import AlgoliaSearch with Swift 2 causing error

Adding this line to my App import AlgoliaSearch returns this error:
2017-05-08 22:35:07.814593 XXXXXX[6255:2627487] -[__NSDictionaryI
length]: unrecognized selector sent to instance 0x1702f0980 2017-05-08
22:35:07.816565 XXXXXX[6255:2627487] * Terminating app due to
uncaught exception 'NSInvalidArgumentException', reason:
'-[__NSDictionaryI length]: unrecognized selector sent to instance
0x1702f0980'
* First throw call stack: (0x192f351b8 0x19196c55c 0x192f3c268 0x192f39270 0x192e3280c 0x1015c8608 0x10158d72c 0x10194a198
0x1001f6c24 0x1001f8c9c 0x100091fd4 0x1003973d4 0x100397690
0x1003be2c0 0x101a5d258 0x101a5d218 0x101a62280 0x192ee2810
0x192ee03fc 0x192e0e2b8 0x1948c2198 0x198e557fc 0x198e50534
0x10013c734 0x191df15b8) libc++abi.dylib: terminating with uncaught
exception of type NSException (lldb)
The line of code it is referring to is as below:
self.ref.child("users").observeSingleEventOfType(.Value, withBlock: { (snapshot) in
for user in snapshot.children{
var numVids = NSDictionary()
if ((user.hasChild("videos")) == true){
--> numVids = user.value["videos"] as! NSDictionary
}
}
As soon as I remove the import Algolia module the error is removed, I have tried changing the version of the module and even switching to use the objc version but the error was the same.
Anyone seen something like this before?
https://github.com/algolia/algoliasearch-client-swift
https://github.com/algolia/algoliasearch-client-objc

Resources