Swift framework with a C lib inside: Got segmentation fault during working with C types - ios

I'm building swift wrapper for PJSIP C lib.
I faced with a strange behaviour of memory alloc/free.
This func produces seg fault error [old plain NULL pointer]:
pjsua_msg_data is a C struct
static func makePj(fromHeaders headers: [SipHeader],
pool: inout UnsafeMutablePointer<pj_pool_t>) -> pjsua_msg_data {
var msgData = pjsua_msg_data()
pjsua_msg_data_init(&msgData)
pj_list_init(&msgData.hdr_list)
for header in headers {
let pjHeader = header.toPj(pool: &pool)
pj_list_push_back(&msgData.hdr_list, pjHeader)
}
return msgData
}
This implementation works (difference is that msgData as inout param)
static func makePj(fromHeaders headers: [SipHeader],
msgData: inout pjsua_msg_data,
pool: inout UnsafeMutablePointer<pj_pool_t>) {
pjsua_msg_data_init(&msgData)
pj_list_init(&msgData.hdr_list)
for header in headers {
let pjHeader = header.toPj(pool: &pool)
pj_list_push_back(&msgData.hdr_list, pjHeader)
}
}
Usage
var msgData = pjsua_msg_data()
var pool = try API.shared.createMemPool("pool", block: 4096, increment: 1024)
defer { try? API.shared.releaseMemPool(pool) }
if !headers.isEmpty {
// - usage of working implementations
//MessageData.makePj(fromHeaders: headers,
// msgData: &msgData,
// pool: &pool)
// - seg fault implementation usage
msgData = MessageData.makePj(fromHeaders: headers,
pool: &pool)
}
try callPJSUA {
pjsua_call_make_call(accountId,
&uriStr,
&callSetting,
nil,
&msgData,
&callId)
}
Little bit about framework:
it's a just Swift wrapper under C lib.
This framework then linked to the iOS app
Question:
I don't understand why inout param works but returning value doesn't.
Can I change this swift compiler behaviour? Build settings or smth else ?
Exception:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Codes: 0x0000000000000001, 0x0000000000000000
VM Region Info: 0 is not in any region. Bytes before following region: 4365074432
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
--->
__TEXT 1042dc000-1056ec000 [ 20.1M] r-x/r-x SM=COW ...app/CallScape
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: SIGNAL 11 Segmentation fault: 11
Terminating Process: exc handler [2095]
Thread 11 name: Dispatch queue: working.queue
Thread 11 Crashed:
0 SDK 0x10d3f3f28 pjsip_hdr_clone + 36
1 SDK 0x10d6d7454 pjsua_msg_data_clone + 280
2 SDK 0x10d6d7454 pjsua_msg_data_clone + 280
3 SDK 0x10d6cc4c8 pjsua_call_make_call + 1276
4 SDK 0x10d38a710 specialized CallAPI.make(_:destinationURI:setting:headers:) + 1268
5 SDK 0x10d389de8 protocol witness for CallAPI.make(_:destinationURI:setting:headers:) in conformance API + 12
6 SDK 0x10d39c8a8 Call.make(to:setting:headers:) + 152

Related

Crash on one specific Unity scene in iOS build - TexturesMetal::AddCreatedTexture

