Symbol not found when building App including MapKit - swift

When using the new Xcode 11 beta. I'm getting the following crash while running my app that uses MapKit. Xcode 10 works fine. Also creating a new project and adding a Map with Mapkit works fine.
A simple web search doesn't yield anything.
Any clues where to look to solve this problem?
Xcode 11 beta 1:
dyld: Symbol not found: _NavigationConfig_MapLocalizeLabels
Referenced from: /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/MapKit.framework/MapKit
Expected in: /Users/Teameh/Library/Developer/Xcode/DerivedData/MyApp-dejdjcwzzweszweqllhjxqbarbsp/Build/Products/Debug-iphonesimulator/Navigation.framework/Navigation
in /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/MapKit.framework/MapKit
Xcode 11 beta 3:
dyld: Symbol not found: _NavigationConfig_MapLocalizeLabels
Referenced from: /System/Library/Frameworks/MapKit.framework/MapKit
Expected in: /Users/Teameh/Library/Developer/Xcode/DerivedData/MyApp-dejdjcwzzweszweqllhjxqbarbsp/Build/Products/Debug-iphonesimulator/Navigation.framework/Navigation
in /System/Library/Frameworks/MapKit.framework/MapKit
I've split my code up in multiple frameworks, one is called Navigation.framework, could that be the issue? This was not a problem with Xcode 10.
Update 1
As suggested by in the comments, this is not fixed by adding MapKit to the embedded frameworks. I thought system frameworks should not be added to the embedded frameworks, and this shows that that does not work.
Update 2
I've removed MapKit and all the code referencing it but still I get the same crash.

As you stated you have your own Navigation Framework.
Xcode is looking for _NavigationConfig_MapLocalizeLabels in your own Navigation Framework instead of Mapkit's Navigation framework.
Renaming your Navigation framework to something else should do the trick.

Related

Xcode Ignoring import

I have just installed Xcode 11 and when I try to create new fresh project with the SwiftUI check mark selected it returns an error.
Not able to build and run successfully.
File 'ContentView.swift' is part of module 'SwiftUI'; ignoring import
ContentView.swift
Use of undeclared type 'View'
SceneDelegate.swift
Use of unresolved identifier 'UIHostingController'
I have tried removing all derived data and also set command-line tools to 11
Your project is named SwiftUI - please try using a different name.
Detailed Answer
Each project you create has a module with the same name as the project. So there are two SwifUI modules here:
The actual SwiftUI
The project itself
Xcode always takes the nearest definition as the default. So your SwiftUI is closer than the system's SwiftUI. But you are in the project's module already! So Xcode ignores the import.
A very common mistake is to name the project same as one of the using frameworks! (e.g. CoreData, SwiftUI, SceneKit, Metal)
Solution
As Matteo mentioned in his answer, Don't name your project same with another module. Change it to anything else.
Note that It could appear as an error too. For example, if you name your project CoreData and using SwiftUI, the error appears as Circular dependency error:
Circular dependency between modules 'CoreData' and 'SwiftUI'
Because Xcode gets confused about modules and can not detect what the real issue is.
How can we access our module's classes instead of the system's module?
Imagine you have a class named Section in a custom framework called MyProject and you imported it alongside the SwiftUI.
import SwiftUI
import MyProject
Section // <- This could be either SwiftUI's section or MyProject's Section
To make it clear for the compiler (and anyone else), you should call the module before the class name:
SwiftUI.Section // <- This returns the SwiftUI's Section
MyProject.Section // <- This returns the MyProject's Section
Try with different project name. With SwiftUI, it will always show compilation error. Just change the name and enjoy coding with SwiftUI

Why am I able to use MessageUI without a framework reference?

