Converting an array containing structure to json - arrays

I'm trying to convert an array into json but can't get it to work. It says the array is an invalid type to convert to json, but it's just an array of ints.
//These are for me to able to use time
let date = NSDate()
let calendar = NSCalendar.current
//This is the structure that my array will be filled with
struct Day
{
var week: Int?
var date: Int?
var month: Int?
var year: Int?
var weekday: Int?
}
//This is my array
var theArrayContainingAllTheUserData = [Day]()
var numberofloops = 0
//This is a loop that fills my array with data
while theArrayContainingAllTheUserData.count < 20
{
var theincreasingnumberofdays: NSDate {
return NSCalendar.current.date(byAdding: .day, value: numberofloops, to: NSDate() as Date)! as NSDate
}
let myCalendar = NSCalendar(calendarIdentifier: NSCalendar.Identifier.gregorian)!
numberofloops=numberofloops+1
var ScoopDay = Day()
ScoopDay.week=Int(myCalendar.component(.weekOfYear, from: theincreasingnumberofdays as Date!))
ScoopDay.date=Int(myCalendar.component(.day, from: theincreasingnumberofdays as Date!))
ScoopDay.month=Int(myCalendar.component(.month, from: theincreasingnumberofdays as Date!))
ScoopDay.year=Int(myCalendar.component(.year, from: theincreasingnumberofdays as Date!))
ScoopDay.weekday=Int(myCalendar.component(.weekday, from: theincreasingnumberofdays as Date!))
theArrayContainingAllTheUserData.append(ScoopDay)
}
//And here is my failed attempt at converting it to json
do {
let jsonData = try JSONSerialization.data(withJSONObject: theArrayContainingAllTheUserData, options: JSONSerialization.WritingOptions.prettyPrinted)
} catch {
print(error.localizedDescription)
}
Getting Error:
2016-10-28 13:20:09.669 jsona arrayen[3284:332873] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (_SwiftValue)'
First throw call stack:
(
0 CoreFoundation 0x000000010840834b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000107e6921e objc_exception_throw + 48
2 CoreFoundation 0x0000000108471265 +[NSException raise:format:] + 197
3 Foundation 0x000000010795d284 _writeJSONValue + 668
4 Foundation 0x000000010795d6d9 ___writeJSONArray_block_invoke + 132
5 CoreFoundation 0x00000001083ae36f __NSArrayEnumerate + 607
6 Foundation 0x000000010795d3df _writeJSONArray + 330
7 Foundation 0x000000010795d204 _writeJSONValue + 540
8 Foundation 0x000000010795cf94 -[_NSJSONWriter dataWithRootObject:options:error:] + 124
9 Foundation 0x000000010795ce74 +[NSJSONSerialization dataWithJSONObject:options:error:] + 333
10 ??? 0x0000000116ddd3cb 0x0 + 4678603723
11 jsona arrayen 0x0000000107892620 main + 0
12 CoreFoundation 0x00000001083ad25c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
13 CoreFoundation 0x0000000108392304 __CFRunLoopDoBlocks + 356
14 CoreFoundation 0x0000000108391a75 __CFRunLoopRun + 901
15 CoreFoundation 0x0000000108391494 CFRunLoopRunSpecific + 420
16 GraphicsServices 0x000000010d796a6f GSEventRunModal + 161
17 UIKit 0x0000000108f3bf34 UIApplicationMain + 159
18 jsona arrayen 0x00000001078926e9 main + 201
19 libdyld.dylib 0x000000010b8e968d start + 1
20 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Related

SwiftUI Crash in ForEach Loop

ScrollView(.horizontal, showsIndicators: false, content: {
LazyHGrid(rows: gridLayout2, alignment: .center, spacing: columnSpacing, pinnedViews: [], content: {
Section(
header: SectionView(rotateClockwise: false, headerText: "Premium Store"),
footer: SectionView(rotateClockwise: true, headerText: "Premium Store")) {
ForEach(premiumStoreItems) { item in
StoreItemView(storeItem: item)
}
}
}) //: LAZYHGRID
.frame(height: 200)
.padding(15)
})
The crash is occurring in the ForEach loop.
If I comment the ForEach and pass in 1 specific item from my array, it works fine. However I need to display all my items in my array.
I am not sure what to do here.
The following code works fine.
//ForEach(premiumStoreItems) { item in
StoreItemView(storeItem: premiumStoreItems[0])
//}
CRASH LOG (sorry I didnt know where to get it)
Application Specific Information:
Fatal error: each layout item may only occur once: file SwiftUI, line 0
------ FULL CRASH LOG
Process: AppExample001 [3525]
Path: /Users/USER/Library/Developer/Xcode/UserData/Previews/Simulator Devices/C93C2BE8-C23A-4813-9D6C-110E87786FFE/data/Containers/Bundle/Application/40562FF7-7B66-4BE4-915A-5A2A35AD3EC2/AppExample001.app/AppExample001
Identifier: AppExample001
Version: 1.0 (1)
Code Type: X86-64 (Native)
Parent Process: launchd_sim [2488]
Responsible: SimulatorTrampoline [611]
User ID: 501
Date/Time: 2021-04-07 12:23:50.173 -0400
OS Version: macOS 11.2.3 (20D91)
Report Version: 12
Bridge OS Version: 5.2 (18P4347)
Anonymous UUID: 5A68DF80-DD1B-1132-4597-BBC26C334627
Time Awake Since Boot: 7000 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_INSTRUCTION (SIGILL)
Exception Codes: 0x0000000000000001, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Illegal instruction: 4
Termination Reason: Namespace SIGNAL, Code 0x4
Terminating Process: exc handler [3525]
ID Vend/Dev
95f5 687f1002
Seconds Ago ID Type
6900.0 95f5 Attach
Application Specific Information:
Fatal error: each layout item may only occur once: file SwiftUI, line 0
CoreSimulator 732.18.6 - Device: iPhone SE (2nd generation) (C93C2BE8-C23A-4813-9D6C-110E87786FFE) - Runtime: iOS 14.4 (18D46) - DeviceType: iPhone SE (2nd generation)
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libswiftCore.dylib 0x00007fff2fc85004 assertionFailure(::file:line:flags:) + 532
1 com.apple.SwiftUI 0x00007fff572e9d24 ViewCache.commitPlacedChildren(from:to:) + 4020
2 com.apple.SwiftUI 0x00007fff571a1f16 specialized IncrementalChildPlacements.updateValue() + 1558
3 com.apple.SwiftUI 0x00007fff572be37f partial apply for specialized implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init(:) + 15
4 com.apple.AttributeGraph 0x00007fff4cd78723 AG::Graph::UpdateStack::update() + 505
5 com.apple.AttributeGraph 0x00007fff4cd78bb9 AG::Graph::update_attribute(AG::data::ptr<AG::Node>, bool) + 335
6 com.apple.AttributeGraph 0x00007fff4cd7d85f AG::Graph::input_value_ref_slow(AG::data::ptr<AG::Node>, AG::AttributeID, unsigned int, AGSwiftMetadata const*, bool*, long) + 523
7 com.apple.AttributeGraph 0x00007fff4cd8edc5 AGGraphGetValue + 203
8 com.apple.SwiftUI 0x00007fff572edac0 IncrementalPreference.children.getter + 48
9 com.apple.SwiftUI 0x00007fff572edb95 IncrementalPreference.value.getter + 85
10 com.apple.SwiftUI 0x00007fff572ede1c protocol witness for Rule.value.getter in conformance IncrementalPreference + 28
11 com.apple.AttributeGraph 0x00007fff4cd91907 dispatch thunk of Rule.value.getter + 7
12 com.apple.SwiftUI 0x00007fff570e9a18 implicit closure #2 in implicit closure #1 in closure #1 in closure #1 in Attribute.init(_:) + 56
13 com.apple.AttributeGraph 0x00007fff4cd78723 AG::Graph::UpdateStack::update() + 505
14 com.apple.AttributeGraph 0x00007fff4cd78bb9 AG::Graph::update_attribute(AG::data::ptr<AG::Node>, bool) + 335
15 com.apple.AttributeGraph 0x00007fff4cd7d318 AG::Graph::value_ref(AG::AttributeID, AGSwiftMetadata const*, bool*) + 130
16 com.apple.AttributeGraph 0x00007fff4cd8ee13 AGGraphGetValue + 281
17 com.apple.SwiftUI 0x00007fff57987807 GraphHost.updatePreferences() + 39
18 com.apple.SwiftUI 0x00007fff57458cbf ViewGraph.updateOutputs(at:) + 95
19 com.apple.SwiftUI 0x00007fff573f04e4 specialized closure #1 in ViewRendererHost.render(interval:updateDisplayList:) + 1316
20 com.apple.SwiftUI 0x00007fff573ed28e specialized ViewRendererHost.render(interval:updateDisplayList:) + 366
21 com.apple.SwiftUI 0x00007fff57a59c0e specialized UIHostingController._render(seconds:) + 46
22 com.apple.dt.XCPreviewKit 0x000000010c117536 0x10c10a000 + 54582
23 com.apple.dt.XCPreviewKit 0x000000010c1246eb 0x10c10a000 + 108267
24 com.apple.dt.XCPreviewKit 0x000000010c11b91f 0x10c10a000 + 71967
25 com.apple.dt.XCPreviewKit 0x000000010c11bc08 0x10c10a000 + 72712
26 com.apple.dt.XCPreviewKit 0x000000010c11ddff 0x10c10a000 + 81407
27 com.apple.dt.XCPreviewKit 0x000000010c11c274 0x10c10a000 + 74356
28 com.apple.dt.XCPreviewKit 0x000000010c1134e3 0x10c10a000 + 38115
29 com.apple.dt.XCPreviewKit 0x000000010c112eee 0x10c10a000 + 36590
30 libdispatch.dylib 0x00007fff2010532f _dispatch_call_block_and_release + 12
31 libdispatch.dylib 0x00007fff20106508 _dispatch_client_callout + 8
32 libdispatch.dylib 0x00007fff20112ff7 dispatch_main_queue_callback_4CF + 1045
33 com.apple.CoreFoundation 0x00007fff2038fdbb CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9
34 com.apple.CoreFoundation 0x00007fff2038a63e __CFRunLoopRun + 2685
35 com.apple.CoreFoundation 0x00007fff203896d6 CFRunLoopRunSpecific + 567
36 com.apple.GraphicsServices 0x00007fff2c257db3 GSEventRunModal + 139
37 com.apple.UIKitCore 0x00007fff24696cf7 -[UIApplication run] + 912
38 com.apple.UIKitCore 0x00007fff2469bba8 UIApplicationMain + 101
39 com.apple.SwiftUI 0x00007fff5791abc7 closure #1 in KitRendererCommon(:) + 119
40 com.apple.SwiftUI 0x00007fff5791ab3f runApp(:) + 143
41 com.apple.SwiftUI 0x00007fff5745212d static App.main() + 61
42 com.oneorangetree.AppExample001 0x000000010bfcaf4e static AppExample001App.$main() + 78
43 com.oneorangetree.AppExample001 0x000000010bfcafd4 main + 20
44 libdyld.dylib 0x00007fff2025a3e9 start + 1
ForEach is unable to identify the each item uniquely,
make sure your data model struct is confirm to identifiable protocol
try this on
ForEach(premiumStoreItems, id:\.self)
ForEach(premiumStoreItems, id:\.id) // if you've unique identifier with the name of "id"

Unusual Error appending new element to an array resulting in application crash

I am fetching a list of items from an API. This works fine. I have a local variable in my view controller such that upon successfully fetch of the items from API, I am reloading my table view.
Recently in the line where I am appending contents of the array from API to my local array variable, I am now getting a crash. I have research severally on SO with no success. I keep getting the thesame error
This is code causing the crash
Irrelevant API fetch code
if refresh {
self?.items = ticketItems
}
else {
self?.ticketItems.append(contentsOf:
ticketItems)
}
Usually, I should not get a crash when appending the contents of an array. This is weird to me. Please Find error message:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: !CGSizeEqualToSize(size, CGSizeZero)'
*** First throw call stack:
(
0 CoreFoundation 0x0000000116bb86fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x00000001157adac5 objc_exception_throw + 48
2 CoreFoundation 0x0000000116bb8482 +[NSException raise:format:arguments:] + 98
3 Foundation 0x000000010fe51927 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 194
4 UIKitCore 0x000000011e0f0399 -[_UIUpdateVisibleCellsContext addSize:forIndexPath:] + 385
5 UIKitCore 0x000000011e0e8643 -[UICollectionViewFlowLayout shouldInvalidateLayoutForPreferredLayoutAttributes:withOriginalAttributes:] + 409
6 UIKitCore 0x000000011e0a2f08 -[UICollectionView _checkForPreferredAttributesInView:originalAttributes:] + 559
7 UIKitCore 0x000000011e0a3c24 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:isFocused:notify:] + 1596
8 UIKitCore 0x000000011e0a35e2 -[UICollectionView _createPreparedCellForItemAtIndexPath:withLayoutAttributes:applyAttributes:] + 31
9 UIKitCore 0x000000011e0a8a8c -[UICollectionView _updateVisibleCellsNow:] + 6120
10 UIKitCore 0x000000011e0adbb6 -[UICollectionView layoutSubviews] + 365
11 UIKitCore 0x000000011ecf99c1 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1417
12 QuartzCore 0x0000000111cf7eae -[CALayer layoutSublayers] + 173
13 QuartzCore 0x0000000111cfcb88 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 396
14 QuartzCore 0x0000000111d08ee4 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 72
15 QuartzCore 0x0000000111c783aa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 328
16 QuartzCore 0x0000000111caf584 _ZN2CA11Transaction6commitEv + 608
17 QuartzCore 0x0000000111cafede _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 76
18 CoreFoundation 0x0000000116b1f0f7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
19 CoreFoundation 0x0000000116b195be __CFRunLoopDoObservers + 430
20 CoreFoundation 0x0000000116b19c31 __CFRunLoopRun + 1505
21 CoreFoundation 0x0000000116b19302 CFRunLoopRunSpecific + 626
22 GraphicsServices 0x000000011be162fe GSEventRunModal + 65
23 UIKitCore 0x000000011e82bba2 UIApplicationMain + 140
24 Sterling Bank App 0x000000010c1be211 main + 225
25 libdyld.dylib 0x0000000118307541 start + 1
26 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I was getting the exact error:
'Invalid parameter not satisfying: !CGSizeEqualToSize(size, CGSizeZero)'
It was just because I forgot to set translatesAutoresizingMaskIntoConstraints to false for a subview I was adding to cell's contentView...

Swift 3 - Core Data - create object

So I am trying to fetch my data from my core data database, put it into objects and then into an array which I then callback.
func getCoffeeBrandsFromDB(callback: #escaping (_ dbCoffeeBrands: Array<Any>)-> ()) {
//create a fetch request, telling it about the entity
print("running getCBFDB")
var coffeeBrandArray = Array<Any>()
let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "CoffeeBrand")
do {
let searchResults = try getContext().fetch(fetchRequest)
print ("num of results = \(searchResults.count)")
for brands in searchResults as! [NSManagedObject] {
let brand = CoffeeBrand()
brand.dataBaseId = brands.value(forKey: "dataBaseId") as! Int64
brand.brandName = brands.value(forKey: "brandName") as? String
brand.numberOfCoffeesNeeded = brands.value(forKey: "numberOfCoffeesNeeded") as! Int32
coffeeBrandArray.append(brand)
print("brands virker med \(brand.brandName!)")
}
print("CcffeeBrandArray.count is: \(coffeeBrandArray.count)")
callback(coffeeBrandArray)
} catch {
print("Error with request: \(error)")
}
}
When I run getCoffeeBrandsFromDB I get this errorlog:
running getCBFDB
num of results = 4
2017-02-08 15:47:02.179211 Keebin_development_1[8373:626945] [error] error: CoreData: error: Failed to call designated initializer on NSManagedObject class 'CoffeeBrand'
CoreData: error: CoreData: error: Failed to call designated initializer on NSManagedObject class 'CoffeeBrand'
2017-02-08 15:47:02.180 Keebin_development_1[8373:626945] -[CoffeeBrand setDataBaseId:]: unrecognized selector sent to instance 0x608000279e80
2017-02-08 15:47:02.189 Keebin_development_1[8373:626945] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CoffeeBrand setDataBaseId:]: unrecognized selector sent to instance 0x608000279e80'
*** First throw call stack:
(
0 CoreFoundation 0x0000000110c36d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011027721e objc_exception_throw + 48
2 CoreFoundation 0x0000000110ca6f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000110bbc005 ___forwarding___ + 1013
4 CoreFoundation 0x0000000110bbbb88 _CF_forwarding_prep_0 + 120
5 Keebin_development_1 0x000000010fc20e5c _TF20Keebin_development_121getCoffeeBrandsFromDBFT8callbackFGSaP__T__T_ + 1804
6 Keebin_development_1 0x000000010fc2d314 _TFC20Keebin_development_126LoyaltyCardsViewController11viewDidLoadfT_T_ + 180
7 Keebin_development_1 0x000000010fc2d5e2 _TToFC20Keebin_development_126LoyaltyCardsViewController11viewDidLoadfT_T_ + 34
8 UIKit 0x00000001111fca3d -[UIViewController loadViewIfRequired] + 1258
9 UIKit 0x000000011123d28f -[UINavigationController _layoutViewController:] + 55
10 UIKit 0x000000011123db77 -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 471
11 UIKit 0x000000011123dcee -[UINavigationController _startTransition:fromViewController:toViewController:] + 133
12 UIKit 0x000000011123eef9 -[UINavigationController _startDeferredTransitionIfNeeded:] + 874
13 UIKit 0x000000011123ffdb -[UINavigationController __viewWillLayoutSubviews] + 58
14 UIKit 0x0000000111436dd7 -[UILayoutContainerView layoutSubviews] + 223
15 UIKit 0x000000011111fab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
16 QuartzCore 0x00000001161ffbf8 -[CALayer layoutSublayers] + 146
17 QuartzCore 0x00000001161f3440 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
18 QuartzCore 0x00000001161f32be _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
19 QuartzCore 0x0000000116181318 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
20 QuartzCore 0x00000001161ae3ff _ZN2CA11Transaction6commitEv + 475
21 UIKit 0x0000000111053d9b _UIApplicationFlushRunLoopCATransactionIfTooLate + 206
22 UIKit 0x000000011185e77c __handleEventQueue + 5672
23 CoreFoundation 0x0000000110bdb761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
24 CoreFoundation 0x0000000110bc098c __CFRunLoopDoSources0 + 556
25 CoreFoundation 0x0000000110bbfe76 __CFRunLoopRun + 918
26 CoreFoundation 0x0000000110bbf884 CFRunLoopRunSpecific + 420
27 GraphicsServices 0x00000001152f9a6f GSEventRunModal + 161
28 UIKit 0x000000011105ac68 UIApplicationMain + 159
29 Keebin_development_1 0x000000010fc3fe5f main + 111
30 libdyld.dylib 0x000000011434d68d start + 1
31 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I can't seem to figure out where my problem is. I have created my CoffeeBrand+CoreDataClass.Swift and CoffeeBrand+CoreDataProperties.Swift with the editor-> create NSManaged Object Subclass and as other SO questions/answered has said with the codegen to manual/none.
The two classes mentioned:
import Foundation
import CoreData
#objc(CoffeeBrand)
public class CoffeeBrand: NSManagedObject {
}
and:
import Foundation
import CoreData
extension CoffeeBrand {
#nonobjc public class func fetchRequest() -> NSFetchRequest<CoffeeBrand> {
return NSFetchRequest<CoffeeBrand>(entityName: "CoffeeBrand");
}
#NSManaged public var brandName: String?
#NSManaged public var dataBaseId: Int64
#NSManaged public var id: Int64
#NSManaged public var numberOfCoffeesNeeded: Int32
}
Can someone see where I'm going wrong? Obviously it's in my for-loop but I don't know where/what/how to do it right.
Thanks in advance!
I figured out where I went wrong.
I changed let fetchRequest: NSFetchRequest<NSFetchRequestResult> = NSFetchRequest(entityName: "CoffeeBrand")
to
let fetchRequest: NSFetchRequest<NSManagedObject> = NSFetchRequest(entityName: "CoffeeBrand")
this way it is objects I fetch from the DB.
Then it was easy. Now my for-loop is simply:
for brands in searchResults {
coffeeBrandArray.append(brands)
}
callback(coffeeBrandArray)
} catch {
print("Error with request: \(error)")
}
}
And now everything works as it should.

