I have created a class named Bundle, which I'd really like to remain named that way, as it perfectly describes what it's for in my project.
Now, I'm using Swift's Bundle in some code and now those names are conflicting. I had this issue before when I created the class Set. I was able to solve that by putting Swift.Set when I wanted to use the standard Set class, as I found in this answer on exactly this matter.
I also tried to apply that solution my Bundle problem, but Xcode complains:
Module 'Swift' has no member named 'Bundle'
Any idea why it does work for Set, but not Bundle?
Thanks!
Bundle is defined in the Foundation library, not in the Swift standard
library:
let mainBundle = Foundation.Bundle.main
Related
I'm using Swift class in my existing Object-C project.In my Swift class, I'm using CLLocationManagerDelegate. Everything works well. However, when ProjectName-Swift.h is generated, an issue in ProjectName-Swift.h file shows "Can't find protocol declaration for 'CLLocationManagerDelegate'". I tried to silence the issue by importing CoreLocation/CoreLocation.h in ProjectName-Swift.h. It worked. But after compiled a few times, CoreLocation/CoreLocation.h was gone because ProjectName-Swift.h is generated from my swift class. And the issue comes again.
I'm using cocoa pods and map box was working fine but I installed an update and this message appeared:
Now I can't run my project. I'm using map box iOS sdk 3.3.4. What should I do to fix this issue?
According to apple documentation:
The Swift compiler automatically imports Objective-C code as conventional Swift code. There may be edge cases in your code that are not automatically handled. If you need to change the name imported by Swift of an Objective-C method, enumeration case, or option set value, you can use the NS_SWIFT_NAME macro to customize how a declaration is imported. See more.
So all what I did was delete the implementation of the NS_SWIFT_NAME and with that I was able to build the project. I don't know what made this error appear but this was the best solution I found.
Example:
From this:
- (instancetype)recordWithRPM:(NSUInteger)RPM NS_SWIFT_NAME(init(RPM:));
To this:
- (instancetype)recordWithRPM:(NSUInteger)RPM;
For example, I never use the description of XCTestCase.expectation, so I'd like to use a function to provide a default for it, and make it clear via naming that I'm initializing the expectation, as you can't really use an initializer for XCTestExpectation. But if the extension is not in a test target, then it can't compile:
Cannot load underlying module for 'XCTest'
import XCTest
public extension XCTestCase {
func makeExpectation() -> XCTestExpectation {
return expectation(withDescription: "")
}
}
I've created an xcworkspace here (https://github.com/dtweston/TestFrameworkSample) that demonstrates a solution to your issue. There are two projects in this workspace:
SampleApp project with an iOS app target and a unit test target.
SharedTestFramework project that imports XCTest and declares the single extension you put in your question.
The SampleAppTests target links to the SharedTestFramework to be able to use the extension it defines. The single test file imports the SharedTestFramework.
With those steps, I also encounter the Cannot load underlying module for 'XCTest' when building the SharedTestFramework.
The fix for that is to update the Framework Search Paths to include "$(PLATFORM_DIR)/Developer/Library/Frameworks". Now the SharedTestFramework compiles correctly, and as you can see in the workspace I uploaded, the SampleAppTests target is able to use it successfully.
Old and busted answer
Are you building a separate framework that is designed to be imported into test targets? If that's the case then I think you just need to reference XCTest.framework from this custom framework you're building.
On the other hand, if you're trying to add this extension to a framework that is used by your app target, that seems like a bad idea, because it would mean linking XCTest.framework to the binary that goes to the store and runs on people's devices.
I'm not sure if that's possible. I'm more confident that it's not a scenario Apple expects or supports.
I made a bundle target, and its Info.plist file specifies that a very specific class (let's call it PrincipalClass) should be its principal class. This class was written in Swift and has the #objc attribute. The Info.plist file is correctly copied over to the bundle, and I have cleaned and rebuilt the project multiple times already.
However, when I load the bundle from my Swift framework, its principal class is a different class (let's call it NotPrincipalClass). It was not marked #objc, and in fact, it should be internal to the bundle. I checked bundle.bundleURL in the debugger, and the Info.plist file in the bundle does say that it should be PrincipalClass; but when I check bundle.infoDictionary, the NSPrincipalClass attribute reads NotPrincipalClass as a string! (The info dictionary also contains several keys that were not specified by the Info.plist file, like DTCompiler and such.)
If I entirely remove NotPrincipalClass, I get another internal class instead, which is still totally not my principal class.
I checked the build logs thoroughly and I saw no mention of NotPrincipalClass, except when it got compiled.
What could cause this? What can I do to solve it?
Somehow, using its qualified name instead ("PlugInNamespace.PrincipalClass") solved the problem, but this has me very skeptical because I have another plugin that does not requires this.
I am using XCode 3.2.2 to unit test some custom data types. The tests run properly without those data types, but when I use said data types, I get this error:
"_OBJC_CLASS_$_classname", referenced from:
(where "classname" is the, well, class name...)
I have seen hints online that it could be linker related. The strange thing is, I originally followed these instructions http://www.mobileorchard.com/ocunit-integrated-unit-testing-in-xcode/ and they worked for me the first time I tried them. Now, after following the same instructions, I'm getting the same error. Any help would be greatly appreciated.
Thanks!
-Matt
Unfortunately your question is pretty ambiguous.
First, is the example working given in the mentioned tutorial?
Second, I'd double check your code:
Right click the class (.m) you're trying to use with OCUnit and click get info. Make sure the target in the class file is pointing to OCUnit! This is key for the linking.
Are you importing your .h for the associated class in the test case?
Check the spelling of the class names?