Xcode NSSortDescriptor Error Thread 1: signal ABRT - ios

Hi I'm creating a stocks application in the Objective-C Big Nerd Ranch 2nd edition book and at the end of each chapter theres a challenge and the chapter i'm on has a challenge which is add a method to BNRPortfolio that returns an NSArray of all its stock holdings, sorted alphabetically by symbol and then test it in main(). Everything works great except for this method(which is declared in the BNRPortfolio.h). It gives me this error: Thread 1: signal ABRT. And prints the message below in the console. The error report and what I think it is, is there is something happening the the sortDescriptorWithKey:#"symbol" part but the error appears on the [sortedBySymbolHoldings sortUsingDescriptors:#[s]]; part which is whats throwing me off. If you have any ideas on how to fix this your help is greatly appreciated thanks!
Code in BNRPortfolio.m:
- (NSArray *)holdingsSortedBySymbol
{
NSSortDescriptor *s = [NSSortDescriptor sortDescriptorWithKey:#"symbol" ascending:YES];
NSMutableArray *sortedBySymbolHoldings = [[NSMutableArray alloc] init];
sortedBySymbolHoldings = _stocks;
[sortedBySymbolHoldings sortUsingDescriptors:#[s]];
return sortedBySymbolHoldings;
}
What it prints in the console:
2014-02-06 16:18:26.309 Stocks[1286:303] Portfolio for UK has a value of £279.50
2014-02-06 16:18:26.311 Stocks[1286:303] Portfolio for US has a value of $12772.00
2014-02-06 16:18:26.311 Stocks[1286:303] Top 3 most valuable holdings: (
"<BNRStockHolding: 0x100106e90>",
"<BNRStockHolding: 0x100102f70>",
"<BNRStockHolding: 0x100104c90>"
)
2014-02-06 16:18:26.312 Stocks[1286:303] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<BNRStockHolding 0x100106e90> valueForUndefinedKey:]: this class is not key value coding-compliant for the key symbol.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff85d5a41c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff8d933e75 objc_exception_throw + 43
2 CoreFoundation 0x00007fff85d59fc9 -[NSException raise] + 9
3 Foundation 0x00007fff8377e06e -[NSObject(NSKeyValueCoding) valueForUndefinedKey:] + 235
4 Foundation 0x00007fff83695406 -[NSObject(NSKeyValueCoding) valueForKey:] + 381
5 Foundation 0x00007fff836ad49f -[NSObject(NSKeyValueCoding) valueForKeyPath:] + 334
6 Foundation 0x00007fff836ac04c _sortedObjectsUsingDescriptors + 394
7 Foundation 0x00007fff8370fbd6 -[NSMutableArray(NSKeyValueSorting) sortUsingDescriptors:] + 466
8 Stocks 0x0000000100002018 -[BNRPortfolio holdingsSortedBySymbol] + 264
9 Stocks 0x00000001000028c2 main + 1522
10 libdyld.dylib 0x00007fff84b005fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Related

Irregular crash when creating NSManagedObject out of NSSet

I have an irregular crash (1 in 5 times on devices, 4 in 5 times on Simulator). I have set an exception breakpoint and it occurs on the following line without any console information:
if let carColorSet = car.carToDisplay?.allObjects as? [Display] {
Note: car.carToDisplay is an NSSet
Before I set the exception breakpoint, I would get the following info in the console when it crashed:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSMutableSet unionSet:]: set argument is not an NSSet'
*** First throw call stack:
(
0 CoreFoundation 0x0000000102e79b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001023d6141 objc_exception_throw + 48
2 CoreFoundation 0x0000000102e00051 -[NSMutableSet unionSet:] + 1041
3 CoreData 0x0000000101b10df8 -[_NSFaultingMutableSet willReadWithContents:] + 936
4 CoreData 0x0000000101af131b -[_NSFaultingMutableSet allObjects] + 27
5 Keyboard 0x00000001018f838e
Any idea here? It seems like the crash occurs when I try to turn that carToDisplay?.allObjects into an array of Display objects.
This is a keyboard extension app btw.
Thank you for any input!
Problem (probably):
if let carColorSet = car.carToDisplay?.allObjects as? [Display]
carToDisplay is a NSet
However the function allObjects returns an array
I think you are trying to do a unionSet with an array.
Update the Question:
Please update your question, the qestion doesn't state the correct line of error.
The question needs to do the following
state where the unionSet is invoked.
what the argument type of unionSet is.

GMSPolygon array iOS crash

I Have an extremely strange issue with the GMSPolygon object.
Just out of nowhere my code crashes with the error "Unrecognized selector send to instance 0x...."
(Yes it worked all day, and suddenly it starts crashing)
I am using an array of Polygons (to keep track of them and update them dynamically) and I initialize them as follows in my -viewDidLoad:
GMSPolygon *myPoly[50];
--
GMSMutablePath *path = [[GMSMutablePath alloc] init];
// set some fake coordinates, initializing a Polygon with an empty path seems to crash as well...
[path addCoordinate:CLLocationCoordinate2DMake(1,0)];
[path addCoordinate:CLLocationCoordinate2DMake(-1,0)];
[path addCoordinate:CLLocationCoordinate2DMake(0,1)];
for (int i=0;i<50;i++) {
myPoly[i] = [GMSPolygon polygonWithPath:path];
myPoly[i].map = nil;
}
Later on in my program I try to acces the object again in the same way, first set it to nil so it will be removed from the map, and then update and if necessary display it again
for (int i=0;i<50;i++) {
myPoly[i] = [GMSPolygon polygonWithPath:path];
myPoly[i].map = nil; <--------- CRASH
// Do other stuf here, update the Polygon data and if needed
// display again as follows:
myPoly[i].map = mapView_;
}
But it seems to crash..
Same thing happens if I put the GMSPolygon in an NSMutable array. Initializing the array is fine, but getting the GMSPolygon out of the array and setting the .map property gives the same crash..
UPDATE:
It seems be caused by the object Memory locations.. If it works fine, memory locations are as follows:
[0] GMSPolygon * 0x1558ed750 0x00000001558ed750 <--- viewDidLoad for-loop
[0] GMSPolygon * 0x1558ed750 0x00000001558ed750 <--- other function for-loop
When it crashes
[0] GMSPolygon * 0x12e7cbf30 0x000000012e7cbf30 <--- viewDidLoad for-loop
[0] GMSPolygon * 0x129d36630 0x0000000129d36630 <--- other function for-loop
The object is only initialized once in the viewDidLoad, nowhere else!
It obviously explains the crash if the objects memory location are different.. but what's happening here?
Any one an idea why?
UPDATE 2, Got Crash log now:
2016-04-14 15:16:49.618 myApp[1130:240689] -[GMSMutablePath setMap:]: unrecognized selector sent to instance 0x1540bb560
2016-04-14 15:16:49.627 myApp[1130:240689] void uncaughtExceptionHandler(NSException *__strong) [Line 354] CRASH: -[GMSMutablePath setMap:]: unrecognized selector sent to instance 0x1540bb560
2016-04-14 15:16:49.688 myApp[1130:240689] void uncaughtExceptionHandler(NSException *__strong) [Line 355] Stack Trace: (
0 CoreFoundation 0x0000000182ebee50 <redacted> + 148
1 libobjc.A.dylib 0x0000000182523f80 objc_exception_throw + 56
2 CoreFoundation 0x0000000182ec5ccc <redacted> + 0
3 CoreFoundation 0x0000000182ec2c74 <redacted> + 872
4 CoreFoundation 0x0000000182dc0d1c _CF_forwarding_prep_0 + 92
5 myApp 0x00000001001115a0 -[mapViewController plotPoly] + 2028
6 myApp 0x000000010012c944 -[mapViewController mapView:didChangeCameraPosition:] + 556
7 CoreFoundation 0x0000000182ec4ae0 <redacted> + 144
8 CoreFoundation 0x0000000182dbc548 <redacted> + 284
9 CoreFoundation 0x0000000182dc0e70 <redacted> + 60
10 myApp 0x0000000100203370 -[GMSDelegateForward forwardInvocation:] + 108
11 CoreFoundation 0x0000000182ec2aa4 <redacted> + 408
12 CoreFoundation 0x0000000182dc0d1c _CF_forwarding_prep_0 + 92
13 myApp 0x0000000100188fec -[GMSMapView updateWithCamera:] + 176
14 Foundation 0x0000000183893ffc <redacted> + 340
15 CoreFoundation 0x0000000182e75124 <redacted> + 24
16 CoreFoundation 0x0000000182e74bb8 <redacted> + 540
17 CoreFoundation 0x0000000182e728b8 <redacted> + 724
18 CoreFoundation 0x0000000182d9cd10 CFRunLoopRunSpecific + 384
19 GraphicsServices 0x0000000184684088 GSEventRunModal + 180
20 UIKit 0x0000000188069f70 UIApplicationMain + 204
21 myApp 0x000000010013dd3c main + 124
22 libdyld.dylib 0x000000018293a8b8 <redacted> + 4)
2016-04-14 15:16:49.700 myApp[1130:240689] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GMSMutablePath setMap:]: unrecognized selector sent to instance 0x1540bb560'
*** First throw call stack:
(0x182ebee38 0x182523f80 0x182ec5ccc 0x182ec2c74 0x182dc0d1c 0x1001115a0
0x10012c944 0x182ec4ae0 0x182dbc548 0x182dc0e70 0x100203370 0x182ec2aa4
0x182dc0d1c 0x100188fec 0x183893ffc 0x182e75124 0x182e74bb8 0x182e728b8
0x182d9cd10 0x184684088 0x188069f70 0x10013dd3c 0x18293a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
I am stunned now.
The initial initialization works fine, the Polygons are drawn as the should, but as soon as I call the function to redraw the polygons, the crash happens.. and strange enough now I see why it crashes, but I don't understand.. It changes the first 5 array entry's to GMSMutablePath and GMSPolyLine , instead of GMSPolygon ?!, see link to picture below.. And have no idea why, because I am 100% sure the array of GMSPolygon is not touched anywhere else in the mean time..
Picture of of change in Array type
I can't post a comment yet due to my reputation. Just like what Dan said, use NSArray or NSMutableArray to store your objects. Then do your stuff.
UPDATE:
Here are my suggestions:
Add All Exceptions to your breakpoint navigator.
Try testing your code without loop.
Try adding float values as your coordinates.
See example code below:
GMSMutablePath *prettyPoly = [GMSMutablePath path];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.506191, 1.83197)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.05249, 1.650696)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(51.92225, 1.321106)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(51.996719, 1.219482)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.049112, 1.244202)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.197507, 1.334839)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.519564, 1.801758)];
GMSPolygon *polygon = [GMSPolygon polygonWithPath: prettyPoly];
polygon.fillColor = [UIColor colorWithRed:0 green:0.25 blue:0 alpha:0.3];
polygon.strokeColor = [UIColor greenColor];
polygon.strokeWidth = 5;
polygon.map = self.googleMap;
If everything failed:
- Refer to this doc: https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_polygon#properties
How about you try Polyline class and see this example: https://developers.google.com/maps/documentation/ios-sdk/shapes#add_a_polyline
Last, try seeking help from Google Forum, or from the repo of that library you are using.