Swift: Read and write binary data (cookies) to disk?

Specifically I want the command line utility to write the data from NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies to a file and then read the data so I can later call NSHTTPCookieStorage.sharedHTTPCookieStorage().setCookie()
Here's the code I have so far.
if (Process.arguments.count >= 2 && Process.arguments[1] == "-deleteAll") {
for cookie in NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies! {
NSHTTPCookieStorage.sharedHTTPCookieStorage().deleteCookie(cookie as NSHTTPCookie)
}
} else if (Process.arguments.count >= 3 && Process.arguments[1] == "-restore") {
println("restore from file: " + Process.arguments[2])
} else if (Process.arguments.count >= 3 && Process.arguments[1] == "-export") {
println("export to file: " + Process.arguments[2])
}
The lines
for cookie in NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies! {
cookie.writeToFile("/Users/aaron/Documents/test.txt", options: nil, error: nil)
}
give me an error:
2014-12-30 20:20:46.564 Test[17423:424845] -[NSHTTPCookie writeToFile:options:error:]: unrecognized selector sent to instance 0x100511260
2014-12-30 20:20:46.579 Test[17423:424845] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSHTTPCookie writeToFile:options:error:]: unrecognized selector sent to instance 0x100511260'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff950fc64c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff97e556de objc_exception_throw + 43
2 CoreFoundation 0x00007fff950ff6bd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff95046a84 ___forwarding___ + 1028
4 CoreFoundation 0x00007fff950465f8 _CF_forwarding_prep_0 + 120
5 Test 0x00000001001caa1f top_level_code + 991
6 Test 0x00000001001caa9a main + 42
7 libdyld.dylib 0x00007fff918fd5c9 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I guess this is under the category of writing generic data to disk.