In my Swift 2 project, targeting iOS 9.2 and above, in Xcode 8.2.1, I have code that shows the mail-compose screen like so:
if MFMailComposeViewController.canSendMail() {
let composeMailVC = MFMailComposeViewController()
composeMailVC.mailComposeDelegate = self
composeMailVC.setSubject("Test")
// etc
}
Originally I had a reference to the MessageUI.framework in my project properties, but after removing the framework reference and cleaning the project, it still builds fine and when I run the code on my device the mail compose window still appears and seems fully functional.
I cannot find any explicit references to MessageUI.framework in the raw text of my .xcodeproj file, nor is there anything in my Objective-C bridging header.
I know that Swift does make some implicit framework references, but I couldn't find anything that suggests MessageUI.framework is one of them.
Curiously when I jump to the definition of MFMailComposeViewController XCode shows it in the MessageUI module.
The compiler automatically added the frame work in given its previous direction - IE. Import.

Symbol not found: NSHTTPCookieStorage

I'm new to IOS programming and now experimenting with Swift. Everything was working fine until I tried to use facebook SDK. I added a new bridging header to import facebooksdk, and in my view controller I have
var fbl: FBLoginView = FBLoginView()
But this line gives me an error when deploying the app to my phone, and it crashes with app launch. The error code I get is:
dyld: Symbol not found: _OBJC_CLASS_$_NSHTTPCookieStorage
When using the simulator tho, everything works fine. What would be the reason for this error?
Did you import foundation?
import Foundation

GridView in iPhone

I am working on an iPhone application in which I have to design a GridView, I have searched on google + stackoverflow and found that one possible solution is AQGridView, I have tried it but all of its examples are not working in XCode 4.1.
The error I am facing is: Expected ':', ",", ";", "}" or 'attribute' before '_dataSource'.
The line causing this error is id<AQGridViewDataSource> __unsafe_unretained _dataSource; (line no 100 in AQGridView.m).
What I am trying to achieve is to display buttons in 2x4 table.
Any Help will be appreciated.
Thanks
Edit
Ok, so I have downloaded Xcode 4.2 as some guys suggested in comments, now the previous errors are gone but I am having a new on __bridge Undeclared (first use in this function), the line causing this error is line no 961 in AQGridView.m (Source Code)
Thanks
First create a gridview objective class.write own delgate and datasource methods as tableview in it.call it in the viewcontrler class.
I think, on XCode 4.2 this is not an issue.
XCode 4.1 does not know __unsafe_unretained.
So just define it in some global project header:
#define __unsafe_unretained
and try to compile again.

Calling method on category included from iPhone static library causes NSInvalidArgumentException

