My problem is the following: I want to generate a data matrix with ZXingObjC and show it.
Currently i'm writing an application with XCode 7.3 and Swift 2.have to generate a data matrix with a String value. As the ZXingObjC written in Objective C, i tried to convert it myself according to this example:
NSError *error = nil;
ZXMultiFormatWriter *writer = [ZXMultiFormatWriter writer];
ZXBitMatrix* result = [writer encode:#"A string to encode"
format:kBarcodeFormatQRCode
width:500
height:500
error:&error];
if (result) {
CGImageRef image = [[ZXImage imageWithMatrix:result] cgimage];
} else {
NSString *errorMessage = [error localizedDescription];
}
The problem occurs when i try to encode my String with writer.encode(...) and i think it's good to precise that i tried with longer and smaller string but the result still the same.
do {
let writer = ZXMultiFormatWriter()
let hints = ZXEncodeHints() as ZXEncodeHints
let result = try writer.encode("foo", format: kBarcodeFormatDataMatrix, width: 300, height: 300, hints: hints)
let imageRef = ZXImage.init(matrix: result)
picture.image = UIImage(CGImage: imageRef.cgimage)
}
catch {
print(error)
}
And finally the app crash with this exception :
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't find a symbol arrangement that matches the message. Data codewords: 17'
*** First throw call stack:
(
0 CoreFoundation 0x00000001081b7d85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010854cdeb objc_exception_throw + 48
2 CoreFoundation 0x00000001081b7cbd +[NSException raise:format:] + 205
3 ZXingObjC 0x0000000107eb320a +[ZXDataMatrixSymbolInfo lookup:shape:minSize:maxSize:fail:] + 1178
4 ZXingObjC 0x0000000107ead4bb -[ZXDataMatrixEncoderContext updateSymbolInfoWithLength:] + 379
5 ZXingObjC 0x0000000107ea2866 -[ZXDataMatrixC40Encoder encode:] + 342
6 ZXingObjC 0x0000000107eaf032 +[ZXDataMatrixHighLevelEncoder encodeHighLevel:shape:minSize:maxSize:] + 1330
7 ZXingObjC 0x0000000107eb75b0 -[ZXDataMatrixWriter encode:format:width:height:hints:error:] + 672
8 ZXingObjC 0x0000000107ee246c -[ZXMultiFormatWriter encode:format:width:height:hints:error:] + 1100
9 DemoAppZXing 0x0000000103f54d98 _TFC4DemoAppZXing27VSMatrixOrderViewController11viewDidLoadfT_T_ + 8472
10 DemoAppZXing 0x0000000103f58002 _TToFC4DemoAppZXing27VSMatrixOrderViewController11viewDidLoadfT_T_ + 34
11 UIKit 0x0000000106a95984 -[UIViewController loadViewIfRequired] + 1198
12 UIKit 0x0000000106a9b93b -[UIViewController __viewWillAppear:] + 120
13 UIKit 0x0000000106acb750 -[UINavigationController _startCustomTransition:] + 1203
14 UIKit 0x0000000106adbb9b -[UINavigationController _startDeferredTransitionIfNeeded:] + 712
15 UIKit 0x0000000106adcd0b -[UINavigationController __viewWillLayoutSubviews] + 57
16 UIKit 0x0000000106c8b503 -[UILayoutContainerView layoutSubviews] + 248
17 UIKit 0x00000001069b5980 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 703
18 QuartzCore 0x000000010a2bfc00 -[CALayer layoutSublayers] + 146
19 QuartzCore 0x000000010a2b408e _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
20 QuartzCore 0x000000010a2b3f0c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x000000010a2a83c9 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277
22 QuartzCore 0x000000010a2d6086 _ZN2CA11Transaction6commitEv + 486
23 UIKit 0x00000001068f572e _UIApplicationHandleEventQueue + 7135
24 CoreFoundation 0x00000001080dd301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
25 CoreFoundation 0x00000001080d322c __CFRunLoopDoSources0 + 556
26 CoreFoundation 0x00000001080d26e3 __CFRunLoopRun + 867
27 CoreFoundation 0x00000001080d20f8 CFRunLoopRunSpecific + 488
28 GraphicsServices 0x000000010a8a1ad2 GSEventRunModal + 161
29 UIKit 0x00000001068faf09 UIApplicationMain + 171
30 DemoAppZXing 0x0000000103f60ec2 main + 114
31 libdyld.dylib 0x000000010905492d start + 1
)
libc++abi
.dylib: terminating with uncaught exception of type NSException
Edit :
To solve this problem, i just need to set the minSize and the maxSize.
let hints = ZXEncodeHints() as ZXEncodeHints
hints.maxSize = ZXDimension.init(width: 1000, height: 1000)
hints.minSize = ZXDimension.init(width: 1, height: 1)
let result = try writer.encode(generatedStr[0], format: kBarcodeFormatDataMatrix, width: 500, height: 500, hints: hints)
The method for returning the UIImage in the final form you need:
func generateDataMatrixQRCode(from string: String) -> UIImage? {
do {
let writer = ZXMultiFormatWriter()
let hints = ZXEncodeHints() as ZXEncodeHints
let result = try writer.encode(string, format: kBarcodeFormatDataMatrix, width: 1000, height: 1000, hints: hints)
if let imageRef = ZXImage.init(matrix: result) {
if let image = imageRef.cgimage {
return UIImage.init(cgImage: image)
}
}
}
catch {
print(error)
}
return nil
}
I think thats a "generic error" not tied to Swift but rather Zebra Crossing/ZXing. Try making the rect bigger, might help.
let result = try writer.encode("foo", format: kBarcodeFormatDataMatrix, width: 1000, height: 1000, hints: hints)
Related
We have a crash in our app that occurred 231 times affecting 185 users. I'm not sure if the log file is somehow full or is this a thread issue.
Crashed: com.apple.main-thread EXC_BAD_ACCESS 0x00000001052f77e4
NSClassFromString
Crashed: com.apple.main-thread
0 libdyld.dylib 0x195c656c0 <redacted> + 16
1 libdyld.dylib 0x195c65cd4 <redacted> + 52
2 libdyld.dylib 0x195c65b54 <redacted> + 52
3 libdyld.dylib 0x195c724f8 <redacted> + 132
4 libobjc.A.dylib 0x195ba4c38 getPreoptimizedClass + 148
5 libobjc.A.dylib 0x195b8f8d8 getClassExceptSomeSwift(char const*) + 20
6 libobjc.A.dylib 0x195b90784 look_up_class + 100
7 Foundation 0x196222b00 NSClassFromString + 200
8 Foundation 0x196213264 _decodeObjectBinary + 1708
9 Foundation 0x196212928 _decodeObject + 340
10 Foundation 0x196122050 -[NSKeyedUnarchiver decodeObjectForKey:] + 168
11 Foundation 0x196121eac -[NSKeyedUnarchiver decodeObjectOfClasses:forKey:] + 352
12 Foundation 0x196121b04 -[NSCoder(Exceptions) __tryDecodeObjectForKey:error:decodeBlock:] + 96
13 Foundation 0x196121a7c -[NSCoder decodeTopLevelObjectOfClasses:forKey:error:] + 108
14 Foundation 0x196120d08 +[NSKeyedUnarchiver unarchivedObjectOfClasses:fromData:error:] + 136
15 Foundation 0x196167268 +[NSKeyedUnarchiver unarchivedObjectOfClass:fromData:error:] + 116
16 NetworkExtension 0x1a803f0a4 __64-[NEVPNConnection updateSessionInfoForce:withCompletionHandler:]_block_invoke + 512
17 libsystem_networkextension.dylib 0x19ad05e20 __ne_session_get_info_with_parameters_block_invoke.145 + 32
18 libdispatch.dylib 0x195b2d610 _dispatch_call_block_and_release + 24
19 libdispatch.dylib 0x195b2e184 _dispatch_client_callout + 16
20 libdispatch.dylib 0x195ae01d0 _dispatch_main_queue_callback_4CF$VARIANT$mp + 1044
21 CoreFoundation 0x195dde3c4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
22 CoreFoundation 0x195dd93b8 __CFRunLoopRun + 2004
23 CoreFoundation 0x195dd88bc CFRunLoopRunSpecific + 464
24 GraphicsServices 0x19fc44328 GSEventRunModal + 104
25 UIKitCore 0x199e6e6d4 UIApplicationMain + 1936
26 myapp 0x104ba5da0 main + 19 (Log.swift:19)
27 libdyld.dylib 0x195c63460 <redacted> + 4
com.apple.uikit.eventfetch-thread
0 libsystem_kernel.dylib 0x195c375f4 mach_msg_trap + 8
1 libsystem_kernel.dylib 0x195c36a60 mach_msg + 72
2 CoreFoundation 0x195dde068 __CFRunLoopServiceMachPort + 216
3 CoreFoundation 0x195dd9188 __CFRunLoopRun + 1444
4 CoreFoundation 0x195dd88bc CFRunLoopRunSpecific + 464
5 Foundation 0x196118994 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 228
6 Foundation 0x196118874 -[NSRunLoop(NSRunLoop) runUntilDate:] + 88
7 UIKitCore 0x199f0649c -[UIEventFetcher threadMain] + 152
8 Foundation 0x1962490b0 __NSThread__start__ + 848
9 libsystem_pthread.dylib 0x195b7d1ec _pthread_start + 124
10 libsystem_pthread.dylib 0x195b80aec thread_start + 8
Based on this stack trace, it happened on line 19 of the class Log.swift, which is handle.closeFile().
class Log: TextOutputStream {
func write(_ string: String) {
let fm = FileManager.default
let log = fm.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("myapp.log")
if let handle = try? FileHandle(forWritingTo: log) {
handle.seekToEndOfFile()
handle.write(string.data(using: .utf8)!)
handle.closeFile()
} else {
try? string.data(using: .utf8)?.write(to: log)
}
}
static var log: Log = Log()
private init() {} // we are sure, nobody else could create it
}
Is this happening because it is called while not running on the main thread? Would this below solve it? Since I need accurate logging, maybe I should avoid async and go with sync instead?
class Log: TextOutputStream {
func write(_ string: String) {
DispatchQueue.main.sync {
let fm = FileManager.default
let log = fm.urls(for: .documentDirectory, in: .userDomainMask)[0].appendingPathComponent("myapp.log")
if let handle = try? FileHandle(forWritingTo: log) {
handle.seekToEndOfFile()
handle.write(string.data(using: .utf8)!)
handle.closeFile()
} else {
try? string.data(using: .utf8)?.write(to: log)
}
}
}
static var log: Log = Log()
private init() {} // we are sure, nobody else could create it
}
I'm very new to Swift - having some trouble doing the simple task of displaying a document in a PDFView. I am not using Storyboards or IBOutlets etc. Any idea why the below is crashing?
I have tried referencing an external link, but it gives me the same error. The PDF exists in the bundle directory.
import UIKit
import PDFKit
class ViewController: UIViewController {
private var pdfView = PDFView()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let myNewView = PDFView(frame: CGRect(x: 10, y: 100, width: 500, height: 500))
// Add border to UIView
myNewView.layer.borderWidth=2
// Change UIView Border Color to Red
myNewView.layer.borderColor = UIColor.red.cgColor
guard let path = Bundle.main.path(forResource: "CV", ofType: "pdf") else { return }
let url = URL(fileURLWithPath: path)
let document = PDFDocument(url: url)
myNewView.document = document
// Add UIView as a Subview
self.view.addSubview(myNewView)
}
}
Build succeeds. But I get the below.
2019-06-13 17:49:35.702174+0100 Appp[81235:19343962] * Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
* First throw call stack:
(
0 CoreFoundation 0x00000001083446fb exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000106250ac5 objc_exception_throw + 48
2 CoreFoundation 0x0000000108344555 +[NSException raise:format:] + 197
3 QuartzCore 0x000000010b4072ae _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 140
4 QuartzCore 0x000000010b3f668b -[CALayer setPosition:] + 57
5 QuartzCore 0x000000010b3f6de3 -[CALayer setFrame:] + 560
6 PDFKit 0x0000000107135097 -[PDFPageLayerTile initWithFrame:forPageLayer:withRenderingTransform:tileContentsScale:generationID:] + 168
7 PDFKit 0x000000010713a805 -[PDFPageLayer _updateTiles] + 3439
8 PDFKit 0x0000000107135d8e -[PDFPageLayer setNeedsTilesUpdate] + 87
9 PDFKit 0x000000010714a97d -[PDFPageView setNeedsTilesUpdate] + 48
10 PDFKit 0x000000010714c816 -[PDFPageView setFrame:] + 334
11 PDFKit 0x000000010714311c -[PDFDocumentView createPageViewForPageAtIndex:] + 764
12 PDFKit 0x0000000107144326 -[PDFDocumentView updateVisibility] + 1726
13 PDFKit 0x00000001071b376f -[PDFView resizeDisplayView:] + 517
14 PDFKit 0x00000001071accdf -[PDFView layoutDocumentView] + 464
15 PDFKit 0x00000001071a836a -[PDFView setDocument:waitDuration:] + 1246
16 Appp 0x000000010596c4d1 $s7Appp14ViewControllerC11viewDidLoadyyF + 1441
17 Appp 0x000000010596c7b4 $s7Appp14ViewControllerC11viewDidLoadyyFTo + 36
18 UIKitCore 0x000000010d0ec43b -[UIViewController loadViewIfRequired] + 1183
19 UIKitCore 0x000000010d0ec868 -[UIViewController view] + 27
20 UIKitCore 0x000000010d724c33 -[UIWindow addRootViewControllerViewIfPossible] + 122
21 UIKitCore 0x000000010d725327 -[UIWindow _setHidden:forced:] + 289
22 UIKitCore 0x000000010d737f86 -[UIWindow makeKeyAndVisible] + 42
23 UIKitCore 0x000000010d6e7f1c -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4555
24 UIKitCore 0x000000010d6ed0c6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1617
25 UIKitCore 0x000000010cf326d6 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 904
26 UIKitCore 0x000000010cf3afce +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
27 UIKitCore 0x000000010cf322ec -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236
28 UIKitCore 0x000000010cf32c48 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 1091
29 UIKitCore 0x000000010cf30fba __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 782
30 UIKitCore 0x000000010cf30c71 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433
31 UIKitCore 0x000000010cf359b6 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 576
32 UIKitCore 0x000000010cf36610 _performActionsWithDelayForTransitionContext + 100
33 UIKitCore 0x000000010cf3571d -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 223
34 UIKitCore 0x000000010cf3a6d0 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
35 UIKitCore 0x000000010d6eb9a8 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 514
36 UIKitCore 0x000000010d2a2dfa -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
37 FrontBoardServices 0x00000001135df125 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 448
38 FrontBoardServices 0x00000001135e8ed6 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 283
39 FrontBoardServices 0x00000001135e8700 __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 53
40 libdispatch.dylib 0x00000001096d7db5 _dispatch_client_callout + 8
41 libdispatch.dylib 0x00000001096db2ba _dispatch_block_invoke_direct + 300
42 FrontBoardServices 0x000000011361a146 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 30
43 FrontBoardServices 0x0000000113619dfe -[FBSSerialQueue _performNext] + 451
44 FrontBoardServices 0x000000011361a393 -[FBSSerialQueue _performNextFromRunLoopSource] + 42
45 CoreFoundation 0x00000001082abbe1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
46 CoreFoundation 0x00000001082ab463 __CFRunLoopDoSources0 + 243
47 CoreFoundation 0x00000001082a5b1f __CFRunLoopRun + 1231
48 CoreFoundation 0x00000001082a5302 CFRunLoopRunSpecific + 626
49 GraphicsServices 0x00000001107c62fe GSEventRunModal + 65
50 UIKitCore 0x000000010d6eeba2 UIApplicationMain + 140
51 Appp 0x000000010596f68b main + 75
52 libdyld.dylib 0x000000010974c541 start + 1
53 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
If you move myNewView.document = document to viewDidAppear: instead of viewDidLoad, the document will load without issue.
Unfortunately, there were changes to iOS between 12.1 and 12.2 that make this necessary.
This question already has an answer here:
unrecognized selector sent to instance when no related entities found in Core Data
(1 answer)
Closed 4 years ago.
I am getting the above error when executing the following code:
func tableView(_ tableView: UITableView,
commit editingStyle: UITableViewCellEditingStyle,
forRowAt indexPath: IndexPath) {
let eventsOnArray = selectedRecipient?.events.allObjects // crashes here
guard let eventToRemove = eventsOnArray![indexPath.row] as? Event, editingStyle == .delete else {
return
}
managedContext.delete(eventToRemove)
do {
try managedContext.save()
getEvents()
self.eventList.reloadData()
} catch let error as NSError {
print("Saving error: \(error), description: \(error.userInfo)")
}
}
The detailed error is:
2018-03-11 12:20:49.732482-0400 Card Tracker[1516:29197] -[Recipient events]: unrecognized selector sent to instance 0x600000283840
2018-03-11 12:20:49.746477-0400 Card Tracker[1516:29197] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Recipient events]: unrecognized selector sent to instance 0x600000283840'
*** First throw call stack:
(
0 CoreFoundation 0x000000010fe2f12b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010ef76f41 objc_exception_throw + 48
2 CoreFoundation 0x000000010feb0024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010fdb1f78 ___forwarding___ + 1432
4 CoreFoundation 0x000000010fdb1958 _CF_forwarding_prep_0 + 120
5 Card Tracker 0x000000010e62b773 _T012Card_Tracker010ViewEventsC10ControllerC05tableC0ySo07UITableC0C_SC0gC16CellEditingStyleO6commit10Foundation9IndexPathV8forRowAttF + 195
6 Card Tracker 0x000000010e62c177 _T012Card_Tracker010ViewEventsC10ControllerC05tableC0ySo07UITableC0C_SC0gC16CellEditingStyleO6commit10Foundation9IndexPathV8forRowAttFTo + 119
7 UIKit 0x0000000110410a5f -[UITableView _animateDeletionOfRowAtIndexPath:] + 177
8 UIKit 0x0000000110419a59 __82-[UITableView _contextualActionForDeletingRowAtIndexPath:usingPresentationValues:]_block_invoke + 59
9 UIKit 0x0000000110953d67 -[UIContextualAction executeHandlerWithView:completionHandler:] + 174
10 UIKit 0x0000000110c41374 -[UISwipeOccurrence _performSwipeAction:inPullview:swipeInfo:] + 702
11 UIKit 0x0000000110c42bd1 -[UISwipeOccurrence swipeActionPullView:tappedAction:] + 112
12 UIKit 0x0000000110d25ed2 -[UISwipeActionPullView _tappedButton:] + 138
13 UIKit 0x00000001102ae972 -[UIApplication sendAction:to:from:forEvent:] + 83
14 UIKit 0x000000011042dc3c -[UIControl sendAction:to:forEvent:] + 67
15 UIKit 0x000000011042df59 -[UIControl _sendActionsForEvents:withEvent:] + 450
16 UIKit 0x000000011042ce86 -[UIControl touchesEnded:withEvent:] + 618
17 UIKit 0x000000011089ebad _UIGestureEnvironmentSortAndSendDelayedTouches + 5560
18 UIKit 0x0000000110898a4d _UIGestureEnvironmentUpdate + 1506
19 UIKit 0x000000011089841f -[UIGestureEnvironment _deliverEvent:toGestureRecognizers:usingBlock:] + 484
20 UIKit 0x00000001108974cb -[UIGestureEnvironment _updateGesturesForEvent:window:] + 288
21 UIKit 0x0000000110325f14 -[UIWindow sendEvent:] + 4102
22 UIKit 0x00000001102c9365 -[UIApplication sendEvent:] + 352
23 UIKit 0x000000012c2fe49d -[UIApplicationAccessibility sendEvent:] + 85
24 UIKit 0x0000000110c15a1d __dispatchPreprocessedEventFromEventQueue + 2809
25 UIKit 0x0000000110c18672 __handleEventQueueInternal + 5957
26 CoreFoundation 0x000000010fdd2101 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
27 CoreFoundation 0x000000010fe71f71 __CFRunLoopDoSource0 + 81
28 CoreFoundation 0x000000010fdb6a19 __CFRunLoopDoSources0 + 185
29 CoreFoundation 0x000000010fdb5fff __CFRunLoopRun + 1279
30 CoreFoundation 0x000000010fdb5889 CFRunLoopRunSpecific + 409
31 GraphicsServices 0x00000001159789c6 GSEventRunModal + 62
32 UIKit 0x00000001102ad5d6 UIApplicationMain + 159
33 Card Tracker 0x000000010e606727 main + 55
34 libdyld.dylib 0x000000011436dd81 start + 1
35 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I am trying to delete a detail row in a Header-Detail based Entity. The crash occurs in the debugger as soon as I leave the line let eventsOnArray. I have placed a break point on that line, the code runs up until that point and then crashes when I use "Step Over".
getEvents:
func getEvents () {
// Now load all Events for this Receipient
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Event")
request.resultType = .dictionaryResultType
do {
events = try managedContext.fetch(request) as! [NSDictionary]
} catch {
print("Core Data Fetch Failed:", error.localizedDescription)
}
}
Core Data Definition:
Chances are that selectedRecepient is not an instance of Recipient class (or at least ObjC runtime thinks so).
Try to examine its type:
print(type(of: selectedRecipient))
If it prints NSManagedObject then you should make sure that Recipient entity has its class set to Recipient in data model editor – this tells Core Data to cast instances of that entity to the corresponding class.
I finished migrating my application to swift3 but this section keeps yielding is causing problems.
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.navigationController?.setNavigationBarHidden(false, animated: animated)
self.navigationItem.title = artworkTitle
let title = "<center><span style=\"font-size: 17px;font-weight:lighter;font-family:Avenir-Book;\">" + artworkCaption + "</span></center>"
artworkImageView.image = UIImage(named: artworkImagePath)
artworkCaptionView.attributedText = title.html2AttStr
}
Important Console Parts
-[_SwiftValue unsignedIntegerValue]: unrecognized selector sent to instance 0x608000243d50
terminating with uncaught exception of type NSException
(lldb)
extension String
{
var html2AttStr:NSAttributedString
{
let contents: NSMutableAttributedString?
do {
let attrTextStyle = NSMutableParagraphStyle()
attrTextStyle.alignment = NSTextAlignment.center
contents = try NSMutableAttributedString(data: data(using: String.Encoding.utf8)!, options:[NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8], documentAttributes: nil)
} catch _ {
contents = nil
}
Console
0 CoreFoundation 0x000000010b70934b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010ad7521e objc_exception_throw + 48
2 CoreFoundation 0x000000010b778f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010b68ec15 ___forwarding___ + 1013
4 CoreFoundation 0x000000010b68e798 _CF_forwarding_prep_0 + 120
5 UIFoundation 0x0000000114565953 -[NSHTMLReader _loadUsingWebKit] + 1329
6 UIFoundation 0x0000000114566f15 -[NSHTMLReader attributedString] + 22
7 UIFoundation 0x00000001144fd45c _NSReadAttributedStringFromURLOrData + 5779
8 UIFoundation 0x00000001144fbd35 -[NSAttributedString(NSAttributedStringUIFoundationAdditions) initWithData:options:documentAttributes:error:] + 115
9 pg 0x000000010a39fe1d _TTOFCSo25NSMutableAttributedStringcfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S_ + 173
10 pg 0x000000010a39fba4 _TFCSo25NSMutableAttributedStringCfzT4dataV10Foundation4Data7optionsGVs10DictionarySSP__18documentAttributesGSqGVs33AutoreleasingUnsafeMutablePointerGSqCSo12NSDictionary____S_ + 100
11 pg 0x000000010a39f96a _TFE2pgSSg11html2AttStrCSo18NSAttributedString + 458
12 pg 0x000000010a3a901d _TFC2pg21ViewControllerArtwork14viewWillAppearfSbT_ + 1197
13 pg 0x000000010a3a90b1 _TToFC2pg21ViewControllerArtwork14viewWillAppearfSbT_ + 49
14 UIKit 0x000000010c642de3 -[UIViewController _setViewAppearState:isAnimating:] + 692
15 UIKit 0x000000010c6434f3 -[UIViewController __viewWillAppear:] + 147
16 UIKit 0x000000010c67e1a3 -[UINavigationController _startTransition:fromViewController:toViewController:] + 890
17 UIKit 0x000000010c67f0b9 -[UINavigationController _startDeferredTransitionIfNeeded:] + 874
18 UIKit 0x000000010c68019b -[UINavigationController __viewWillLayoutSubviews] + 58
19 UIKit 0x000000010c8771b7 -[UILayoutContainerView layoutSubviews] + 223
20 UIKit 0x000000010c560344 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
21 QuartzCore 0x000000010c312cdc -[CALayer layoutSublayers] + 146
22 QuartzCore 0x000000010c3067a0 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
23 QuartzCore 0x000000010c30661e _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
24 QuartzCore 0x000000010c29462c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
25 QuartzCore 0x000000010c2c1713 _ZN2CA11Transaction6commitEv + 475
26 UIKit 0x000000010c495067 _UIApplicationFlushRunLoopCATransactionIfTooLate + 206
27 UIKit 0x000000010cca4b30 __handleEventQueue + 5672
28 CoreFoundation 0x000000010b6ae311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
29 CoreFoundation 0x000000010b69359c __CFRunLoopDoSources0 + 556
30 CoreFoundation 0x000000010b692a86 __CFRunLoopRun + 918
31 CoreFoundation 0x000000010b692494 CFRunLoopRunSpecific + 420
32 GraphicsServices 0x0000000111084a6f GSEventRunModal + 161
33 UIKit 0x000000010c49bf34 UIApplicationMain + 159
34 pg 0x000000010a3acaaf main + 111
35 libdyld.dylib 0x000000011233668d start + 1
36 ??? 0x0000000000000001 0x0 + 1
libc++abi.dylib: terminating with uncaught exception of type NSException
I remember reading on Apple's Swift blog that if you get unrecognized selector errors, it means that the auto-wrapping of Swift structs are causing issues. Most likely it is wrapping String.Encoding instead of converting it to an NSNumber (what the Objective-C code behind NSMutableAttributedString is expecting).
Try replacing NSCharacterEncodingDocumentAttribute: String.Encoding.utf8 with NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue
I would like to know what it means when we get an error like the 'NSInvalidArgumentException', reason: 'A Node can't parent itself' :
2015-03-04 01:51:33.421 FlappyPOOSwift[1789:155918] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'A Node can't parent itself: <SKSpriteNode> name:'(null)' texture:[<SKTexture> 'pipeDown' (30 x 160)] position:{0, 851} size:{60, 320} rotation:0.00'
*** First throw call stack:
(
0 CoreFoundation 0x0000000105361f35 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010705bbb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000105361e6d +[NSException raise:format:] + 205
3 SpriteKit 0x0000000105c23d14 -[SKNode(setParent) setParent:] + 134
4 SpriteKit 0x0000000105c1c1ea -[SKNode addChild:] + 179
5 FlappyPOOSwift 0x00000001051754d6 _TFC14FlappyPOOSwift9GameScene10spawnPipesfS0_FT_T_ + 2294
6 FlappyPOOSwift 0x0000000105176e28 _TFFC14FlappyPOOSwift9GameScene13didMoveToViewFS0_FCSo6SKViewT_U_FT_T_ + 56
7 FlappyPOOSwift 0x0000000105176e67 _TTRXFo__dT__XFdCb__dT__ + 39
8 SpriteKit 0x0000000105c11586 -[SKRunBlock updateWithTarget:forTime:] + 99
9 SpriteKit 0x0000000105beb586 _ZN11SKCSequence27cpp_updateWithTargetForTimeEP9SKCSprited + 92
10 SpriteKit 0x0000000105be374c _ZN9SKCRepeat27cpp_updateWithTargetForTimeEP9SKCSprited + 40
11 SpriteKit 0x0000000105c3bce8 _ZN9SKCSprite6updateEd + 170
12 SpriteKit 0x0000000105bf5435 -[SKScene _update:] + 120
13 SpriteKit 0x0000000105c0f949 -[SKView(Private) _update:] + 563
14 SpriteKit 0x0000000105c0d2d9 -[SKView renderCallback:shouldBlock:] + 837
15 SpriteKit 0x0000000105c0a391 __29-[SKView setUpRenderCallback]_block_invoke + 56
16 SpriteKit 0x0000000105c36df4 -[SKDisplayLink _callbackForNextFrame:] + 256
17 QuartzCore 0x0000000109c73747 _ZN2CA7Display15DisplayLinkItem8dispatchEv + 37
18 QuartzCore 0x0000000109c7360f _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 315
19 CoreFoundation 0x00000001052c9f64 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
20 CoreFoundation 0x00000001052c9b25 __CFRunLoopDoTimer + 1045
21 CoreFoundation 0x000000010528ce5d __CFRunLoopRun + 1901
22 CoreFoundation 0x000000010528c486 CFRunLoopRunSpecific + 470
23 GraphicsServices 0x000000010c70e9f0 GSEventRunModal + 161
24 UIKit 0x0000000105da3420 UIApplicationMain + 1282
25 FlappyPOOSwift 0x000000010517a89e top_level_code + 78
26 FlappyPOOSwift 0x000000010517a8da main + 42
27 libdyld.dylib 0x0000000107847145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Thanks in advance.
hi i guess ill just show you the code
func spawnPipes() {
let pipePair = SKNode()
pipePair.position = CGPointMake(self.frame.size.width + pipeUpTexture.size().width * 2, 0)
pipePair.zPosition = -10
let height = UInt32(self.frame.size.height / 4)
let y = arc4random() % height + height
let pipeDown = SKSpriteNode (texture: pipeDownTexture)
pipeDown.setScale(2.0)
pipeDown.position = CGPointMake(0.0 , CGFloat(y) + pipeDown.size.height + CGFloat(pipeGap))
pipeDown.physicsBody = SKPhysicsBody (rectangleOfSize: pipeDown.size)
pipeDown.physicsBody?.dynamic = false
pipeDown.addChild(pipeDown)
//pipe Up
**let pipeUp = SKSpriteNode (texture: pipeUpTexture)**
pipeUp.setScale(2.0)
pipeUp.position = CGPointMake(0.0 , CGFloat(y))
pipeUp.physicsBody = SKPhysicsBody (rectangleOfSize: pipeUp.size)
pipeUp.physicsBody?.dynamic = false
pipeUp.addChild(pipeUp)
pipePair.runAction(PipesMoveAndRemove)
self.addChild(pipePair)
}
I guess the lines which are ** marked have the error but i can't see them in the Xcode. I hope you understand what I'm trying to say
My guess is that either :
You are trying to add the node to itself (as the error mention), like for example : pipeDownNode.addChild(pipeDownNode) instead of anotherNode.addChild(pipeDownNode)
You are trying to add node at the same node twice, like : aNode.addChild(pipeDownNode) and pipeDownNode.parent = aNode
Let me know if it helped. Otherwise, please add some code (where you add the node).