How to map a local JSON string into an object using RestKit 0.24 with RKObjectMapping?

I am trying to map a JSON NSString into an object using RestKit 0.24.0 where I have a RKObjectMapping as well as the corresponding dictionary.
Most of the solutions online refer to RestKit 0.22 and below.
Some of the solutions on SO result into app crash.
What is the easiest way to convert a local string into an object. Consider the following
CODE UPDATE
RKMapperOperation *mapper = [[RKMapperOperation alloc] initWithRepresentation:parsedData mappingsDictionary:[RJobObject mappingDictionary]];
RJobObject * rrrr = [[RJobObject alloc] init];
mapper.targetObject = rrrr;
//mapper.mappingOperationDataSource = parsedData;
[mapper execute:nil];
Here , mappingDictionary is basically the key-value pair matching between the JSON key and Object variable name
So in the above code whenever I run execute, the app crashes.
Stack Trace
2015-11-22 09:12:29.193 Help[22427:699579] -[__NSCFConstantString forceCollectionMapping]: unrecognized selector sent to instance 0x1022736a0
2015-11-22 09:12:29.211 Help[22427:699579] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString forceCollectionMapping]: unrecognized selector sent to instance 0x1022736a0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105d7dc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000105a14bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000105d850ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x0000000105cdb13c ___forwarding___ + 988
4 CoreFoundation 0x0000000105cdacd8 _CF_forwarding_prep_0 + 120
5 Help 0x000000010212f424 -[RKMapperOperation mapRepresentationOrRepresentations:atKeyPath:usingMapping:] + 132
6 Help 0x000000010212fe97 -[RKMapperOperation mapSourceRepresentationWithMappingsDictionary:] + 1959
7 Help 0x00000001021307a2 -[RKMapperOperation main] + 1330
8 Foundation 0x00000001034c4774 -[__NSOperationInternal _start:] + 645
9 Help 0x00000001021310b7 -[RKMapperOperation execute:] + 39
10 Help 0x0000000101f62f8e -[AppDelegate fetchJobsFromDB] + 1102
More Details
Updated to RestKit 0.26.0 , am still facing the issue.
Basically in RKMapperOperation.m, line 333 a po mapping.forceCollectionMapping gives an error and it crashed the app.
ANSWER : Sample Solution
Use RKMappingOperation , as we do not have to specify the keyPath
RJobObject * rrrJob = [RJobObject new];
RKMappingOperation *mappingOperation = [[RKMappingOperation alloc] initWithSourceObject:jobEntity.dictionary destinationObject:rrrJob mapping:[RJobObject mapping]];
mappingOperation.dataSource = (id)rrrJob;
[mappingOperation start];
For what you're trying to do 'parsedData' should be a dictionary or array that has been deserialised from the JSON string, and [RJobObject mappingDictionary] should be a dictionary where the keys are the source key paths and the values are RKMapping Instances defining what to do with the contents.
The idea is that the key paths determine how to drill into the JSON data and the mapping determines how to process the content found there. Your key path might be an empty string if you want to process the whole JSON data.
You might consider using RKMappingOperation instead if you want to avoid the key path complexity and you're mapping the whole JSON into a single target object.

