Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]' - cgrectmake

The problem started with the XCode 10.2.x as I guess
While it was working fine with the XCode 10.1
The crash point is "pdfView.frame = self.view.frame" from below code:
import UIKit
import PDFKit
class ViewController: UIViewController {
var pdfView = PDFView()
override func viewDidLoad() {
super.viewDidLoad()
// Prepare document to show
let url = Bundle.main.url(forResource: "sample", withExtension: "pdf")
let pdfDocument = PDFDocument(url: url!)
// PDFView
pdfView = PDFView()
pdfView.frame = self.view.frame
pdfView.autoScales = true
pdfView.document = pdfDocument
// Add PDFView to viewController
self.view.addSubview(pdfView)
}
}
Crash Log:
2019-05-20 16:24:39.269219+0530 PDFKitDemo[6795:305736] *** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [nan nan]'
*** First throw call stack:
(
0 CoreFoundation 0x00000001118c06fb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x000000010fd63ac5 objc_exception_throw + 48
2 CoreFoundation 0x00000001118c0555 +[NSException raise:format:] + 197
3 QuartzCore 0x00000001149632ae _ZN2CA5Layer12set_positionERKNS_4Vec2IdEEb + 140
4 QuartzCore 0x000000011495268b -[CALayer setPosition:] + 57
5 QuartzCore 0x0000000114952de3 -[CALayer setFrame:] + 560
6 PDFKit 0x00000001106c7097 -[PDFPageLayerTile initWithFrame:forPageLayer:withRenderingTransform:tileContentsScale:generationID:] + 168
7 PDFKit 0x00000001106cc805 -[PDFPageLayer _updateTiles] + 3439
8 PDFKit 0x00000001106c7d8e -[PDFPageLayer setNeedsTilesUpdate] + 87
9 PDFKit 0x00000001106dc97d -[PDFPageView setNeedsTilesUpdate] + 48
10 PDFKit 0x00000001106de816 -[PDFPageView setFrame:] + 334
11 PDFKit 0x00000001106d511c -[PDFDocumentView createPageViewForPageAtIndex:] + 764
12 PDFKit 0x00000001106d6326 -[PDFDocumentView updateVisibility] + 1726
13 PDFKit 0x000000011074576f -[PDFView resizeDisplayView:] + 517
14 PDFKit 0x000000011073ecdf -[PDFView layoutDocumentView] + 464
15 PDFKit 0x000000011073a36a -[PDFView setDocument:waitDuration:] + 1246
16 PDFKitDemo 0x000000010f4833b3 $s10PDFKitDemo14ViewControllerC11viewDidLoadyyF + 2147
17 PDFKitDemo 0x000000010f483874 $s10PDFKitDemo14ViewControllerC11viewDidLoadyyFTo + 36
18 UIKitCore 0x000000011666843b -[UIViewController loadViewIfRequired] + 1183
19 UIKitCore 0x0000000116668868 -[UIViewController view] + 27
20 UIKitCore 0x0000000116ca0c33 -[UIWindow addRootViewControllerViewIfPossible] + 122
21 UIKitCore 0x0000000116ca1327 -[UIWindow _setHidden:forced:] + 289
22 UIKitCore 0x0000000116cb3f86 -[UIWindow makeKeyAndVisible] + 42
23 UIKitCore 0x0000000116c63f1c -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4555
24 UIKitCore 0x0000000116c690c6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1617
25 UIKitCore 0x00000001164ae6d6 __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 904
26 UIKitCore 0x00000001164b6fce +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
27 UIKitCore 0x00000001164ae2ec -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236
28 UIKitCore 0x00000001164aec48 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 1091
29 UIKitCore 0x00000001164acfba __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 782
30 UIKitCore 0x00000001164acc71 -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433
31 UIKitCore 0x00000001164b19b6 __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 576
32 UIKitCore 0x00000001164b2610 _performActionsWithDelayForTransitionContext + 100
33 UIKitCore 0x00000001164b171d -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 223
34 UIKitCore 0x00000001164b66d0 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
35 UIKitCore 0x0000000116c679a8 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 514
36 UIKitCore 0x000000011681edfa -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
37 FrontBoardServices 0x000000011cb5b125 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 448
38 FrontBoardServices 0x000000011cb64ed6 __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 283
39 FrontBoardServices 0x000000011cb64700 __40-[FBSWorkspace _performDelegateCallOut:]_block_invoke + 53
40 libdispatch.dylib 0x0000000112c53db5 _dispatch_client_callout + 8
41 libdispatch.dylib 0x0000000112c572ba _dispatch_block_invoke_direct + 300
42 FrontBoardServices 0x000000011cb96146 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
43 FrontBoardServices 0x000000011cb95dfe -[FBSSerialQueue _performNext] + 451
44 FrontBoardServices 0x000000011cb96393 -[FBSSerialQueue _performNextFromRunLoopSource] + 42
45 CoreFoundation 0x0000000111827be1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
46 CoreFoundation 0x0000000111827463 __CFRunLoopDoSources0 + 243
47 CoreFoundation 0x0000000111821b1f __CFRunLoopRun + 1231
48 CoreFoundation 0x0000000111821302 CFRunLoopRunSpecific + 626
49 GraphicsServices 0x0000000119d422fe GSEventRunModal + 65
50 UIKitCore 0x0000000116c6aba2 UIApplicationMain + 140
51 PDFKitDemo 0x000000010f484a6b main + 75
52 libdyld.dylib 0x0000000112cc8541 start + 1
53 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Don't the exact reason but by adding the method viewDidLayoutSubviews, it's fixed the crash problem.
Now, working code is
override func viewDidLoad() {
super.viewDidLoad()
// Prepare document to show
let url = Bundle.main.url(forResource: "sample", withExtension: "pdf")
let pdfDocument = PDFDocument(url: url!)
// PDFView
pdfView = PDFView()
pdfView.autoScales = true
pdfView.document = pdfDocument
// Add PDFView to viewController
self.view.addSubview(pdfView)
}
override func viewDidLayoutSubviews() {
pdfView.frame = self.view.frame
}

Related

In SwiftUI Textfield inside HStack which is inside VStack generates runtime Error in macOS

I'm working with Xcode 12.3 and MacOS 11.1.
A Textfield is embedded in a HStack and this one is embedded in a VStack.
struct ContentView: View {
#State var username: String = ""
var body: some View {
VStack {
HStack() {
Text("Enter Username:")
TextField("", text: $username)
}
Text("Your username: \(username)")
}
}
}
The code runs without any problems as an iOS-App.
However, compiling the code as a MacOS-App results in a runtime error.
2021-01-23 23:18:29.835048+0100 TestMacSwiftUI[6349:280606] [General] ERROR: Setting
<_TtC7SwiftUIP33_C58093E7172B0A541A997680E343D0D516_SystemTextField: 0x7fa1666294b0> as the first responder for window
<NSWindow: 0x7fa166606110>, but it is in a different window ((null))! This would eventually crash when the view is freed.
The first responder will be set to nil.
0 AppKit 0x00007fff22c5a499 -[NSWindow _validateFirstResponder:] + 449
1 AppKit 0x00007fff22c5a294 -[NSWindow _setFirstResponder:] + 31
2 AppKit 0x00007fff22d7e72b -[NSWindow _realMakeFirstResponder:] + 338
3 SwiftUI 0x00007fff42d8627b $s7SwiftUI11FocusBridgeC04moveC02toyAA0C4ItemV_tF + 155
4 SwiftUI 0x00007fff42d86fad $s7SwiftUI11FocusBridgeC27hostDidBecomeFirstResponder33_74086170859BF7C5D78394D4DEE7E0F9LLyyF + 861
5 SwiftUI 0x00007fff42d85b97 $s7SwiftUI11FocusBridgeC23firstResponderDidChange2to04rootF0ySo11NSResponderCSg_AA0F4Node_pSgtF + 583
6 SwiftUI 0x00007fff42c7102b $s7SwiftUI13NSHostingViewC12observeValue10forKeyPath2of6change7contextySSSg_ypSgSDySo05NSKeyf6ChangeH0aypGSgSvSgtFyycfU_ + 299
7 SwiftUI 0x00007fff42632c8c $sIeg_ytIegr_TR + 12
8 SwiftUI 0x00007fff42c79631 $sIeg_ytIegr_TRTA + 17
9 SwiftUI 0x00007fff42b61374 $s7SwiftUI6UpdateO3endyyFZ + 436
10 SwiftUI 0x00007fff42c70e85 $s7SwiftUI13NSHostingViewC12observeValue10forKeyPath2of6change7contextySSSg_ypSgSDySo05NSKeyf6ChangeH0aypGSgSvSgtF + 805
11 SwiftUI 0x00007fff42c71159 $s7SwiftUI13NSHostingViewC12observeValue10forKeyPath2of6change7contextySSSg_ypSgSDySo05NSKeyf6ChangeH0aypGSgSvSgtFTo + 249
12 Foundation 0x00007fff21188ab8 NSKeyValueNotifyObserver + 327
13 Foundation 0x00007fff2124fe45 NSKeyValueDidChange + 431
14 Foundation 0x00007fff212f0539 NSKeyValueDidChangeWithPerThreadPendingNotifications + 146
15 AppKit 0x00007fff22d7e72b -[NSWindow _realMakeFirstResponder:] + 338
16 AppKit 0x00007fff22d93adf -[NSWindow _selectFirstKeyView] + 758
17 AppKit 0x00007fff22d9310f -[NSWindow _setUpFirstResponder] + 189
18 AppKit 0x00007fff22d90577 -[NSWindow _doWindowWillBeVisibleAsSheet:] + 153
19 AppKit 0x00007fff22d8e4bd -[NSWindow _reallyDoOrderWindowAboveOrBelow:relativeTo:findKey:forCounter:force:isModal:] + 1317
20 AppKit 0x00007fff22d8dc42 -[NSWindow _reallyDoOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 135
21 AppKit 0x00007fff22d8cc52 -[NSWindow _doOrderWindow:relativeTo:findKey:forCounter:force:isModal:] + 289
22 AppKit 0x00007fff22d8cad0 -[NSWindow orderWindow:relativeTo:] + 155
23 AppKit 0x00007fff22d806f1 -[NSWindow makeKeyAndOrderFront:] + 60
24 TestMacSwiftUI 0x000000010e887d21 $s14TestMacSwiftUI11AppDelegateC29applicationDidFinishLaunchingyy10Foundation12NotificationVF + 3169
25 TestMacSwiftUI 0x000000010e887f62 $s14TestMacSwiftUI11AppDelegateC29applicationDidFinishLaunchingyy10Foundation12NotificationVFTo + 146
26 CoreFoundation 0x00007fff2041dfec __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
27 CoreFoundation 0x00007fff204b989b ___CFXRegistrationPost_block_invoke + 49
28 CoreFoundation 0x00007fff204b980f _CFXRegistrationPost + 454
29 CoreFoundation 0x00007fff203eebde _CFXNotificationPost + 723
30 Foundation 0x00007fff2115dabe -[NSNotificationCenter postNotificationName:object:userInfo:] + 59
31 AppKit 0x00007fff22c4cf6d -[NSApplication _postDidFinishNotification] + 305
32 AppKit 0x00007fff22c4ccbb -[NSApplication _sendFinishLaunchingNotification] + 208
33 AppKit 0x00007fff22c49eb2 -[NSApplication(NSAppleEventHandling) _handleAEOpenEvent:] + 541
34 AppKit 0x00007fff22c49b07 -[NSApplication(NSAppleEventHandling) _handleCoreEvent:withReplyEvent:] + 665
35 Foundation 0x00007fff21189056 -[NSAppleEventManager dispatchRawAppleEvent:withRawReply:handlerRefCon:] + 308
36 Foundation 0x00007fff21188ec6 _NSAppleEventManagerGenericHandler + 80
37 AE 0x00007fff26201ed9 _AppleEventsCheckInAppWithBlock + 15850
38 AE 0x00007fff262015f4 _AppleEventsCheckInAppWithBlock + 13573
39 AE 0x00007fff261fa260 aeProcessAppleEvent + 452
40 HIToolbox 0x00007fff286bd612 AEProcessAppleEvent + 54
41 AppKit 0x00007fff22c44276 _DPSNextEvent + 2048
42 AppKit 0x00007fff22c425af -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1366
43 AppKit 0x00007fff22c34b0a -[NSApplication run] + 586
44 AppKit 0x00007fff22c08df2 NSApplicationMain + 816
45 TestMacSwiftUI 0x000000010e8882d4 $sSo21NSApplicationDelegateP6AppKitE4mainyyFZ + 36
46 TestMacSwiftUI 0x000000010e88829e $s14TestMacSwiftUI11AppDelegateC5$mainyyFZ + 46
47 TestMacSwiftUI 0x000000010e888309 main + 41
48 libdyld.dylib 0x00007fff2034b621 start + 1
49 ??? 0x0000000000000003 0x0 + 3

How can I fix the following error: ""Cannot assign value of type 'ViewController' to type 'UITextFieldDelegate?'"?

I'm new to all this so please keep that in mind while reading.
This is the code I am using; the file refuses to build because of line 16. The error says "Cannot assign value of type 'ViewController' to type 'UITextFieldDelegate?'".
//
// ViewController.swift
// FoodTracker
//
//
import UIKit
class ViewController: UIViewController {
//MARK: Properties
#IBOutlet weak var nameTextField: UITextField!
#IBOutlet weak var mealNameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
nameTextField.delegate = self
// Handle the text field’s user input through delegate callbacks.
}
//MARK: UITextFieldDelegate
func textFieldShouldReturn(_ textField: UITextField) -> Bool {
//Hide the keyboard
textField.resignFirstResponder()
return true
}
func textFieldDidEndEditing(_ textField: UITextField) {
mealNameLabel.text = textField.text
}
//MARK: Actions
#IBAction func setDefaultLabelText(_ sender: UIButton) {
mealNameLabel.text = "Default Text"
}
}
Here is the full error output message.
020-04-09 14:19:12.897243-0400 FoodTracker[29402:868329] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<FoodTracker.ViewController 0x7ffaef406830> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key nameTypeField.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23e3dcce __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50b3b9b2 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23e3d899 -[NSException raise] + 9
3 Foundation 0x00007fff258d5796 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 325
4 UIKitCore 0x00007fff485689b6 -[UIViewController setValue:forKey:] + 87
5 UIKitCore 0x00007fff48874ad3 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00007fff23e29fe2 -[NSArray makeObjectsPerformSelector:] + 242
7 UIKitCore 0x00007fff48871cbc -[UINib instantiateWithOwner:options:] + 2192
8 UIKitCore 0x00007fff4856fdbe -[UIViewController _loadViewFromNibNamed:bundle:] + 379
9 UIKitCore 0x00007fff485708f5 -[UIViewController loadView] + 177
10 UIKitCore 0x00007fff48570bf4 -[UIViewController loadViewIfRequired] + 172
11 UIKitCore 0x00007fff485713a1 -[UIViewController view] + 27
12 UIKitCore 0x00007fff48c51ae1 -[UIWindow addRootViewControllerViewIfPossible] + 326
13 UIKitCore 0x00007fff48c5110a -[UIWindow _updateLayerOrderingAndSetLayerHidden:actionBlock:] + 219
14 UIKitCore 0x00007fff48c52195 -[UIWindow _setHidden:forced:] + 362
15 UIKitCore 0x00007fff48c655bc -[UIWindow _mainQueue_makeKeyAndVisible] + 42
16 UIKitCore 0x00007fff48e84d2c -[UIWindowScene _makeKeyAndVisibleIfNeeded] + 202
17 UIKitCore 0x00007fff48177720 +[UIScene _sceneForFBSScene:create:withSession:connectionOptions:] + 1405
18 UIKitCore 0x00007fff48c15561 -[UIApplication _connectUISceneFromFBSScene:transitionContext:] + 1019
19 UIKitCore 0x00007fff48c15898 -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 291
20 UIKitCore 0x00007fff4876a160 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
21 FrontBoardServices 0x00007fff36c6091e -[FBSSceneImpl _callOutQueue_agent_didCreateWithTransitionContext:completion:] + 419
22 FrontBoardServices 0x00007fff36c869b1 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke.154 + 102
23 FrontBoardServices 0x00007fff36c6b347 -[FBSWorkspace _calloutQueue_executeCalloutFromSource:withBlock:] + 220
24 FrontBoardServices 0x00007fff36c86642 __86-[FBSWorkspaceScenesClient sceneID:createWithParameters:transitionContext:completion:]_block_invoke + 355
25 libdispatch.dylib 0x00000001075eee8e _dispatch_client_callout + 8
26 libdispatch.dylib 0x00000001075f1da2 _dispatch_block_invoke_direct + 300
27 FrontBoardServices 0x00007fff36cac2d9 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 30
28 FrontBoardServices 0x00007fff36cabfc7 -[FBSSerialQueue _queue_performNextIfPossible] + 441
29 FrontBoardServices 0x00007fff36cac4d6 -[FBSSerialQueue _performNextFromRunLoopSource] + 22
30 CoreFoundation 0x00007fff23da1c71 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
31 CoreFoundation 0x00007fff23da1b9c __CFRunLoopDoSource0 + 76
32 CoreFoundation 0x00007fff23da13cc __CFRunLoopDoSources0 + 268
33 CoreFoundation 0x00007fff23d9bf6e __CFRunLoopRun + 974
34 CoreFoundation 0x00007fff23d9b884 CFRunLoopRunSpecific + 404
35 GraphicsServices 0x00007fff38b5ac1a GSEventRunModal + 139
36 UIKitCore 0x00007fff48c19220 UIApplicationMain + 1605
37 FoodTracker 0x000000010737880b main + 75
38 libdyld.dylib 0x00007fff519b910d start + 1
39 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Thanks for your help in advance.