I have created a static library to house some of my code like categories.
I have a category for UIViews in "UIView-Extensions.h" named Extensions.
In this category I have a method called:
- (void)fadeOutWithDelay:(CGFloat)delay duration:(CGFloat)duration;
Calling this method works fine on the simulator on Debug configuration.
However, if try to run the app on the device I get a NSInvalidArgumentException:
[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[UIView fadeOutWithDelay:duration:]: unrecognized selector sent to instance 0x1912b0
It seems for some reason UIView-Extensions.h is not being included in the device builds.
What I have checked/tried
I did try to include another category for NSString, and had the same issue.
Other files, like whole classes and functions work fine. It is an issue that only happens with categories.
I did a clean all targets, which did not fix the problem.
I checked the static library project, the categories are included in the target's "copy headers" and "compile sources" groups.
The static library is included in the main projects "link binary with library" group.
Another project I have added the static library to works just fine.
I deleted and re-added the static library with no luck
-ObjC linker flag is set
Any ideas?
nm output
libFJSCodeDebug.a(UIView-Extensions.o):
000004d4 t -[UIView(Extensions) changeColor:withDelay:duration:]
00000000 t -[UIView(Extensions) fadeInWithDelay:duration:]
000000dc t -[UIView(Extensions) fadeOutWithDelay:duration:]
00000abc t -[UIView(Extensions) firstResponder]
000006b0 t -[UIView(Extensions) hasSubviewOfClass:]
00000870 t -[UIView(Extensions) hasSubviewOfClass:thatContainsPoint:]
000005cc t -[UIView(Extensions) rotate:]
000002d8 t -[UIView(Extensions) shrinkToSize:withDelay:duration:]
000001b8 t -[UIView(Extensions) translateToFrame:delay:duration:]
U _CGAffineTransformRotate
000004a8 t _CGPointMake
U _CGRectContainsPoint
U _NSLog
U _OBJC_CLASS_$_UIColor
U _OBJC_CLASS_$_UIView
U ___CFConstantStringClassReference
U ___addsf3vfp
U ___divdf3vfp
U ___divsf3vfp
U ___extendsfdf2vfp
U ___muldf3vfp
U ___truncdfsf2vfp
U _objc_enumerationMutation
U _objc_msgSend
U _objc_msgSend_stret
U dyld_stub_binding_helper
The only solution that worked was to include:
"-all_load"
in other linker flags.
EDIT: Be sure to add this flag to the project including the static library, not to the static library itself.
I know this isn't the correct method, but it is working for now.
It maybe a OS 3.0 issue since this was the work around for Three20 as well.
Unfortunately, due to the what categories work and the dynamic nature of the Objective-C runtime, not everything works well with static libraries. The reason you get this error is that the category implementation in the static library is never actually linked into the executable image because the compiler has no way of knowing that the implementation code will be needed at run-time.
In order to cure this, you can force the linker to copy object files from a static archive for any and all Objective-C Class and Category images. The downside is that your executable will include image code for classes that you may not be using at all. To get the linker to include the category code, add -ObjC to the OTHER_LD_FLAGS build setting in Xcode. Your category implementation will now be copied from the static archive to your executable and you won't get the runtime exception.
I just spoke to an Apple engineer about this, and this has been addressed in ld with versions >100. This is included in Xcode 4. He walked me through this and I tried it myself and indeed the category problem is fixed.
Take out "-all_load" and go back to "-ObjC" in your Build Settings with the new linker.
If you are on Xcode 3.2 you can avoid using -all_load and instead use -force_load for just the library in question, which should be slightly more efficient.
This is described in a recently updated Apple Technical QA: http://developer.apple.com/mac/library/qa/qa2006/qa1490.html
The issue that -all_load or -force_load linker flags were needed to link categories has been fixed in LLVM. The fix ships as part of LLVM 2.9 The first Xcode version to contain the fix is Xcode 4.2 shipping with LLVM 3.0. The mentioned fixes are no longer needed when working with Xcode 4.2. The -ObjC flag is still needed when linking ObjC binaries
I ran into this problem recently. I was unable to get the -all_load to work, when I noticed that another category I had DID work. I was lazy for this category and included it in with another file.
I eventually created a dummy class (no methods, instance variables) and included the implementation of my categories in the .m file for that dummy class. After doing this my categories started working even after I removed the -all_load flag.
This was on iPhone OS 3.1.3.
This certainly is not the RIGHT way to fix it, but it seemed to work.
Full sample code is on my blog for my (trivial) categories.
I just had this same problem but adding any combination of the described flags (-ObjC, -all_load, -force_load) did not work.
It turned out that I had not checked the box "Add to Target" when adding the files to the project. I removed the files from the project and added them again, this time making sure that that box was checked. This fixed the problem.
In the past I was able to force linkage of the category with -u .objc_category_name_UIView_Extensions, but with the 3.0 dev environment that's broken and the only option seems to be -all_load.
I had the same problem with Categories in my static library. In my case, "-all_load" didn't help as it caused loads of build errors (my static library is a wrapper around another private C/C++ lib).
I solved it by a hack suggested at http://iphonedevelopmentexperiences.blogspot.com/2010/03/categories-in-static-library.html which simply involved adding a dummy (empty) class definition to the category files. Using this hack, I kept "-ObjC" but dropped "-all_load" in the application linker settings and it worked fine on the device.