"unsafeMutableAddressor : Swift.String", referenced from:.." - ios

I got an error:
Undefined symbols for architecture x86_64:
"DirectBistro.DBTabBarOrderedIndexesKey.unsafeMutableAddressor : Swift.String", referenced from:
DirectBistroUITests.TabBarControllerTests.setUp (DirectBistroUITests.TabBarControllerTests)() -> () in TabBarControllerTests.o
ld: symbol(s) not found for architecture x86_64
This is my simple UITest class:
import XCTest
#testable import DirectBistro
class TabBarControllerTests: XCTestCase {
override func setUp() {
super.setUp()
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject([], forKey: DBTabBarOrderedIndexesKey)
defaults.synchronize()
}
}
This is how it is defined in DBTabBarController.swift:
let DBTabBarOrderedIndexesKey = "TabBarOrderedIndexesKey"
Info pane:
General pane:

The conslusion is: it is not going to work.
I report it as a bug to Apple, and got a response:
UI tests execute differently from Unit tests - Unit tests run inside your application process so they can access your application code. UI tests execute in a separate process, outside your application, so they can simulate how the user interacts with the application. It’s not expected that you will be able to access your app class from a UI test.

It is possible to access application code from your UI tests. Just add the source file to the UI test target:
You can then access that application code from within your UI test code:
But bear in mind that the application code you're accessing thus from your UI Test is code running in your UI Test target (MyAppUITests), it does not correspond to the code running in the actual app target (MyApp). So do not use it to inspect or modify application state.

I had the same problem when I added my swift package and tried to use a string variable inside it. The fix is just to add the swift package in the frameworks, libraries section in the target General section

I received similar error while running test case. I identified that there were certain string values being referred in my test case from another file in the main iOS app project. They couldn't be accessed here.
I solved it by creating a local constant in my test case method. You may please suggest a better way.

Related

Use of undeclared type 'XCTestCaseEntry'

Hi I can't seem to figure out why I am Use of undeclared type 'XCTestCaseEntry'
when using the following code in my .xctest:
import XCTest
#if !os(macOS)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(TrakkproTests.allTests),
]
}
#endif
I just ran into the same issue while attempting to run unit tests for a custom framework I've built using the Swift Package Manager.
It turned out I had accidentally selected an iOS simulator in the Xcode scheme/device selector:
This compiled the code for iOS which satisfies the compilation condition of !os(macOS) and causes the error to occur. XCTestCaseEntry appears to be part of the swift-corelibs-xctest project which provides XCTest functionality to non-Apple platforms (i.e. linux) but is not the same implementation Apple uses... I think.
The solution for me was to select "My Mac" in the scheme/device selector:
looks like the typealias XCTestCaseEntry is added as part of the commit https://github.com/apple/swift-corelibs-xctest/commit/1c7fb283231ce53960a232aa7c771bb2d38dee62 on oct 2017.
I don't think the XCTestCase class as part of the XCode/XCTest has this change yet. Where are you checking this anyway ?

UITest: Undefined symbols for architecture armv7

I'm trying to call a swift singleton from my UITest target. I'm importing the main module: #testable import Ary but when I try to build it says:
Undefined symbols for architecture armv7:
"Ary.DataModelLayerOperation.getter : Ary.DataModelLayer", referenced from:
AryUITests.AryUITests.setUp (AryUITests.AryUITests)() -> () in AryUITests.o
d: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Syntax highlighting works though (the singleton doesn't have access modifiers, so it's marked as internal which should be perfectly fine for access from the test target)...
The function I'm calling is [in an XCTestCase]:
override func setUp() {
super.setUp()
if !DataModelLayerOperation.isUserLoggedIn() {
//do something
}
}
I'm afraid what you want to achieve is not possible at the moment. I have encountered similar problem and asked my question here. I will soon accept the answer that says:
The UI tests are a separate module from the app, therefore not run
inside your app as a logic test would.
I'm hoping this will be improved in the next Xcode versions.

(Swift) Error: UIApplicationMain attribute cannot be used in a module