Error while Launching saying NSInternalInconsistencyException

Need help. receiving below error while launching the application
Objective-C exception thrown. Name: NSInternalInconsistencyException Reason: Application windows are expected to have a root view controller at the end of application launch
Native stack trace:
0 CoreFoundation 0x00000001160421e6 exceptionPreprocess + 294
1 libobjc.A.dylib 0x0000000116fdf031 objc_exception_throw + 48
2 CoreFoundation 0x0000000116047472 +[NSException raise:format:arguments:] + 98
3 Foundation 0x0000000114f7b652 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 193
4 UIKit 0x0000000112d1bb96 -[UIApplication _runWithMainScene:transitionContext:completion:] + 3064
5 UIKit 0x00000001130dde4a __111-[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:]_block_invoke + 866
6 UIKit 0x00000001134b0909 +[_UICanvas _enqueuePostSettingUpdateTransactionBlock:] + 153
7 UIKit 0x00000001130dda86 -[__UICanvasLifecycleMonitor_Compatability _scheduleFirstCommitForScene:transition:firstActivation:completion:] + 236
8 UIKit 0x00000001130de2a7 -[__UICanvasLifecycleMonitor_Compatability activateEventsOnly:withContext:completion:] + 675
9 UIKit 0x0000000113a4f4d4 __82-[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:]_block_invoke + 299
10 UIKit 0x0000000113a4f36e -[_UIApplicationCanvas _transitionLifecycleStateWithTransitionContext:completion:] + 433
11 UIKit 0x000000011373362d __125-[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:]_block_invoke + 221
12 UIKit 0x000000011392e387 _performActionsWithDelayForTransitionContext + 100
13 UIKit 0x00000001137334f7 -[_UICanvasLifecycleSettingsDiffAction performActionsForCanvas:withUpdatedScene:settingsDiff:fromSettings:transitionContext:] + 223
14 UIKit 0x00000001134affb0 -[_UICanvas scene:didUpdateWithDiff:transitionContext:completion:] + 392
15 UIKit 0x0000000112d19f0c -[UIApplication workspace:didCreateScene:withTransitionContext:completion:] + 515
16 UIKit 0x00000001132eca97 -[UIApplicationSceneClientAgent scene:didInitializeWithEvent:completion:] + 361
17 FrontBoardServices 0x000000011d9c32f3 -[FBSSceneImpl _didCreateWithTransitionContext:completion:] + 331
18 FrontBoardServices 0x000000011d9cbcfa __56-[FBSWorkspace client:handleCreateScene:withCompletion:]_block_invoke_2 + 225
19 libdispatch.dylib 0x0000000117c74779 _dispatch_client_callout + 8
20 libdispatch.dylib 0x0000000117c79931 _dispatch_block_invoke_direct + 317
21 FrontBoardServices 0x000000011d9f7470 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK + 24
22 FrontBoardServices 0x000000011d9f712e -[FBSSerialQueue _performNext] + 439
23 FrontBoardServices 0x000000011d9f768e -[FBSSerialQueue _performNextFromRunLoopSource] + 45
24 CoreFoundation 0x0000000115fe4bb1 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
25 CoreFoundation 0x0000000115fc94af __CFRunLoopDoSources0 + 271
26 CoreFoundation 0x0000000115fc8a6f __CFRunLoopRun + 1263
27 CoreFoundation 0x0000000115fc830b CFRunLoopRunSpecific + 635
28 GraphicsServices 0x0000000119779a73 GSEventRunModal + 62
29 UIKit 0x0000000112d1d0b7 UIApplicationMain + 159
30 ??? 0x000000013437347e 0x0 + 5171000446
31 ??? 0x0000000134373213 0x0 + 5170999827
Application windows are expected to have a root view controller at the end of application
It seems that you didn't set the RootViewController.It worked fine in old version.But in the new version ,you should set it in AppDelegate
public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
{
// Override point for customization after application launch.
// If not required for your application you can safely delete this method
var indexVC = new XXXViewController ();//your viewcontroller
Window = new UIWindow ((CGRect)UIScreen.MainScreen.Bounds);
Window .RootViewController = indexVC;
Window .MakeKeyAndVisible ();
return true;
}

