3

I posted this question on the Apple IOS Developers' Forum, with a notable lack of response. I'm hoping the StackOverflow wizards can help...

I'm developing an iOS 8 app using Swift. In Xcode beta 5 the code below code worked, but gives me a linker error in beta 6 and beta 7:

var sqlStr = "SELECT count(*) as count FROM nouns WHERE bucket = ?;"
var rs = db.executeQuery(sqlStr, withArgumentsInArray: [0] as NSArray)

The linker error is:

Undefined symbols for architecture x86_64:
  __TFSs26_forceBridgeFromObjectiveCU__FTPSs9AnyObject_MQ__Q_", referenced from:
  __TFC8les_Mots13WordGenerator9getBucketfS0_FT_Si in WordGenerator.o

(getBucket is a method in the UIViewController WordGenerator. If I reduce the method to just these two lines, I get the same error, and if I comment these two lines out, the error goes away, so I know the problem is here.)

The db.executeQuery() is an FMDB method with this signature:

 - (BOOL)executeUpdate:(NSString*)sql withArgumentsInArray:(NSArray *)arguments;

If I change the code to this, it works in all betas:

var sqlStr = "SELECT count(*) as count FROM nouns WHERE bucket = '\(whereClause)';"
var rs = db.executeQuery(sqlStr, withArgumentsInArray: nil)

From the linker error and my trials-and-efforts to debug this, it appears that the cast of [0], which is of type AnyObject to an NSArray, which is required, is failing. I'm using this example, but I'm seeing similar problems in other areas of the app, all where an AnyObject has to be cast to an NSArray or NSDictionary.

The original code above works just fine in Xcode beta 5, but not in subsequent betas. Clearly I'm not understanding something about the AnyObject to NSArray cast, but I'm darned if I know what, and it appears that betas 5 and 6 enforce something not previously enforced. I've tried every kind of explicit cast I can think of, with no success.

Any help will be GREATLY appreciated.

johnz
  • 489
  • 2
  • 17
  • I'm having the same problem and tried all of the proposed solutions for beta 6: http://stackoverflow.com/a/25376271/887210 to no avail. Hopefully someone will be able to shed some insight on this issue! – Kyle Rosenbluth Sep 03 '14 at 01:47
  • You may have to provide some more context to get assistance with this issue. I attempted to duplicate the issue with a simple test class that has a method with that signature and it compiled without any difficulties using Xcode 6 beta 7. –  Sep 03 '14 at 12:38
  • I have deleted derived data and cleaned the build and intermediate folders more times than I can count, with no success. I don't know what additional context I can provide. I also wrote a test class with the above statements, and it results in the same linker error. I appreciate your response - it tells me that someone is making it work! – johnz Sep 03 '14 at 15:05

1 Answers1

1

I changed the Build location and the code now compiles, links and runs. Previously the Build location was Custom/relative to workspace; I changed it to Unique.

I have no idea why this would change things, as I had deleted derived data and cleaned the build folder many times. But...it worked, so if anyone is having the same problems, give this a try.

johnz
  • 489
  • 2
  • 17
  • Interesting. I figured it had something to do with the binaries. Did you try holding down the option key when doing a clean build? The shortcut is option-shift-command-k, if you hold down the option key the menu item is Product->Clean Build Folder... –  Sep 03 '14 at 15:37
  • I never could do that via the menu - the Clean Build Folder menu item was always grayed out. I manually deleted everything I could find, but maybe I missed something. Anyway, thanks for your interest and help. – johnz Sep 03 '14 at 17:10