Quick nimble variable is always nil - swift

I create a basic test case, I cannot instantiate the variable. And while test is running, it always crashes.
import Foundation
import XCTest
import Quick
import Nimble
import UIKit
#testable import tar22102
class ViewControllerTests: QuickSpec {
override func spec() {
var vc: ViewController?
beforeEach{               
vc = ViewController()
let _ = vc?.view
}
describe("testing Initial values") {
context("Reading values") {
expect(vc).toNot(beNil())
}
}
}
This is the crash log. I put breakpoint to the lines in the beforeEach, it would not reach. I also have switched to several different projects. The same issue happens.
2020-07-18 07:49:36.935064-0400 tar22102[15304:300447] Launching with XCTest injected. Preparing to run tests.
2020-07-18 07:49:37.263912-0400 tar22102[15304:300447] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An exception occurred when building Quick's example groups.
Some possible reasons this might happen include:
- An 'expect(...).to' expectation was evaluated outside of an 'it', 'context', or 'describe' block
- 'sharedExamples' was called twice with the same name
- 'itBehavesLike' was called with a name that is not registered as a shared example
Here's the original exception: 'NSInternalInconsistencyException', reason: 'Attempted to report a test failure to XCTest while no test case was running. The failure was:
"expected to not be nil, got <nil>
"
It occurred at: /Users/hzhan25/Desktop/DD/22102/22102Tests/_2102Tests.swift:27', userInfo: '(null)''
*** First throw call stack:
(
0 CoreFoundation 0x000000010eb8327e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x000000010ce4db20 objc_exception_throw + 48
2 CoreFoundation 0x000000010eb830bc +[NSException raise:format:] + 188
3 22102Tests 0x000000012b7dc8f9 __23+[QuickSpec initialize]_block_invoke + 457
4 22102Tests 0x000000012b7f8cda $sIyB_Ieg_TR + 10
5 22102Tests 0x000000012b7f8b82 $s5Quick5WorldC30performWithCurrentExampleGroup_7closureyAA0fG0C_yyXEtF + 370
6 22102Tests 0x000000012b7f8c9b $s5Quick5WorldC30performWithCurrentExampleGroup_7closureyAA0fG0C_yyXEtFTo + 107
7 22102Tests 0x000000012b7dc705 +[QuickSpec initialize] + 229
8 libobjc.A.dylib 0x000000010ce4e103 CALLING_SOME_+initialize_METHOD + 17
9 libobjc.A.dylib 0x000000010ce4eee9 initializeNonMetaClass + 624
10 libobjc.A.dylib 0x000000010ce4f4ba _ZL24initializeAndMaybeRelockP10objc_classP11objc_objectR8mutex_ttILb0EEb + 157
11 libobjc.A.dylib 0x000000010ce59a5d lookUpImpOrForward + 595
12 libobjc.A.dylib 0x000000010ce4a219 _objc_msgSend_uncached + 73
13 Foundation 0x000000010d12852b -[NSBundle loadAndReturnError:] + 1141
14 libXCTestBundleInject.dylib 0x000000010cc46719 __XCTestBundleInject + 538
15 ??? 0x000000010cbb53a7 0x0 + 4508570535
16 ??? 0x000000010cbb57b8 0x0 + 4508571576
17 ??? 0x000000010cbb09a2 0x0 + 4508551586
18 ??? 0x000000010cbaf7a6 0x0 + 4508546982
19 ??? 0x000000010cbaf846 0x0 + 4508547142
20 ??? 0x000000010cba4046 0x0 + 4508500038
21 ??? 0x000000010cba80fc 0x0 + 4508516604
22 ??? 0x000000010cba31cd 0x0 + 4508496333
23 ??? 0x000000010d055234 0x0 + 4513419828
24 ??? 0x000000010d0530ce 0x0 + 4513411278
25 ??? 0x000000010d04e503 0x0 + 4513391875
26 ??? 0x000000010d04e036 0x0 + 4513390646
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Matcher calls need to be inside an it block
describe("Initial values") {
it("Sets vc") {
expect(vc).toNot(beNil())
}
}

Related

'NSInvalidArgumentException', reason: '*** -getValue: only defined for abstract class. Define -[KotlinInt getValue:]!'

I am using Kotlin multiplatform to build framework for iOS, and everything works well except the strange issue.
The code from Kotlin:
fun example(): Map<Int, Double> {
val result = mutableMapOf<Int, Double>()
result[1] = 9.99
return result
}
Using framework is Swift:
let example = example()
The app will crash and display the trace as following
2019-10-30 15:37:19.096474+0800 Test[73756:3057881] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -getValue: only defined for abstract class. Define -[KotlinInt getValue:]!'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23baa1ee __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50864b20 objc_exception_throw + 48
2 Foundation 0x00007fff2584a6b3 _NSRequestConcreteObject + 0
3 Foundation 0x00007fff256bea7e -[NSNumber copyWithZone:] + 129
4 CoreFoundation 0x00007fff23add550 __NSSingleEntryDictionaryI_new + 128
5 CoreFoundation 0x00007fff23ba56f3 -[NSDictionary initWithDictionary:copyItems:] + 403
6 CoreFoundation 0x00007fff23c07fc7 -[__NSPlaceholderDictionary initWithDictionary:copyItems:] + 135
7 libswiftFoundation.dylib 0x00007fff511ef3a0 $sSD10FoundationE26_forceBridgeFromObjectiveC_6resultySo12NSDictionaryC_SDyxq_GSgztFZ + 192
8 libswiftFoundation.dylib 0x00007fff511e3593 $sSD10FoundationE36_unconditionallyBridgeFromObjectiveCySDyxq_GSo12NSDictionaryCSgFZ + 67
9 Test 0x0000000102f54320 $s4Test11ContentViewV3calSSyF + 1104
10 Test 0x0000000102f53e3b $s4Test11ContentViewV4bodyQrvg + 91
11 Test 0x0000000102f549c1 $s4Test11ContentViewV7SwiftUI0C0AadEP4body4BodyQzvgTW + 17
12 SwiftUI 0x00007fff2bfb1c49 $s7SwiftUI8ViewBody33_9F92ACD17B554E8AB7D29ABB1E796415LLV5applyy0D0QzxF + 585
13 SwiftUI 0x00007fff2bfb2df9 $s7SwiftUI8ViewBody33_9F92ACD17B554E8AB7D29ABB1E796415LLVyxG14AttributeGraph07UntypedM0AafGP7_update_5graph9attributeySv_So10AGGraphRefaSo11AGAttributeatFZTW + 137
14 AttributeGraph 0x00007fff2f8f1849 $sTA + 25
15 AttributeGraph 0x00007fff2f8d9255 _ZN2AG5Graph11UpdateStack6updateEv + 1111
16 AttributeGraph 0x00007fff2f8d9513 _ZN2AG5Graph16update_attributeEjb + 377
17 AttributeGraph 0x00007fff2f8de131 _ZN2AG8Subgraph6updateEj + 929
18 SwiftUI 0x00007fff2c10d100 $s7SwiftUI9ViewGraphC14runTransaction33_D63C4EB7F2B205694B6515509E76E98BLL2inySo10AGGraphRefa_tF + 224
19 SwiftUI 0x00007fff2c10d517 $s7SwiftUI9ViewGraphC13updateOutputs2atyAA4TimeV_tFSb5prefs_Sb9idealSizeAC0F0V7outputstSo10AGGraphRefaXEfU_ + 103
20 SwiftUI 0x00007fff2c10d1d1 $s7SwiftUI9ViewGraphC13updateOutputs2atyAA4TimeV_tF + 145
21 SwiftUI 0x00007fff2c4af579 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_yyXEfU_ + 1001
22 SwiftUI 0x00007fff2c4aef8a $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtFyyXEfU_ + 634
23 SwiftUI 0x00007fff2c4a4274 $s7SwiftUI16ViewRendererHostPAAE6render8interval17updateDisplayListySd_SbtF + 436
24 SwiftUI 0x00007fff2c65a182 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyF + 226
25 SwiftUI 0x00007fff2c65a1a5 $s7SwiftUI14_UIHostingViewC14layoutSubviewsyyFTo + 21
26 UIKitCore 0x00007fff47a52ad5 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
27 QuartzCore 0x00007fff2b06e91d -[CALayer layoutSublayers] + 255
28 QuartzCore 0x00007fff2b073323 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
29 QuartzCore 0x00007fff2b07fa7c _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
30 QuartzCore 0x00007fff2afc6e54 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
31 QuartzCore 0x00007fff2affc32f _ZN2CA11Transaction6commitEv + 643
32 UIKitCore 0x00007fff475906cd __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
33 CoreFoundation 0x00007fff23b0d09c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
34 CoreFoundation 0x00007fff23b0c808 __CFRunLoopDoBlocks + 312
35 CoreFoundation 0x00007fff23b07694 __CFRunLoopRun + 1284
36 CoreFoundation 0x00007fff23b06e66 CFRunLoopRunSpecific + 438
37 GraphicsServices 0x00007fff38346bb0 GSEventRunModal + 65
38 UIKitCore 0x00007fff47578dd0 UIApplicationMain + 1621
39 Test 0x0000000102f526fb main + 75
40 libdyld.dylib 0x00007fff516ecd29 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Actually, I want to implement the function to return the Map, but I inspect the type of example() in the Xocde's IDE is [KotlinInt : KotlinDouble]. I don't know how to fix this to use this function in the Xcode normally without the exception.
I thought there is no structure type "Map" in Kotlin corresponding to "Dictionary" in iOS Swift. Try to replace the Map with MutableMap and solve this issue.
fun example(): MutableMap <Int, Double> {
val result = mutableMapOf<Int, Double>()
result[1] = 9.99
return result
}
However, you can also cast the type in Swift for another using. For example,
let example = example() as! [Int64 : Double]
Map exist in kotlin, here an example:
val map = mutableMapOf(1 to 1.2, 2 to 1.2, 3 to 1.5)
println(map)
map[4] = 3.4
println(map)
output:
{1=1.2, 2=1.2, 3=1.5}
{1=1.2, 2=1.2, 3=1.5, 4=3.4}

AVAudioPlayer.play() works but AVAudioPlayerNode.play() fails

I have the following Swift playground code that plays an audio file using AVAudioPlayerNode.
import AVFoundation
import Foundation
NSSetUncaughtExceptionHandler { exception in
print("Exception thrown: \(exception)")
}
var filePath = "/Users/fractor/Desktop/TestFile.mp3"
let file : AVAudioFile
do {
file = try AVAudioFile(forReading: URL(fileURLWithPath: filePath))
} catch let error {
print(error.localizedDescription)
throw error
}
let audioEngine = AVAudioEngine()
let playerNode = AVAudioPlayerNode()
audioEngine.attach(playerNode)
audioEngine.connect(playerNode, to: audioEngine.outputNode, format: file.processingFormat);
do {
try audioEngine.start()
} catch let error {
print(error.localizedDescription)
throw error
}
playerNode.scheduleFile(file, at: nil){}
playerNode.play();
This works fine on my mac mini when using the inbuilt speaker or when connected to a UE WONDERBOOM bluetooth speaker. However it crashes when connected to a UE BOOM 2 bluetooth speaker.
Using AVAudioPlayer works fine with all speakers I have tried including the UE BOOM 2.
The exception message is "player started when engine not running" however inserting print commands shows that the engine is running prior to playerNode.play() being called.
Here's (part of) the stack trace.
What does EXC_BAD_INSTRUCTION indicate in this case?
To remove the possibility of erroneous behaviour being introduced due to using a Swift playground, I have also created a Swift macOS Cocoa app. Here is the code:
class ViewController: NSViewController {
let filePath = "/Users/fractor/Desktop/TestFile.mp3"
var file : AVAudioFile?
var audioEngine = AVAudioEngine()
var playerNode = AVAudioPlayerNode()
override func viewDidLoad() {
super.viewDidLoad()
do {
file = try AVAudioFile(forReading: URL(fileURLWithPath: filePath))
} catch let error {
print(error.localizedDescription)
return
}
audioEngine.attach(playerNode)
audioEngine.connect(playerNode, to: audioEngine.outputNode, format: file!.processingFormat);
do {
try audioEngine.start()
} catch let error {
print(error.localizedDescription)
return
}
playerNode.scheduleFile(file!, at: nil){}
print("audioEngine.isRunning = \(audioEngine.isRunning)");
playerNode.play();
print("playerNode.isPlaying = \(playerNode.isPlaying)");
}
}
This fails to play when connected to the UE BOOM 2 speaker with the following errors:
2019-07-23 13:32:50.784444+0100 AVAudioPlayerNodeSwiftTest[1757:29297] [AudioHAL_Client] HALC_ProxyIOContext.cpp:958:IOWorkLoop: HALC_ProxyIOContext::IOWorkLoop: the server failed to start, Error: 0xE00002D6
2019-07-23 13:32:51.696089+0100 AVAudioPlayerNodeSwiftTest[1757:29249] Failed to set (contentViewController) user defined inspected property on (NSWindow): player started when engine not running
2019-07-23 13:32:53.815222+0100 AVAudioPlayerNodeSwiftTest[1757:29448] [AudioHAL_Client] HALC_ProxyIOContext.cpp:958:IOWorkLoop: HALC_ProxyIOContext::IOWorkLoop: the server failed to start, Error: 0xE00002D6
Again this works fine with the WONDERBOOM speaker and the inbuilt speaker.
I manage to get an exception trace if I call play on a background thread using the following code:
DispatchQueue.global(qos: .background).async {
print("audioEngine.isRunning = \(self.audioEngine.isRunning)");
self.playerNode.play();
print("playerNode.isPlaying = \(self.playerNode.isPlaying)");
}
The full output being:
audioEngine.isRunning = true
2019-07-24 12:25:38.710647+0100 AVAudioPlayerNodeSwiftTest[1852:21353] [AudioHAL_Client] HALC_ProxyIOContext.cpp:958:IOWorkLoop: HALC_ProxyIOContext::IOWorkLoop: the server failed to start, Error: 0xE00002D6
2019-07-24 12:25:40.717683+0100 AVAudioPlayerNodeSwiftTest[1852:21340] [General] An uncaught exception was raised
2019-07-24 12:25:40.717738+0100 AVAudioPlayerNodeSwiftTest[1852:21340] [General] player started when engine not running
2019-07-24 12:25:40.717865+0100 AVAudioPlayerNodeSwiftTest[1852:21340] [General] (
0 CoreFoundation 0x00007fff2d017cfd __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff576bea17 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2d032a1a +[NSException raise:format:arguments:] + 98
3 AVFAudio 0x00007fff291f2304 _Z19AVAE_RaiseExceptionP8NSStringz + 156
4 AVFAudio 0x00007fff29247d8c _ZN21AVAudioPlayerNodeImpl9StartImplEP11AVAudioTime + 1282
5 AVFAudio 0x00007fff29246b48 -[AVAudioPlayerNode play] + 75
6 AVAudioPlayerNodeSwiftTest 0x0000000100002924 $s26AVAudioPlayerNodeSwiftTest14ViewControllerC11viewDidLoadyyFyycfU0_ + 644
7 AVAudioPlayerNodeSwiftTest 0x0000000100002b8d $s26AVAudioPlayerNodeSwiftTest14ViewControllerC11viewDidLoadyyFyycfU0_TA + 13
8 AVAudioPlayerNodeSwiftTest 0x00000001000025dd $sIeg_IeyB_TR + 45
9 libdispatch.dylib 0x000000010034fe7c _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x0000000100350f1b _dispatch_client_callout + 8
11 libdispatch.dylib 0x0000000100363a06 _dispatch_root_queue_drain + 816
12 libdispatch.dylib 0x00000001003642da _dispatch_worker_thread2 + 125
13 libsystem_pthread.dylib 0x00000001003ca0b7 _pthread_wqthread + 583
14 libsystem_pthread.dylib 0x00000001003c9e01 start_wqthread + 13
)
2019-07-24 12:25:40.718570+0100 AVAudioPlayerNodeSwiftTest[1852:21340] *** Terminating app due to uncaught exception 'com.apple.coreaudio.avfaudio', reason: 'player started when engine not running'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff2d017cfd __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff576bea17 objc_exception_throw + 48
2 CoreFoundation 0x00007fff2d032a1a +[NSException raise:format:arguments:] + 98
3 AVFAudio 0x00007fff291f2304 _Z19AVAE_RaiseExceptionP8NSStringz + 156
4 AVFAudio 0x00007fff29247d8c _ZN21AVAudioPlayerNodeImpl9StartImplEP11AVAudioTime + 1282
5 AVFAudio 0x00007fff29246b48 -[AVAudioPlayerNode play] + 75
6 AVAudioPlayerNodeSwiftTest 0x0000000100002924 $s26AVAudioPlayerNodeSwiftTest14ViewControllerC11viewDidLoadyyFyycfU0_ + 644
7 AVAudioPlayerNodeSwiftTest 0x0000000100002b8d $s26AVAudioPlayerNodeSwiftTest14ViewControllerC11viewDidLoadyyFyycfU0_TA + 13
8 AVAudioPlayerNodeSwiftTest 0x00000001000025dd $sIeg_IeyB_TR + 45
9 libdispatch.dylib 0x000000010034fe7c _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x0000000100350f1b _dispatch_client_callout + 8
11 libdispatch.dylib 0x0000000100363a06 _dispatch_root_queue_drain + 816
12 libdispatch.dylib 0x00000001003642da _dispatch_worker_thread2 + 125
13 libsystem_pthread.dylib 0x00000001003ca0b7 _pthread_wqthread + 583
14 libsystem_pthread.dylib 0x00000001003c9e01 start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Again, no problem if using the WONDERBOOM or built in speaker.
People are also having a problem here: https://forums.developer.apple.com/thread/118459
AudioKit also crashes: AudioKit macOS HelloWorld crashes with UE BOOM 2 speaker
AVAudioPlayer is not sufficient for the application I am developing. What is the problem? Presumably since it throws an exception, it is a bug in Apple code?

segue with timer causing signal sigbart

let timer = NSTimer.scheduledTimerWithTimeInterval(8.0, target: self, selector: "timeToMoveOn", userInfo: nil, repeats: false)
func timeToMoveOn() {
self.performSegueWithIdentifier("omar", sender: nil)
}
are causing :
libc++abi.dylib: terminating with uncaught exception of type
NSException (lldb)
error log:
2015-07-31 22:22:34.014 Shiltawi[1236:21701] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<Shiltawi.ViewController2: 0x7f96b1ee2fa0>) has no segue with identifier 'omar''
*** First throw call stack:
(
0 CoreFoundation 0x000000010c318c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010e6dbbb7 objc_exception_throw + 45
2 UIKit 0x000000010d542473 -[UIViewController shouldPerformSegueWithIdentifier:sender:] + 0
3 Shiltawi 0x000000010b825198 _TFC8Shiltawi15ViewController212timeToMoveOnfS0_FT_T_ + 232
4 Shiltawi 0x000000010b8251f2 _TToFC8Shiltawi15ViewController212timeToMoveOnfS0_FT_T_ + 34
5 Foundation 0x000000010c995744 __NSFireTimer + 83
6 CoreFoundation 0x000000010c280174 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
7 CoreFoundation 0x000000010c27fd35 __CFRunLoopDoTimer + 1045
8 CoreFoundation 0x000000010c241d3d __CFRunLoopRun + 1901
9 CoreFoundation 0x000000010c241366 CFRunLoopRunSpecific + 470
10 GraphicsServices 0x0000000110243a3e GSEventRunModal + 161
11 UIKit 0x000000010d40f8c0 UIApplicationMain + 1282
12 Shiltawi 0x000000010b8507d7 main + 135
13 libdyld.dylib 0x000000010ee1d145 start + 1
14 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
You are missing to assign an identifier to your segue.
First of all click on the segue which you want to perform in your storyBoard after that go to Attribute inspector at the right side then add an identifier to it as shown in below image:
After that it will work fine.

Swift - Editing UITextView from inside callback crashes app

I have the following code that makes a HTTP Request, then outputs the result to a UITextView:
#IBOutlet var echoLog: UITextView!
#IBAction func sendEcho(sender: AnyObject) {
let callback = { (textString: String) -> Void in
self.echoLog.text = textString // App crashes here :(
}
HTTPRequest("http://localhost/echo", ["echo": "Echo!"], callback)
}
But when I call sendEcho the app crashes with this error:
2014-07-28 20:58:22.218 AppName[10463:144343] *** Assertion failure in void _UIPerformResizeOfTextViewForTextContainer(NSLayoutManager *, UIView<NSTextContainerView> *, NSTextContainer *, NSUInteger)(), /SourceCache/UIFoundation_Sim/UIFoundation-364/UIFoundation/TextSystem/NSLayoutManager_Private.m:1547
2014-07-28 20:58:22.231 AppName[10463:144343] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Only run on the main thread!'
*** First throw call stack:
(
0 CoreFoundation 0x00496ca6 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x01df08bf objc_exception_throw + 44
2 CoreFoundation 0x00496b3a +[NSException raise:format:arguments:] + 138
3 Foundation 0x00904d2e -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 102
4 UIFoundation 0x03344072 -[NSLayoutManager(NSPrivate) _resizeTextViewForTextContainer:] + 418
5 UIFoundation 0x03343d6e -[NSLayoutManager(NSPrivate) _recalculateUsageForTextContainerAtIndex:] + 2017
6 UIFoundation 0x0337da43 -[NSLayoutManager textStorage:edited:range:changeInLength:invalidatedRange:] + 871
7 UIFoundation 0x0337db53 -[NSLayoutManager processEditingForTextStorage:edited:range:changeInLength:invalidatedRange:] + 85
8 UIFoundation 0x033a7a7b -[NSTextStorage _notifyEdited:range:changeInLength:invalidatedRange:] + 153
9 UIFoundation 0x033a759a -[NSTextStorage processEditing] + 458
10 UIFoundation 0x033a7124 -[NSTextStorage endEditing] + 80
11 UIFoundation 0x033a71af -[NSTextStorage coordinateEditing:] + 67
12 UIKit 0x014938ae -[UITextView setAttributedText:] + 250
13 UIKit 0x01499745 -[UITextView setText:] + 149
14 AppName 0x00036216 _TFFC8AppName19FirstViewController8sendEchoFS0_FPSs9AnyObject_T_U_FOS_9JSONValueT_ + 1350
15 AppName 0x0003525a _TPA__TFFC8AppName19FirstViewController8sendEchoFS0_FPSs9AnyObject_T_U_FOS_9JSONValueT_ + 106
16 AppName 0x0001de86 _TFF8AppName11HTTPRequestFTSSGVSs10DictionarySSPSs9AnyObject__FOS_9JSONValueT__T_U_FTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError__T_ + 1350
17 AppName 0x0001d0a4 _TPA__TFF8AppName11HTTPRequestFTSSGVSs10DictionarySSPSs9AnyObject__FOS_9JSONValueT__T_U_FTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError__T_ + 100
18 AppName 0x0001e289 _TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFo_iTGSQS__GSQS0__GSQS1____iT__ + 41
19 AppName 0x0001d15a _TPA__TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFo_iTGSQS__GSQS0__GSQS1____iT__ + 90
20 AppName 0x0001e2d7 _TTRXFo_iTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError___iT__XFo_oGSQS__oGSQS0__oGSQS1___dT__ + 55
21 AppName 0x0001d224 _TPA__TTRXFo_iTGSQCSo6NSData_GSQCSo13NSURLResponse_GSQCSo7NSError___iT__XFo_oGSQS__oGSQS0__oGSQS1___dT__ + 100
22 AppName 0x0001e36e _TTRXFo_oGSQCSo6NSData_oGSQCSo13NSURLResponse_oGSQCSo7NSError__dT__XFdCb_dGSQS__dGSQS0__dGSQS1___dT__ + 142
23 CFNetwork 0x02c36158 __49-[__NSCFLocalSessionTask _task_onqueue_didFinish]_block_invoke + 181
24 Foundation 0x0092da35 __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 12
25 Foundation 0x00854635 -[NSBlockOperation main] + 99
26 Foundation 0x00833a97 -[__NSOperationInternal _start:] + 700
27 Foundation 0x008337c9 -[NSOperation start] + 83
28 Foundation 0x00833613 __NSOQSchedule_f + 237
29 libdispatch.dylib 0x022ef3ff _dispatch_client_callout + 14
30 libdispatch.dylib 0x022d8578 _dispatch_queue_drain + 1424
31 libdispatch.dylib 0x022d7f90 _dispatch_queue_invoke + 142
32 libdispatch.dylib 0x022d9e06 _dispatch_root_queue_drain + 312
33 libdispatch.dylib 0x022dae67 _dispatch_worker_thread2 + 45
34 libsystem_pthread.dylib 0x0263fdab _pthread_wqthread + 336
35 libsystem_pthread.dylib 0x02643cce start_wqthread + 30
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Thanks in advance!
It looks like your problem is that you are not on the mainThread, by the second line in the trace.
You are probably still running code in the background, due to the nature of HTTPRequest asynchronous handling of data... that's fine. You just need to get to the main thread, after all is said and done.
Here's how to probably fix it...
#IBAction func sendEcho(sender: AnyObject)
{
let callback = {(textString: String) in
dispatch_sync(dispatch_get_main_queue())
{
self.echoLog.text = textString //Yay!
}
}
HTTPRequest("http://localhost/echo", ["echo": "Echo!"], callback)
}
Reminder time UI updates should only be performed on the mainThread. Simply because doing so provides high priority for this thing to occur. Usually when you try to do UI updates on a background thread, you will see a delay between when the code is executed and when you see results. In this case, an Assertion failure (I like that). If you do not know if you are on the main thread, you can check it out by doing NSThread.isMainThread() which returns a bool.
Warning If you are already on the main thread while calling dispatch_sync(dispatch_get_main_queue()) {...} your app will freeze up, so make sure you know what thread you are on...
Apple will only let you modify UI components on the main event loop. It appears that the HTTPRequest is running callback on a background thread so you will have to explicitly run the change on the main thread:
let callback = { (textString: String) -> Void in
dispatch_async(dispatch_get_main_queue(), {
self.echoLog.text = textString
})
}

Unit Tests Failure At Xcode 3.2.4, iOS 4.1 SDK Using Hamcrest Assertion

We upgraded to Xcode 3.2.4 with iOS 4.1 SDK, now our tests are failing.
First because of this An internal error occurred when handling command output: -[XCBuildLogCommandInvocationSectionRecorder endMarker]: unrecognized selector sent to instance 0x201aa7200 then we used the patch suggested by apple forums (http://gist.github.com/586296) and now the test fail on the first Hamcrest assertion.
NSNumber * c1 = ...
NSNumber * c2 = ...
assertThat(c1, is(c2))
Here's the log:
-[NSCFNumber conformsToProtocol:]: unrecognized selector sent to instance 0x2116890
2010-09-30 22:10:23.153 otest[21063:903] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSCFNumber conformsToProtocol:]: unrecognized selector sent to instance 0x2116890'
*** Call stack at first throw:
(
0 CoreFoundation 0x004e3b99 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x002d840e objc_exception_throw + 47
2 CoreFoundation 0x004e56ab -[NSObject(NSObject) doesNotRecognizeSelector:] + 187
3 CoreFoundation 0x004552b6 ___forwarding___ + 966
4 CoreFoundation 0x00454e72 _CF_forwarding_prep_0 + 50
5 OCHamcrest 0x00ccd17b HC_wrapInMatcher + 52
6 OCHamcrest 0x00ccb4e1 HC_is + 41
7 UnitTests 0x030870c9 -[MyTest testMethod] + 141
8 CoreFoundation 0x004545cd __invoking___ + 29
9 CoreFoundation 0x004544a1 -[NSInvocation invoke] + 145
10 SenTestingKit 0x2010464a -[SenTestCase invokeTest] + 69
11 SenTestingKit 0x20104d1f -[SenTestCase performTest:] + 192
12 SenTestingKit 0x2010444b -[SenTest run] + 88
13 SenTestingKit 0x20106fa7 -[SenTestSuite performTest:] + 115
14 SenTestingKit 0x2010444b -[SenTest run] + 88
15 SenTestingKit 0x20106fa7 -[SenTestSuite performTest:] + 115
16 SenTestingKit 0x2010444b -[SenTest run] + 88
17 SenTestingKit 0x20106871 +[SenTestProbe runTests:] + 174
18 otest 0x000023b3 0x0 + 9139
19 otest 0x000025de 0x0 + 9694
20 otest 0x00002086 0x0 + 8326
21 otest 0x00002035 0x0 + 8245
22 ??? 0x00000003 0x0 + 3
)
terminate called after throwing an instance of 'NSException'
/Developer/Xcode3.2.4/Tools/RunPlatformUnitTests.include: line 415: 21063 Abort trap "${THIN_TEST_RIG}" "${OTHER_TEST_FLAGS}" "${TEST_BUNDLE_PATH}"
/Developer/Xcode3.2.4/Tools/RunPlatformUnitTests.include:451: error: Test rig '/Developer/Xcode3.2.4/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk/Developer/usr/bin/otest' exited abnormally with code 134 (it may have crashed).
Any one see that before? it was working perfectly on 3.1.3 SDK.
This is fixed, by using the latest OCHamcrest as a static library instead of a framework and add -lstdc++ to other linker flags.
Hope that save someone time.