[NSSearchField object]: unrecognized selector sent to instance

I'm testing Swift in a simple Mac app. I got a NSToolbar in Storyboard and draw a NSSearchfield inside. The NSSearchfiled is connected to the First Responder's method controlTextDidChange (the first responder is the ViewController where I added NSTextFieldDelegate).
This is the method:
#IBAction override func controlTextDidChange(obj: NSNotification!) {
println("searching...")
println(obj.object.stringValue)
}
The method gets correctly called every time a new character is searched and the app does not crash however what's being returned is the following:
searching...
2014-08-03 09:56:57.770 TestApp[1129:24219] -[NSSearchField object]: unrecognized selector sent to instance 0x6080001a07e0
2014-08-03 09:56:57.770 TestApp[1129:24219] -[NSSearchField object]: unrecognized selector sent to instance 0x6080001a07e0
2014-08-03 09:56:57.775 TestApp[1129:24219] (
0 CoreFoundation 0x00007fff92e6af1c __exceptionPreprocess + 172
1 libobjc.A.dylib 0x00007fff930ae74e objc_exception_throw + 43
2 CoreFoundation 0x00007fff92e6de4d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff92db63c4 ___forwarding___ + 1028
4 CoreFoundation 0x00007fff92db5f38 _CF_forwarding_prep_0 + 120
5 TestApp 0x000000010000c187 _TFC9TestApp14ViewController20controlTextDidChangefS0_FGSQCSo14NSNotification_T_ + 231
6 TestApp 0x000000010000c582 _TToFC9TestApp14ViewController20controlTextDidChangefS0_FGSQCSo14NSNotification_T_ + 66
7 libsystem_trace.dylib 0x00007fff9117bc07 _os_activity_initiate + 75
8 AppKit 0x00007fff8d52b168 -[NSApplication sendAction:to:from:] + 410
9 AppKit 0x00007fff8d52af90 -[NSControl sendAction:to:] + 86
10 AppKit 0x00007fff8d6faf91 __26-[NSCell _sendActionFrom:]_block_invoke + 131
11 libsystem_trace.dylib 0x00007fff9117bc07 _os_activity_initiate + 75
12 AppKit 0x00007fff8d57329e -[NSCell _sendActionFrom:] + 144
13 AppKit 0x00007fff8d92fe8f __64-[NSSearchFieldCell(NSSearchFieldCell_Local) _sendPartialString]_block_invoke + 63
14 libsystem_trace.dylib 0x00007fff9117bc07 _os_activity_initiate + 75
15 AppKit 0x00007fff8d92fe47 -[NSSearchFieldCell(NSSearchFieldCell_Local) _sendPartialString] + 186
16 Foundation 0x00007fff932ee3d3 __NSFireTimer + 95
17 CoreFoundation 0x00007fff92dbf464 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
18 CoreFoundation 0x00007fff92dbf0f3 __CFRunLoopDoTimer + 1059
19 CoreFoundation 0x00007fff92e320fd __CFRunLoopDoTimers + 301
20 CoreFoundation 0x00007fff92d7b4d2 __CFRunLoopRun + 2018
21 CoreFoundation 0x00007fff92d7aaa8 CFRunLoopRunSpecific + 296
22 HIToolbox 0x00007fff90adcaff RunCurrentEventLoopInMode + 235
23 HIToolbox 0x00007fff90adc872 ReceiveNextEventCommon + 431
24 HIToolbox 0x00007fff90adc6b3 _BlockUntilNextEventMatchingListInModeWithFilter + 71
25 AppKit 0x00007fff8d35c2a5 _DPSNextEvent + 1000
26 AppKit 0x00007fff8d35ba79 -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 139
27 AppKit 0x00007fff8d34fad3 -[NSApplication run] + 594
28 AppKit 0x00007fff8d33b2de NSApplicationMain + 1778
29 TestApp 0x000000010000da72 top_level_code + 34
30 TestApp 0x000000010000daaa main + 42
31 libdyld.dylib 0x00007fff8cb765c9 start + 1
32 ??? 0x0000000000000003 0x0 + 3
)
I can't figure out where the "unrecognized selector sent to instance" comes from.
controlTextDidChange method expects NSSearchField!, not NSNotification!.
Replace
#IBAction override func controlTextDidChange(obj: NSNotification!) {
println("searching...")
println(obj.object.stringValue)
}
with
#IBAction override func controlTextDidChange(obj: NSSearchField!) {
println("searching...")
println(obj.stringValue)
}
Solved by defining a custom method
#IBAction func controlTextDidChange_Custom(obj: NSSearchField!) {
if (!obj.stringValue.isEmpty) {
println("Searched: \(obj.stringValue)")
} else {
println("EMPTY")
}
}