AngularJS Safari crash EXC_BAD_ACCESS (SIGSEGV)

this is about an AngularJS app crashing Safari.The app crashes Safari on randomly on desktop and iPad. I understand that something is calling a non-existing record in memory. How can I trace that log to JavaScript / HTML / CSS actions?
Below is the output from Safari error report. I found that calls 22 and 44 in the thread that crashed look somewhat different than the others. I removed the reports for the threads that didn't crash. I also removed the thread state (it exceeded the character limit).
Process: WebProcess [44604]
Path: /System/Library/PrivateFrameworks/WebKit2.framework/WebProcess.app/Contents/MacOS/WebProcess
Identifier: com.apple.WebProcess
Version: 8536 (8536.30.1)
Build Info: WebKit2-7536030001000000~9
Code Type: X86-64 (Native)
Parent Process: ??? [1]
User ID: 502
Date/Time: 2014-10-07 11:20:38.251 +0100
OS Version: Mac OS X 10.8.5 (12F45)
Report Version: 10
Interval Since Last Report: 5675572 sec
Crashes Since Last Report: 18
Per-App Interval Since Last Report: 412893 sec
Per-App Crashes Since Last Report: 8
Anonymous UUID: [xxx removed]
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
VM Regions Near 0:
-->
__TEXT 0000000100a14000-0000000100a15000 [ 4K] r-x/rwx SM=COW /System/Library/PrivateFrameworks/WebKit2.framework/WebProcess.app/Contents/MacOS/WebProcess
Application Specific Information:
Bundle controller class:
BrowserBundleController
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.apple.WebCore 0x00007fff83c98a19 WebCore::Length::incrementCalculatedRef() const + 25
1 com.apple.WebCore 0x00007fff838ec186 bool compareEqual<WebCore::Length, WebCore::Length>(WebCore::Length const&, WebCore::Length const&) + 70
2 com.apple.WebCore 0x00007fff8339aa01 WebCore::RenderStyle::setPaddingLeft(WebCore::Length) + 33
3 com.apple.WebCore 0x00007fff8347242b WebCore::PropertyWrapper<WebCore::Length>::blend(WebCore::AnimationBase const*, WebCore::RenderStyle*, WebCore::RenderStyle const*, WebCore::RenderStyle const*, double) const + 155
4 com.apple.WebCore 0x00007fff83ef8b2b WebCore::CSSPropertyAnimation::blendProperties(WebCore::AnimationBase const*, WebCore::CSSPropertyID, WebCore::RenderStyle*, WebCore::RenderStyle const*, WebCore::RenderStyle const*, double) + 123
5 com.apple.WebCore 0x00007fff83473079 WebCore::ImplicitAnimation::animate(WebCore::CompositeAnimation*, WebCore::RenderObject*, WebCore::RenderStyle const*, WebCore::RenderStyle*, WTF::RefPtr<WebCore::RenderStyle>&) + 233
6 com.apple.WebCore 0x00007fff8346bfe0 WebCore::CompositeAnimation::animate(WebCore::RenderObject*, WebCore::RenderStyle*, WebCore::RenderStyle*) + 208
7 com.apple.WebCore 0x00007fff8333b7df WebCore::AnimationController::updateAnimations(WebCore::RenderObject*, WebCore::RenderStyle*) + 239
8 com.apple.WebCore 0x00007fff8333b6d0 WebCore::RenderObject::setAnimatableStyle(WTF::PassRefPtr<WebCore::RenderStyle>) + 144
9 com.apple.WebCore 0x00007fff83348d16 WebCore::Node::setRenderStyle(WTF::PassRefPtr<WebCore::RenderStyle>) + 38
10 com.apple.WebCore 0x00007fff83348606 WebCore::Element::recalcStyle(WebCore::Node::StyleChange) + 854
11 com.apple.WebCore 0x00007fff833489a2 WebCore::Element::recalcStyle(WebCore::Node::StyleChange) + 1778
12 com.apple.WebCore 0x00007fff833489a2 WebCore::Element::recalcStyle(WebCore::Node::StyleChange) + 1778
13 com.apple.WebCore 0x00007fff833489a2 WebCore::Element::recalcStyle(WebCore::Node::StyleChange) + 1778
14 com.apple.WebCore 0x00007fff8331805f WebCore::Document::recalcStyle(WebCore::Node::StyleChange) + 559
15 com.apple.WebCore 0x00007fff833420c3 WebCore::Document::updateStyleIfNeeded() + 67
16 com.apple.WebCore 0x00007fff8334dcb7 WebCore::Document::updateLayout() + 55
17 com.apple.WebCore 0x00007fff8334dc65 WebCore::Document::updateLayoutIgnorePendingStylesheets() + 133
18 com.apple.WebCore 0x00007fff838851d7 WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue(WebCore::CSSPropertyID, WebCore::EUpdateLayout) const + 71
19 com.apple.WebCore 0x00007fff83898a56 WebCore::CSSComputedStyleDeclaration::getPropertyCSSValueInternal(WebCore::CSSPropertyID) + 22
20 com.apple.WebCore 0x00007fff83b3400c WebCore::cssPropertyGetter(JSC::ExecState*, WebCore::JSCSSStyleDeclaration*, unsigned int) + 44
21 com.apple.JavaScriptCore 0x00007fff8ce06cbe cti_op_get_by_val + 942
22 ??? 0x0000000100ef9d7f 0 + 4310670719
23 com.apple.JavaScriptCore 0x00007fff8cde1d70 JSC::Interpreter::executeCall(JSC::ExecState*, JSC::JSObject*, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 912
24 com.apple.JavaScriptCore 0x00007fff8cde19d4 JSC::call(JSC::ExecState*, JSC::JSValue, JSC::CallType, JSC::CallData const&, JSC::JSValue, JSC::ArgList const&) + 52
25 com.apple.WebCore 0x00007fff83b240a1 WebCore::JSCallbackData::invokeCallback(JSC::JSValue, JSC::MarkedArgumentBuffer&, bool*) + 593
26 com.apple.WebCore 0x00007fff83be0383 WebCore::JSRequestAnimationFrameCallback::handleEvent(unsigned long long) + 275
27 com.apple.WebCore 0x00007fff83d8270b WebCore::ScriptedAnimationController::serviceScriptedAnimations(unsigned long long) + 203
28 com.apple.WebCore 0x00007fff838e1d9d WebCore::DisplayRefreshMonitor::notifyClients() + 93
29 com.apple.JavaScriptCore 0x00007fff8cdcba3a WTF::dispatchFunctionsFromMainThread() + 266
30 com.apple.Foundation 0x00007fff8939d5ca __NSThreadPerformPerform + 225
31 com.apple.CoreFoundation 0x00007fff8a882b31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
32 com.apple.CoreFoundation 0x00007fff8a88251d __CFRunLoopDoSources0 + 445
33 com.apple.CoreFoundation 0x00007fff8a8a57f5 __CFRunLoopRun + 789
34 com.apple.CoreFoundation 0x00007fff8a8a50e2 CFRunLoopRunSpecific + 290
35 com.apple.HIToolbox 0x00007fff8c823eb4 RunCurrentEventLoopInMode + 209
36 com.apple.HIToolbox 0x00007fff8c823c52 ReceiveNextEventCommon + 356
37 com.apple.HIToolbox 0x00007fff8c823ae3 BlockUntilNextEventMatchingListInMode + 62
38 com.apple.AppKit 0x00007fff8d4ce533 _DPSNextEvent + 685
39 com.apple.AppKit 0x00007fff8d4cddf2 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 128
40 com.apple.AppKit 0x00007fff8d4c51a3 -[NSApplication run] + 517
41 com.apple.WebCore 0x00007fff83d7a4ff WebCore::RunLoop::run() + 63
42 com.apple.WebKit2 0x00007fff89fe1462 WebKit::WebProcessMain(WebKit::CommandLine const&) + 2586
43 com.apple.WebKit2 0x00007fff89fa7bfd WebKitMain + 285
44 com.apple.WebProcess 0x0000000100a14e7b 0x100a14000 + 3707
45 libdyld.dylib 0x00007fff853717e1 start + 1
What version of Safari are you seeing this on? And does it happen with Dev tools open or closed?
Safari 7.0.1 is buggy, I'm betting upgrading to a later version will fix it.
See: https://github.com/angular/angularjs.org/issues/70

Resources