EXC_BAD_ACCESS using Swift generics

After updating to Xcode 7.3, I'm seeing an odd crash on an iPhone 4 running iOS 7.1.2. I've narrowed it down to the following minimal example (using the Xcode 'Single View Application' template as a testbed):


import UIKit

class Foo<T> {
    let value = 0
}

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
    var window: UIWindow?

    let foo = Foo<Int>() // EXC_BAD_ACCESS, code=2
}

class ViewController: UIViewController {}


The app crashes with EXC_BAD_ACCESS on the line indicated.


Does anyone see anything wrong with this code? Or might this be a Swift bug?

Accepted Reply

Definitely file a bug. If you need it, here's the link: Apple Bug Reporter

Replies

Definitely file a bug. If you need it, here's the link: Apple Bug Reporter

Thanks, bug filed. Just wanted to make sure I wasn't overlooking something obvious.

Well, Swift is "never" supposed to hard crash like that, so that's kind of a clue that something's wrong. Of course, since Swift is still in its infancy, there are still a lot of kinks that need to be worked out (especially in the area of interacting with Objective-C features like KVC and KVO.) But in your case, there's nothing complex going on, so I think it's just a random error. Oh, and unless you marked that bug report as high priority, don't expect to hear back from Apple about it for at least a month or longer.


Does it happen only on iOS 7.1.2 or any 7.x, for that matter? You might want to consider bumping up your deployment target to iOS 8 to keep it from happening in the future.

"Well, Swift is "never" supposed to hard crash like that, so that's kind of a clue that something's wrong."


Oh, I know that. I just like to ask before filing bugs even if it seems absolutely certain it isn't user error, just to make sure I haven't missed anything.


"Oh, and unless you marked that bug report as high priority, don't expect to hear back from Apple about it for at least a month or longer."


I'm not expecting anything. I don't know if it happens on any iOS version other than 7.1.2, but I probably won't be targeting 7 anyway, so it shouldn't be an issue.


Thanks for your feedback.

Yeah, I agree with you that iOS 7 is kind of too far back to be worth significant effort. Good luck! 🙂

I'm getting this bug and it's a major pain and I wish Apple would please address it. iOS 7 support is absolutely critical to my business and that of I suspect many others.


I wish Apple would stop assuming that nobody cares about supporting older phones. It's a law in the IT world - we simply NEED to support older hardware. Apple seems to say "ohh just by an iPhone 6S" but it's simply not practical especially for developers like me that are working in a more "internal use" scenario where we don't have money growing on our cubicle desk zen garden trees.


In my case, I built a pilot app in HTML5 back around 2013 and when it worked well. So we purchased around 50 iPhone 3GS models for use of the app to be re-written "fore real" using Swift 1.0 Beta for which 3GS support was advertised by Apple.


Then Swift 1.0 RC 5 came out and OHH SORRY --- no 3GS support.


OK, that's a beta product and arguably my fault but try explaining that to my clients, who then had to sell 50 iPhone 3GS models on eBay and buy in exchange 50 more iPhone 4 models, which I assured them would work fine.


Well it never really worked well, with Xcode continuing to be buggy as crap with iOS 7 even from the start, but I got by and the app is now stable and I'm supporting around 200 iPhone 4 models and another 200 iPhone 5 and 6 users.


Then XCode 7.2 came out and OHH SORRY --- no more iOS 7 simulator and no plans by Apple to make one.


So from that point, I have to use a physical iPhone 4 by USB cable to do any debugging.


Now I upgrade to XCode 7.3 and OHH SORRY --- generics don't work anymore (this bug - which is now preventing my release) and nobody seems to care.


The iPhone 4 running iOS 7 is a perfectly fine phone for our purposes - our users only need to make calls, use SMS, use Google Maps (in a very simple way) and run the app I built and that's it. It's an economical solution with models on eBay at around USD $100.

For us, a newer phone like the 5C is a complete waste of money - the speed is already fine with the 4. If we have to upgrade all 200 of our existing phones, that's an expense of something like $50,000 which for the small business I support will be incredibly painful if not render the whole project uneconomical.

Anyone else in this situation, please reply to this thread and let Apple know we're there.

Or if I'm really the only one in the whole world that cares about iOS7 then I guess tell me that and I'll go to my clients and tell them "sorry Apple wants you to all buy new phones"... but be careful since I might just decide Android is the better platform at some point and advise them of that instead. 😟

Sorry to hear this is causing you problems (fortunately, for me it was mostly just a matter of curiosity). Apologies if you've already done this, but if you haven't already filed a bug report, you might go ahead and do so, just so they have more information to work with.