Terminating app due to uncaught exception error

The app is supposed to save data in Text Fields when I click return on the keyboard. The app crashes when I click the return key. I have connected the IBActions to the textfields with "Did End on Exit" in .xib". Here is the error log:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSPlaceholderString initWithFormat:locale:arguments:]: nil argument'
*** First throw call stack:
(
0 CoreFoundation 0x0173b5e4 __exceptionPreprocess + 180
1 libobjc.A.dylib 0x014be8b6 objc_exception_throw + 44
2 CoreFoundation 0x0173b3bb +[NSException raise:format:] + 139
3 Foundation 0x010da664 -[NSPlaceholderString initWithFormat:locale:arguments:] + 99
4 Foundation 0x010da5f4 -[NSString initWithFormat:] + 58
5 Attendance 0x00002ded -[ShiftAController1 saveRoster1:] + 157
6 libobjc.A.dylib 0x014d081f -[NSObject performSelector:withObject:] + 70
7 UIKit 0x0022e0c2 -[UIApplication sendAction:to:from:forEvent:] + 108
8 UIKit 0x0022e04e -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 61
9 UIKit 0x003260c1 -[UIControl sendAction:to:forEvent:] + 66
10 UIKit 0x00326484 -[UIControl _sendActionsForEvents:withEvent:] + 577
11 UIKit 0x0032da28 -[UIFieldEditor insertText:] + 263
12 UIKit 0x0091771f -[UITextField insertText:] + 59
13 UIKit 0x00409b40 -[UIKeyboardImpl insertText:] + 87
14 UIKit 0x0041af14 -[TIKeyboardOperationInsertText(UIKeyboardImpl) main] + 83
15 Foundation 0x01193829 -[__NSOperationInternal _start:] + 671
16 Foundation 0x01110558 -[NSOperation start] + 83
17 UIKit 0x004081cd -[UIKeyboardImpl performOperations:] + 153
18 UIKit 0x0040640b -[UIKeyboardImpl continueHandleKeyboardInputWithOperations:] + 40
19 UIKit 0x0040627c __73-[UIKeyboardImpl replyHandlerForHandleKeyboardInputWithExecutionContext:]_block_invoke_2 + 44
20 UIKit 0x0093b3c8 -[UIKeyboardTaskQueue continueExecutionOnMainThread] + 402
21 libobjc.A.dylib 0x014d081f -[NSObject performSelector:withObject:] + 70
22 Foundation 0x011139d8 __NSThreadPerformPerform + 285
23 CoreFoundation 0x016c483f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15
24 CoreFoundation 0x016c41cb __CFRunLoopDoSources0 + 235
25 CoreFoundation 0x016e129e __CFRunLoopRun + 910
26 CoreFoundation 0x016e0ac3 CFRunLoopRunSpecific + 467
27 CoreFoundation 0x016e08db CFRunLoopRunInMode + 123
28 GraphicsServices 0x036e09e2 GSEventRunModal + 192
29 GraphicsServices 0x036e0809 GSEventRun + 104
30 UIKit 0x0022cd3b UIApplicationMain + 1225
31 Attendance 0x00003a1d main + 141
32 libdyld.dylib 0x01d7970d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
This is my code in .m:
-(IBAction)saveRoster1:(id)sender{
myString1 = [[NSString alloc] initWithFormat:roster1.text];
[roster1 setText:myString1];
NSUserDefaults *stringDefault1 = [NSUserDefaults standardUserDefaults];
[stringDefault1 setObject:myString1 forKey:#"stringKey1"];}
-(IBAction)savetimeIn:(id)sender{
myString2 = [[NSString alloc] initWithFormat:timeIn.text];
[timeIn setText:myString2];
NSUserDefaults *stringDefault2 = [NSUserDefaults standardUserDefaults];
[stringDefault2 setObject:myString2 forKey:#"stringKey2"];}
-(IBAction)savetimeOut:(id)sender{
myString3 = [[NSString alloc] initWithFormat:timeOut.text];
[timeOut setText:myString3];
NSUserDefaults *stringDefault3 = [NSUserDefaults standardUserDefaults];
[stringDefault3 setObject:myString3 forKey:#"stringKey3"];}

Resources