NSMutableData appendBytes is setting length to -1 and crashing

I'm getting a rare and intermittent crash which looks like appendBytes being called with -1 as it's length.
now, I've hard coded the "length" argument every time I've used this method so I can't see how this could happen and worse still I can't see how I could test for and avoid this crash.
here's the top of the stack and the exception (note the ~4.2b length):
*** Terminating app due to uncaught exception 'NSMallocException', reason: '*** -[NSConcreteMutableData appendBytes:length:]: unable to allocate memory for length (4294967295)'
*** Call stack at first throw:
(
0 CoreFoundation 0x91ec5a67 __raiseError + 231
1 libobjc.A.dylib 0x9950a149 objc_exception_throw + 155
2 CoreFoundation 0x91e2d289 +[NSException raise:format:arguments:] + 137
3 CoreFoundation 0x91e2d1f9 +[NSException raise:format:] + 57
4 Foundation 0x92d2489e _NSMutableDataGrowBytes + 1136
5 Foundation 0x92d24391 -[NSConcreteMutableData appendBytes:length:] + 354
here's a simplified version of the code that's supposedly crashing:
if (self.isConnectedToService) {
NSMutableData *myData = [NSMutableData data];
float newValue = PanValue;
const char theTwo[] = {(char)Chan_L, (char)PanParam};
[myData appendBytes:&theTwo length:2];
[myData appendBytes:&newValue length:4];
}
So length is always 2 or 4.
I've tested different situations in which the buffers contain more or less than 2 and 4 and I've never managed to cause this crash intentionally.
I've got the same code running on both MacOS10.7.4 and iOS6.0(on iPad3) and see this issue occasionally on both platforms.
so how is appendBytes getting that bogus value?

NSArray exception when adding track to starred playlist

Sometimes, I'm getting a fatal exception when trying to "star" a track in cocoalibspotify. I'm logging in with a user with a heavy dataset (hundreds of playlists, but < 15 starred tracks).
This is how I "star" the SPTrack:
[[[[SPSession sharedSession] starredPlaylist] items] addObject:myTrack];
... and the stack trace:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSArray objectsAtIndexes:]: index 12 beyond bounds [0 .. 11]'
*** Call stack at first throw:
(
0 CoreFoundation 0x01e125a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x021a1313 objc_exception_throw + 44
2 CoreFoundation 0x01da0f99 -[NSArray objectsAtIndexes:] + 633
3 Foundation 0x016a250b -[NSKeyValueArray objectsAtIndexes:] + 110
4 Foundation 0x016aaca6 NSKeyValueDidChangeByArrayMutation + 103
5 Foundation 0x01610c30 NSKeyValueDidChange + 266
6 Foundation 0x016aba95 -[NSObject(NSKeyValueObserverNotification) didChange:valuesAtIndexes:forKey:] + 123
7 Foundation 0x016a4d0e -[NSKeyValueNotifyingMutableArray addObject:] + 239
8 MyApp 0x000922cd -[PlaylistManager starTrack:] + 285
...
This only seems to happen within a minute or two after logging in (i.e. user data is loaded), so I'm guessing it might be an issue where the data isn't fully loaded or something?
I've tried to find out if there's any properties to observe in order to find out when everything's fully loaded. But as the array might be empty (and the user might not have starred any tracks before), it seems like there's no good way of validating that everything's loaded...? The loaded property of SPPlaylist seems to refer to the playlist metadata, and not its tracks (?).
Any ideas?
You are getting the So it looks like you're not supposed to manipulate that array directly. Instead call [myTrack setStarred:YES];
Basically, I just went through the entire Spotify API for you to find that answer.
A full code sample for this:
-(void)starTrack:(NSString *)uri {
NSURL *trackURL = [NSURL URLWithString:uri];
[[SPSession sharedSession] trackForURL:trackURL callback:^(SPTrack *track) {
if (track != nil) {
[SPAsyncLoading waitUntilLoaded:track timeout:kSPAsyncLoadingDefaultTimeout then:^(NSArray *tracks, NSArray *notLoadedTracks) {
[track setStarred:YES];
}];
}
}];
}

Resources