I am having a crash only on one specific scene in my AR Foundation Unity build with the following error.
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Subtype: KERN_INVALID_ADDRESS at 0x0000000000000020
VM Region Info: 0x20 is not in any region. Bytes before following region: 4362387424
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
UNUSED SPACE AT START
__TEXT 10404c000-104050000 [ 16K] r-x/r-x SM=COW ...lycoroTestApp
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [5380]
Triggered by Thread: 28
Thread 28 name:
Thread 28 Crashed:
0 libobjc.A.dylib 0x0000000195ac5ac0 objc_retain + 16 (objc-object.h:636)
1 UnityFramework 0x00000001066d5320 TexturesMetal::AddCreatedTexture(TextureID, id, bool) + 32 (TexturesMetal.mm:481)
2 UnityFramework 0x0000000106634828 GfxDeviceWorker::RunCommand(ThreadedStreamBuffer&) + 21972 (GfxDeviceWorker.cpp:0)
3 UnityFramework 0x00000001066aa2ec GfxDeviceWorkerAutoreleasePoolProxy + 68 (GfxDeviceMetal.mm:5242)
4 UnityFramework 0x0000000106636bd0 GfxDeviceWorker::RunExt(ThreadedStreamBuffer&) + 92 (GfxDeviceWorker.cpp:389)
5 UnityFramework 0x0000000106636b68 GfxDeviceWorker::Run() + 156 (GfxDeviceWorker.cpp:373)
6 UnityFramework 0x000000010662ef70 GfxDeviceWorker::RunGfxDeviceWorker(void*) + 12 (GfxDeviceWorker.cpp:352)
7 UnityFramework 0x00000001062289f8 Thread::RunThreadWrapper(void*) + 496 (Thread.cpp:81)
8 libsystem_pthread.dylib 0x00000001c9777c74 _pthread_start + 288 (pthread.c:887)
9 libsystem_pthread.dylib 0x00000001c977c878 thread_start + 8
At first I thought it was because I was missing the Environmental Probe manager in that scene (no). Then I thought perhaps it was because I was using a specific shader that didn't use a _MainTex. But I use that shader no problem in other working scenes.
And then I built the scene with only a simple primitive and my UI and still received this error. After that crash the scene did open successfully, but obviously the problem is still there. The UI is the exact same as the other working scenes.
I can't find out much about this specific error: TexturesMetal::AddCreatedTexture - only that there may be this bug with GLES3 and PVRTC textures - but they aren't present in the most recent build.
https://issuetracker.unity3d.com/issues/ios-crash-in-uploadtexture-at-texturesmeta-dot-mm-or-drawbufferranges-at-gfxdevicegles-dot-cpp-using-atlas-with-pvrtc-compress
The scene works perfectly in Android - it only crashes in iOS.
Any ideas? Full report below.
I ran a Product>Analysis in Xcode and it gave me this warning:
/Users/xcodeclub/Downloads/Eliot Silver/Classes/UI/UnityView.mm:200:5: nil returned from a method that is expected to return a non-null value
For this bit of Code in UnityView.mm:
static Class UnityRenderingView_LayerClassMTL(id self_, SEL _cmd)
{
return NSClassFromString(#"CAMetalLayer");
}
static Class UnityRenderingView_LayerClassNULL(id self_, SEL _cmd)
{
return NSClassFromString(#"CALayer");
}
#implementation UnityRenderingView
(Class)layerClass
{
return nil;
}
(void)InitializeForAPI:(UnityRenderingAPI)api
{
IMP layerClassImpl = api == apiMetal ? (IMP)UnityRenderingView_LayerClassMTL : (IMP)UnityRenderingView_LayerClassNULL;
class_replaceMethod(object_getClass([UnityRenderingView class]), #Selector(layerClass), layerClassImpl, UIView_LayerClass_Enc);
}
#End

iOS handling crash EXC_CRASH (SIGSEGV) with source code

I have received the following error from one of our clients with an exact place where the crash happen.
Error report:
Symbolize build number: 89778
2Incident Identifier: 8B5F5ADE-295C-4596-8B34-37280A38511A
3Hardware Model: iPhone13,2
4Process: Glip [73149]
5Path: /private/var/containers/Bundle/Application/D2CA9563-630A-470F-BC84-A9E6546D5B71/SomeApp.app
6Identifier: SomeApp
7Version: 89778 (21.2.35)
8AppStoreTools: 12E506
9AppVariant: 1:iPhone13,2:14
10Code Type: ARM-64 (Native)
11Role: unknown
12Parent Process: launchd [1]
13Coalition: com.glip.mobile [7033]
14
15
16Date/Time: 2021-07-06 18:29:00.1537 -0700
17Launch Time: 2021-07-06 18:28:56.2301 -0700
18OS Version: iPhone OS 14.6 (18F72)
19Release Type: User
20Baseband Version: 1.71.01
21Report Version: 104
22
23Exception Type: EXC_CRASH (SIGSEGV)
24Exception Codes: 0x0000000000000000, 0x0000000000000000
25Exception Note: EXC_CORPSE_NOTIFY
26Termination Signal: Segmentation fault: 11
27Termination Reason: Namespace SIGNAL, Code 0xb
28Terminating Process: Glip [73149]
29Triggered by Thread: 0
30
31Thread 0 name:
32Thread 0 Crashed:
330 CoreFoundation 0x000000018ed62ea4 __CFStringChangeSizeMultiple + 148 (CFString.c:1032)
341 CoreFoundation 0x000000018ed5d874 __CFStringAppendBytes + 708 (CFString.c:1149)
352 CoreFoundation 0x000000018ed4d800 __CFStringAppendFormatCore + 9220 (CFString.c:8375)
363 CoreFoundation 0x000000018ed619fc _CFStringAppendFormatAndArgumentsAux2 + 68 (CFString.c:7556)
374 CoreFoundation 0x000000018ec8af58 -[__NSCFString appendFormat:] + 120 (CFObject.m:462)
385 Pendo 0x0000000114173794 -[NSString(IIOStringUtils) pnd_toHexString:length:] + 116
396 Pendo 0x00000001141733cc -[NSString(IIOStringUtils) pnd_SHA256] + 112
The code responsible for the crash is the following:
//my stack trace is get called from this method (don't think its matter in that case)
- (nonnull NSString *)pnd_SHA1 {
unsigned int outputLength = CC_SHA1_DIGEST_LENGTH;
unsigned char output[outputLength];
CC_SHA1(self.UTF8String, [self pnd_UTF8Length], output);
return [NSString pnd_toHexString:output length:outputLength];
}
- (NSString *)pnd_SHA256 {
unsigned int outputLength = CC_SHA256_DIGEST_LENGTH;
unsigned char output[outputLength];
CC_SHA256(self.UTF8String, [self pnd_UTF8Length], output);
return [self pnd_toHexString:output length:outputLength];
}
- (NSString*)pnd_toHexString:(unsigned char*) data length:(unsigned int)length {
NSMutableString* hash = [NSMutableString stringWithCapacity:length * 2];
for (unsigned int i = 0; i < length; i++) {
[hash appendFormat:#"%02x", data[i]];
data[i] = 0;
}
return [hash copy];
}
From quick look I immediately blamed the following line:
[hash appendFormat:#"%02x", data[i]];
So I reproduced the crash by:[hash appendFormat:nil];
And the local report I got: (which is similar BUT not exact)
Process: MyApp [45754]
Path: /Users/USER/Library/Developer/CoreSimulator/Devices/EAEA42C2-3B8F-48EF-B1D3-BEA68FE046A0/data/Containers/Bundle/Application/DE83DA67-70A9-4ECF-92B9-526137C6E4B3/MyApp
Identifier: PendoDevelopmentApp
Version: 1.0 (1)
Code Type: X86-64 (Native)
Parent Process: launchd_sim [24742]
Responsible: SimulatorTrampoline [957]
User ID: 502
Date/Time: 2021-07-21 14:42:56.804 +0300
OS Version: Mac OS X 10.15.7 (19H1217)
Report Version: 12
Bridge OS Version: 5.4 (18P4663)
Anonymous UUID: 74B25560-EFCE-769F-F0B4-E4DD4C6B09A4
Sleep/Wake UUID: F52FC80E-F86E-4813-B352-D0A7B5FF87B2
Time Awake Since Boot: 120000 seconds
Time Since Wake: 6700 seconds
System Integrity Protection: enabled
Crashed Thread: 0 Dispatch queue: com.apple.main-thread
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Signal: Segmentation fault: 11
Termination Reason: Namespace SIGNAL, Code 0xb
Terminating Process: exc handler [45754]
VM Regions Near 0:
-->
__TEXT 000000010f038000-000000010f0bc000 [ 528K] r-x/r-x SM=COW /Users/USER/Library/Developer/CoreSimulator/Devices/EAEA42C2-3B8F-48EF-B1D3-BEA68FE046A0/data/Containers/Bundle/Application/DE83DA67-70A9-4ECF-92B9-526137C6E4B3/MyApp
Application Specific Information:
CoreSimulator 732.18.6 - Device: iPhone 11 Pro Max (EAEA42C2-3B8F-48EF-B1D3-BEA68FE046A0) - Runtime: iOS 13.0 (17A577) - DeviceType: iPhone 11 Pro Max
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 com.apple.CoreFoundation 0x00007fff23b1df08 __CFStringAppendFormatCore + 536
1 com.apple.CoreFoundation 0x00007fff23b395cc _CFStringAppendFormatAndArgumentsAux2 + 60
2 com.apple.CoreFoundation 0x00007fff23accba8 -[__NSCFString appendFormat:] + 184
3 io.pendo.PendoSDKFramework 0x000000010f35061d -[NSString(IIOStringUtils) pnd_toHexString:length:] + 109 (NSString+IIOStringUtils.m:111)
4 io.pendo.PendoSDKFramework 0x000000010f35010f -[NSString(IIOStringUtils) pnd_SHA256] + 175 (NSString+IIOStringUtils.m:57)
and fixed the code as follows:
+ (NSString*)pnd_toHexString:(unsigned char*)data length:(unsigned int)length {
if (data == nil || data == NULL) {
IIOCriticalLog(#"hash diget is nil");
return nil;
}
NSMutableString* hash = [NSMutableString stringWithCapacity:length * 2];
for (unsigned int i = 0; i < length; i++) {
NSString *str = [NSString stringWithFormat:#"%02x",data[i]];
if (str == nil) {
IIOCriticalLog(#"hash diget was corrupted");
return nil;
}
[hash appendString:str];
data[i] = 0;
}
return [hash copy];
}
The problem that I am still not 100% sure how it could happen for only this specific client as for how the appendString could get a nil.
Maybe somebody had a similar issue.

Why "dict[String(aUint16)] = Int(Date().timeIntervalSince1970 * 1000)" failed in some cases? [duplicate]

This question already has an answer here:
Timestamp function that has been working reliably just caused EXC_BAD_INSTRUCTION
(1 answer)
Closed 5 years ago.
My code, which use SimplePing:
func simplePing(_ pinger: SimplePing, didSendPacket packet: Data, sequenceNumber: UInt16) {
begin[String(sequenceNumber)] = Int(Date().timeIntervalSince1970 * 1000)//AppDelegate.swift:185
print("Send: \(Common.startCount)")
}
It works perfectly in my simulator and iPhone, but after made it available on AppStore, I received about 20 crash logs with some error like that:
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x00000000e7ffdefe
Triggered by Thread: 1
...
Thread 1 name:
Thread 1 Crashed:
0 ME 0x0011e5cc specialized AppDelegate.simplePing(SimplePing, didSendPacket : Data, sequenceNumber : UInt16) -> () + 652 (AppDelegate.swift:185)
1 ME 0x00116990 #objc AppDelegate.simplePing(SimplePing, didSendPacket : Data, sequenceNumber : UInt16) -> () + 68
2 ME 0x00116818 #objc AppDelegate.simplePing(SimplePing, didSendPacket : Data, sequenceNumber : UInt16) -> () + 40
3 ME 0x000f3348 -[SimplePing sendPingWithData:] + 640 (SimplePing.m:297)
...
I can't reproduce that crash, so I have to analysis that line of the code:
begin[String(sequenceNumber)]
begin initialized with begin = [String: Int](), so its type is [String : Int], and sequenceNumber's type is UInt16. So I think begin[String(sequenceNumber)] doesn't have any potential bug.
Int(Date().timeIntervalSince1970 * 1000)
And Int(Date().timeIntervalSince1970 * 1000) is just something like Int(aDouble * 1000), it seems correct in any situation.
So I get really confused with that crash log, could anyone please give me some hints?
From the docs for Int:
On 32-bit platforms, Int is the same size as Int32, and on 64-bit platforms, Int is the same size as Int64.
A signed 32-bit integer has a maximum value of 2,147,483,647.
At the moment, Int(Date().timeIntervalSince1970 * 1000) returns a value of 1,495,855,170,970.
That is significantly larger than what will fit in a 32-bit integer.
The crash is being caused by the overflow you are attempting when casting the Double to an Int when run on a 32-bit iOS device.
I would suggest an explicit use of Int64 instead of Int:
begin[String(sequenceNumber)] = Int64(Date().timeIntervalSince1970 * 1000)

App crashing when launching from AppStore or TestFlight but working fine elseways

My application update has been rejected. Into the rejection message, they wrote "Application crashes at launch". I then tried my application but couldn't make it crash. So I used TestFlight and noticed that when I was launched my app from TestFlight or AppStore, it was crashing at launch. But if I launch my app normally, it does work without any crashes. The thing is this bug occurred since iOS 10 update. Now my application on store also crashes when launched from AppStore while it was working fine 2 weeks go.
Apple sent me a crash log:
Incident Identifier: 001969F1-F275-4AC3-AFE1-E0426957B702
CrashReporter Key: 5ad9695e945a7d5eb5d61fd18d1c3989ccd155b4
Hardware Model: xxx
Process: MyApp [400]
Path: /private/var/containers/Bundle/Application/644423A4-EFE7-41B1-99D9-47B46338A6E2/MyApp.app/MyApp
Identifier: com.MyApp.com
Version: 20160527 (2.7.9)
Code Type: ARM-64 (Native)
Role: Foreground
Parent Process: launchd [1]
Coalition: com.MyApp.com [451]
Date/Time: 2016-09-22 11:19:22.6893 -0700
Launch Time: 2016-09-22 11:19:22.4164 -0700
OS Version: iPhone OS 10.0.1 (14A403)
Report Version: 104
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0x0000000000000001, 0x000000010008a864
Termination Signal: Trace/BPT trap: 5
Termination Reason: Namespace SIGNAL, Code 0x5
Terminating Process: exc handler [0]
Triggered by Thread: 0
Filtered syslog:
None found
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 MyApp 0x1000efd3c specialized AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift:218)
1 MyApp 0x1000ed310 #objc AppDelegate.application(UIApplication, didFinishLaunchingWithOptions : [NSObject : AnyObject]?) -> Bool (AppDelegate.swift)
2 UIKit 0x19888c42c <redacted> + 400
3 UIKit 0x198a9cb70 <redacted> + 3524
4 UIKit 0x198aa28e0 <redacted> + 1656
5 UIKit 0x198ab7080 <redacted> + 48
6 UIKit 0x198a9f8c4 <redacted> + 168
7 FrontBoardServices 0x1945798bc <redacted> + 36
8 FrontBoardServices 0x194579728 <redacted> + 176
9 FrontBoardServices 0x194579ad0 <redacted> + 56
10 CoreFoundation 0x192986278 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 24
11 CoreFoundation 0x192985bc0 __CFRunLoopDoSources0 + 524
12 CoreFoundation 0x1929837c0 __CFRunLoopRun + 804
13 CoreFoundation 0x1928b2048 CFRunLoopRunSpecific + 444
14 UIKit 0x1988855dc <redacted> + 608
15 UIKit 0x198880360 UIApplicationMain + 208
16 MyApp 0x1000ee818 main (AppDelegate.swift:58)
17 libdispatch.dylib 0x1918945b8 (Missing)
There is 4 others threads but this one is the one crashing so I did not copy the rest. I did some research and even though I did notice my crash log wasn't fully translated (for some strange reason since I have all dsyms but whatever), I did manage to understand that I was crashing on line 217 (tell me if I'm wrong). I know that SIGTRAP are most of time NSExceptions being thrown. The line itself is:
let api = MyAppAPI.instance
The instance is a singleton. My guess is that something into the instance creation is failing. Here is the code:
static var instance: MyAppAPI = {
return Singleton.instance
}()
class MyAppAPI: Manager {
struct Singleton {
static var configuration: NSURLSessionConfiguration = {
var configuration = NSURLSessionConfiguration.defaultSessionConfiguration()
let version = NSBundle.mainBundle().objectForInfoDictionaryKey("CFBundleShortVersionString") as? String ?? ""
configuration.HTTPAdditionalHeaders = [
"Accept": "application/vnd.MyApp.api+json, application/json;q=0.9",
"User-Agent": "MyApp iOS/\(version)",
"X-API-Version": "1.0.1"
]
return configuration
}()
static var instance = MyAppAPI(configuration: configuration)
static var baseURL : NSURL! = nil
}
I'm so desperate about this error, I did try a few things that did not work out. Am I looking into the right place ? Is there anyone with a solution ? Any kind of help would be greatly appreciated. I'm willing to gift anyone that can find me the solution or help me find the solution !
I found the solution of my problem.
As expected it was coming from func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
Inside the function I had let userInfo = launchOpts[UIApplicationLaunchOptionsRemoteNotificationKey] as! NSDictionary.
I changed it to let userInfo = launchOpts[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary and then checked if userInfo != nil to make all the code running userInfointo the bracket.
If it helps anyone or if anyone is struggling with this issue, check all yours ! and swap these to ? if needed (on didFinishLaunchingWithOptions) since launching from TestFlight/AppStore seems to have different options than from installed application (just a guess, not pro enough to claim it).

Segmentation Fault: 11 - Xcode 6.3

Can't archive
My app runs fine (Xcode 6.3.2, swift based) on Simulator and on multiple devices. But when I try to archive it I get the error Command failed due to signal: Segmentation fault: 11.
Others face same problem
Segmentation Fault 11 when running Swift app
"Command failed due to signal: Segmentation fault: 11" - What is the issue?
Command failed due to signal: Segmentation fault: 11
Root cause?
But it seems that each have different reasons for getting the error.. I am unable to comprehend the error message I am getting. Posted below, any hints or tips would be greatly appreciated!
Error log
0 swift 0x0000000108e5d2b8 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x0000000108e5d794 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff8897bf1a _sigtramp + 26
3 libsystem_platform.dylib 0x00007fff574b7b28 _sigtramp + 3467885608
4 swift 0x0000000108a053f2 swift::serialization::Serializer::writeCrossReference(swift::Decl const*) + 578
5 swift 0x0000000108a0e275 swift::serialization::Serializer::writeAllDeclsAndTypes() + 2181
6 swift 0x0000000108a0f2f8 swift::serialization::Serializer::writeAST(llvm::PointerUnion<swift::Module*, swift::SourceFile*>) + 2600
7 swift 0x0000000108a11960 swift::serialization::Serializer::writeToStream(llvm::raw_ostream&, llvm::PointerUnion<swift::Module*, swift::SourceFile*>, swift::SILModule const*, swift::SerializationOptions const&) + 144
8 swift 0x0000000108a12521 swift::serialize(llvm::PointerUnion<swift::Module*, swift::SourceFile*>, swift::SerializationOptions const&, swift::SILModule const*) + 321
9 swift 0x0000000108746c1a frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 5514
10 swift 0x00000001087454e6 main + 1814
11 libdyld.dylib 0x00007fff8db235c9 start + 1
12 libdyld.dylib 0x0000000000000080 start + 1917700792
Solved it. Problem was two things:
1) Converting to Double
2) Handling an empty array
Converting to Double
Changed from var lat: Double? = d["lat"].doubleValue to var lat: Double? = Double(d["lat"].doubleValue)
Handling an empty array
Changed from
let brands = d["brands_unfiltered"].arrayValue {
if brands == [] {
// Do nothing (empty)
}
else{
// Do stuff
}
To
if let brands = d["brands_unfiltered"].arrayValue as Array! {
// Do stuff
}
To find the root cause I deactivated larges part of the code until I found what got the archiving not to function. Thereafter the solution was pretty straight forward. Hope this helps someone else struggling with the same error.
I found the code that cause my "Archive" action to fail with this error "Command failed due to signal: Segmentation fault: 11"
When I use the indexPath in the cellForRowAtIndexPath function, I need to put an exclamation mark (i.e indexPath! instead of indexPath). However, I still puzzled by why there is such error if I omit the exclamation mark. Does anyone know the reason?
override func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!, object: PFObject!) -> PFTableViewCell! {
// code to get cell, etc
let thumbnailImage = self.userPhotos?.getFromCacheOrDownload(username,
circle: team.circle(), delegate: self, indexPath: indexPath!)
cell.userPhotoImageView.image = thumbnailImage
return cell
}

Resources