So, as part of my effort to learn Swift, I got my hands on the open source "Adventure" project (found HERE) made available by Apple.
Embarrassingly, I didn't go too far before I ran into my first predicament. When I tried to compile the project, I got the following error:
'UIApplicationMain' attribute cannot be used in a module that contains top-level code'
Specifically, the error is found in the AppDelegate.swift file and the attribute comes immediately after the import UIKit declaration as follows:
import UIKit
#UIApplicationMain
class AppDelegate: NSObject, UIApplicationDelegate {
var window: UIWindow?
....
// a number of functions that I won't list here...
....
}
I did some research on this but understandably(?) there doesn't seem to be much information regarding this issue. I wonder if anyone has run into the same issue.
(By the way, I am using Xcode6-beta5)
EDIT 1 --------------
Now with a fresh install of Beta6, I get the following errors after compile:
Undefined symbols for architecture x86_64:
"TFSs15_arrayForceCastU___FGSaQ__GSaQ0", referenced from:
__TFC9Adventure13HeroCharacter20animationDidCompletefS0_FOS_14AnimationStateT_ in HeroCharacter.o
__TFC9Adventure13HeroCharacter14fireProjectilefS0_FT_T_ in HeroCharacter.o
__TFC9Adventure4Cave15applyCaveDamagefS0_FTSd10projectileCSo6SKNode_T_ in Cave.o
__TFC9Adventure4Cave12performDeathfS0_FT_T_ in Cave.o
__TFFC9Adventure4Cave16loadSharedAssetsFMS0_FT_T_U_FT_T_ in Cave.o
__TFC9Adventure6Goblin20animationDidCompletefS0_FOS_14AnimationStateT_ in Goblin.o
__TFFC9Adventure6Goblin16loadSharedAssetsFMS0_FT_T_U_FT_T_ in Goblin.o
...
"__TFSsoi1aUSs17_RawOptionSetType_USs21BitwiseOperationsTypeSs9Equatable__FTQ_Q__Q_", referenced from:
__TFC9Adventure21LayeredCharacterScene14handleKeyEventfS0_FTCSo7NSEvent7keyDownSb_T_ in LayeredCharacterSceneOSXEvents.o
"__TFVSC6CGSizeCfMS_FT5widthSd6heightSd_S_", referenced from:
__TFFC9Adventure6Archer16loadSharedAssetsFMS0_FT_T_U_FT_T_ in Archer.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
I'm not even going to try to guess what these errors mean.
Apparently the Adventure project doesn't compile correctly in Xcode6-Beta5. However, Xcode6-Beta6 compiles and runs it just fine.
As for the error encountered after upgrading to Beta6, the way to fix that is to delete the derived data for the project. To do that, open the Organizer ("Window" menu -> "Organizer"), select the "Adventure" project on the left side of the window, then click the "Delete" button associated with the project's derived data (should be the top one on the far right).
For me, It seems there was another file called main.swift which was conflicting with my AppDelegate. I deleted it and the issue went away.

iOS Swift unit test result in unresolved identifier

Simple function in swift for testing:
func testExample() {
var tagname = "someClass()"
var logger = Device("", "") //unresolved identifier
XCTAssert(true, "Pass")
}
Even after I import my module with "import ", I still cannot use classes from my module. Also though I might have messed something up in the project, but NONE of my sample projects will let me use module classes.
Seems like it should work but might have broken in beta 2.
EDIT: fixed it
The IDE didn't pick up the check for the param names. Seems Xcode is still a tad iffy
I hit the same issue today, not sure if this is only available recently - rather than using import TARGET_NAME in your test file and/or declaring your classes/methods as public, you can add your file to your Tests target via XCode's File Inspector.
Cmd + Opt + 1 to show it while in any file, and check the box under Target Membership for your Tests Target.
You may need to rebuild.... Cmd + b.
Should this be specific to my system.... I'm running Xcode 6.3 beta 1, and testing via Quick + Nimble, both installed with the latest cocoapods beta.
The problem for me was that I had non-alphanumerical characters in my main target name.
I had to import it the following way (Note the special #testable annotation)
#testable import my_tutorial_app
It seems that in Xcode 6 Beta 4 you need to declare public classes and methods as "public". Example:
public class Device {
public init(...) {
}
public func myMethod(...) {
}
}
Now they are accessible from the swift test class.
I had the same problem and discovered that it works if I call it like this:
SuperStructName.StructName

Unit testing a static library with RestKit

I'm attempting to follow along with the RestKit unit test guide ( https://github.com/RestKit/RestKit/wiki/Unit-Testing-with-RestKit ) except that my project is a static library instead of an app.
Here is the test I've written:
- (void)testMappingOfDate
{
id parsedJSON = [RKTestFixture parsedObjectWithContentsOfFixture:#"plan.json"];
RKMappingTest *test = [RKMappingTest testForMapping:[self planMapping] object:parsedJSON];
[test expectMappingFromKeyPath:#"plan.date" toKeyPath:#"date"];
STAssertNoThrow([test verify], nil);
}
When I attempt to run the test I receive this error on the first line of the test:
error: testMappingOfDate (api_clientTests) failed: -[NSBundle parsedObjectWithContentsOfResource:withExtension:]: unrecognized selector sent to instance 0x1765c40
It seems like its not finding the NSBundle category defined by RestKit, but my test target header search path is set to "$(BUILT_PRODUCTS_DIR)/../../Headers" and I've verified this path includes NSBundle+RKAdditions.h which contains the supposed "unrecognized selector".
Is there something I'm missing here?
You are trying to include a category within your binary that comes from a library. To get that accomplished you will need to add the following to your (Unit-Test-Target's) build settings.
Other Linker Flags: -ObjC
From Apple's QA:
Objective-C does not define linker symbols for each function (or
method, in Objective-C) - instead, linker symbols are only generated
for each class. If you extend a pre-existing class with categories,
the linker does not know to associate the object code of the core
class implementation and the category implementation. This prevents
objects created in the resulting application from responding to a
selector that is defined in the category.
Solution:
To resolve this issue, the static library should pass the -ObjC option
to the linker. This flag causes the linker to load every object file
in the library that defines an Objective-C class or category. While
this option will typically result in a larger executable (due to
additional object code loaded into the application), it will allow the
successful creation of effective Objective-C static libraries that
contain categories on existing classes.
The error means that the "unrecognized selector" issue is at runtime. The compiler and NSBundle+RKAdditions.h do not give this error they would at compile timr.
The issue is that the code that has #implementation NSBundle(RKAdditions) is not linked into your app. So you need to add this to your build

Resources