ld:Framework not found for architecture i386 - ios

I am trying to test a method in my framework, and I wrote a simple test case. But it fails to execute , and xcode gives me the error:
ld: framework not found V***ments for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)
I double checked that the framework is added in the embedded binary and also in build phase section.
Here is my test file:
import XCTest
#testable import MYClass
class MYClassTests: XCTestCase {
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}
func testExample() {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock {
// Put the code you want to measure the time of here.
}
}
func testInitalization() {
// tests pass when I comment the following lines.
// let one = MYClass.sharedInstance
// XCTAssertNotNil(one, "Failed to create a MYClass instance")
}
}
When I uncomment the above two lines, I get the Framework not found error.
Also I did tried the following ways:
The framework is added in the Embedded binaries framework section.
Embedded contains swift code is set to YES,as the framework contains swift code.
Executable Prefix in the Packaging section is empty. (It is not set to #executable_path/Frameworks)
Runpath Search path in linking is set to
$(inherited)
#executable_path/Frameworks
#loader_path/Frameworks
Also I tried clean the project and restart the xcode, and build the framework.
Deleted the derived data.
I am not sure what could be the issue. Any ideas?

This is likely because the framework isn't compiled for either the iOS simulator or for your Mac (maybe you've selected an iOS device as the build target).
If you have access to the framework target's project files, head to the Build Settings section and under Build Active Architecture Only select No.
Hope this helps!

That means that V *** ments does not have a version that can be compiled for i386 phones such as iphone 5 and others.
It was useful for me to compile from the termial using this command:
xcodebuild ARCHS = arm64 -scheme <YOUR SCHEME> -workspace <NAME OF WORKSPACE> .xcworkspace / -configuration Debug build

Related

Calling swift function from objective c gives linker error

I am trying to call swift function from objective c file.
Swift function implementation:
#objc class FXFormVariables : NSObject {
class func FXFontName() -> String { return fontName }
class func FXFontSize() -> CGFloat { return fontSizeLarge }
class func FXHiddenCell() -> NSArray { return hiddenElementFromFormIndex as NSArray }
}
Objective C:
NSArray *hideArray = [FXFormVariables FXHiddenCell];
if ([hideArray containsObject:#(cellIndexPath)]){
return 0.0;
}
Linker error in Buildtime:
Undefined symbols for architecture x86_64:
"_OBJC_CLASS_$__TtCC13Social_Engine11AppDelegate15FXFormVariables", referenced from:
objc-class-ref in FXForms.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
This code works fine in Xcode 7.3 but after upgrade to 8.3 it start throwing linker error.
Please help. Thanks in advance.
Import file named Project name appending by -Swift.h in your Objective-C file
Please check below example of import file
#import “ProjectName-Swift.h”
Xcode will generate this file when you build your project with .swift files.
Also, you can check from below question:
How to import Swift code to Objective-C
you can get this type of error check your class is listed under the "Compile Sources" step of the "Build Phases" tab of your target. Normally Xcode does this for you, but sometimes it loses the plot and you need to add the class file manually.
To do this:
TargetSettings -> Build Phases -> Compile Sources -> add your class -.swift >Build and Run

Swift compiler: Printing the AST of a Swift file with 3rd party imports

I'm trying to print the Abstract Syntax Tree (AST) from a Swift file using the Swift compiler with the -print-ast flag. This is without Xcode & xcodebuild.
I'm stuck handling imports of 3rd party frameworks, built via Carthage. Given a source file with the following code:
Source
import Foundation
import BrightFutures // 3rd party framework
class MyAsyncService {
func asyncFunc() -> Future<String, NSError> {
return Promise<String, NSError>().future
}
}
Compiling for MacOS works
By specifying the framework search path (-F) the following command:
swiftc -print-ast Source.swift -F Carthage/Build/Mac
Produces the expected output:
import Foundation
import BrightFutures
internal class MyAsyncService {
internal func asyncFunc() -> Future<String, NSError>
#objc deinit
internal init()
}
Compiling for iOS?
I need to print the AST for a project only targeting iOS, with dependencies built for iOS.
When I try pointing to the frameworks built for iOS:
swiftc -print-ast Source.swift -F Carthage/Build/iOS
The command fails:
Source.swift:2:12: error: module file was created for incompatible target x86_64-apple-ios8.0: [...]/Carthage/Build/iOS/BrightFutures.framework/Modules/BrightFutures.swiftmodule/x86_64.swiftmodule
import BrightFutures // 3rd party framework
^
import Foundation
import BrightFutures
internal class MyAsyncService {
internal func asyncFunc() -> <<error type>>
#objc deinit
internal init()
}
I've tried also tried adding the -sdk flag:
-sdk $(xcrun --sdk iphoneos --show-sdk-path) to specify the iphoneos SDK, but this spits out an error about unsupported architectures.
How can I get this to build?
Looks like an alternative to printing the AST with the Swift compiler is to use SourceKit.
There's a CLI tool called SourceKitten which allows you to parse the structure of a Swift source file into JSON format, without needing to handle imports of 3rd party frameworks and other source files.

Fastlane Snapshot with Objective-C

I am attempting to use Fastlane to take screenshots of my app using the snapshot tool. However The conversion to Objective-C doesn't appear to be working correctly. I have Project-Swift.h imported into my ProjectUITests.m file, and I have included the following code:
SnapshotHelper *snapshotHelper = [[SnapshotHelper alloc] init];
[snapshotHelper setLanguage:app];
[snapshotHelper snapshot:#"01Homescreen" waitForLoadingIndicator:YES];
However, when I run the command "snapshot" in the command line, I get the following errors:
Testing failed:
Use of undeclared identifier 'SnapshotHelper'
Use of undeclared identifier 'snapshotHelper'
(1 failure)
[12:14:52]: Exit status: 65
[12:14:52]: Tests failed - check out the log above
So my question is, how do I get the SnapshotHelper.swift file to run successfully in my ProjectUITests.m file?
I had to change the SnapshotHelper.swift file:
var deviceLanguage = ""
#objc class SnapshotHelper : NSObject { // <--- add this
#available(*, deprecated, message="use setupSnapshot: instead")
class func setLanguage(app: XCUIApplication) {
setupSnapshot(app)
}
...
} // ...#objc class
(Here is the related issue on github: https://github.com/fastlane/snapshot/issues/228)
From time to time my Xcode did not create the bridging headers for me. The easiest work around for that was to remove the swift file from the project and add it again. Usually then Xcode asked whether I want the bridging headers.
Eventually you may need to go to your target's Build Settings > Apple LLVM 7.0 - Language - Modules > Enabled Modules (C and Objective-C) = YES .

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.

Unable to integrate ZXingObjC in a iOS Swift Project

Im working on an iOS project, which shows the customer number in a barcode. I had installed the framework ZXingObjC with CocoaPods, described in GitHub.
I can compile my Project without errors. I can also use the classes of ZXingObjC in my Objective-C classes, without errors. After than, I have added the import Command #import <ZXingObjC/ZXingObjC.h> to my bridging header file, like my other custom objective-c classes, without compile errors. (I had testet the header file by destroying some import statements and got the expected file not found exception.)
But now, I can't use any class of ZXingObjC in my swift classes. I only got the following compile error: Use of undeclared type '...'. The Xcode autocomplete is not working, too.
e.g.
var test : ZXMultiFormatWriter?
>> Use of undeclared type 'ZXMultiFormatWriter'
I tried:
setup new project, same issue
checked header search path: $(SRCROOT)/Pods/Headers/Public/Adjust
reinstalled the ZXingObjC framework
checked build settings: Enable Modules: YES
checked build settings: Other Linker Flags: $(inherited) -ObjC
-framework "ZXingObjC"
checked linked binaries in the build phases: framework is added
checked import statement in the bridging header file (#import
<ZXingObjC/ZXingObjC.h> and #import "ZXingObjC/ZXingObjC.h" -- no
difference)
Windows style: restarting Xcode and Mac ;-)
I'm using:
Xcode: 6.3.2
CocoaPods: 0.37.2
Project Deployment target: iOS 8.0
SDK: 8.3
Does anyone know the problem? Can anyone help?
How can I make the ZXingObjC framework available in swift?
Actually it is an easy issue:
Podfile
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!
pod 'ZXingObjC', '~> 3.1'
So, on terminal:
cd workspace
pod install
Then, once opened project on Xcode, you have to edit bridging-header adding ZXingObj:
#import <ZXingObjC/ZXingObjC.h>
Finally, in your swift classes that uses ZXingObjC, you have to import ZXingObjC.
import ZXingObjC
class ZXingObjCWrapper {
func encode() {
let writer = ZXMultiFormatWriter.writer()
....
}
}
The rest of the code for when you need to set an UIImage with this bar code:
func generateDataMatrixQRCode(from string: String) -> UIImage? {
do {
let writer = ZXMultiFormatWriter()
let hints = ZXEncodeHints() as ZXEncodeHints
let result = try writer.encode(string, format: kBarcodeFormatDataMatrix, width: 1000, height: 1000, hints: hints)
if let imageRef = ZXImage.init(matrix: result) {
if let image = imageRef.cgimage {
return UIImage.init(cgImage: image)
}
}
}
catch {
print(error)
}
return nil
}
The header search path was not correct in my project. The right values are:
$(inherited)
"${PODS_ROOT}/Headers/Public"
"${PODS_ROOT}/Headers/Public/ZXingObjC"
The second and third lines were not added by installation with CocoaPods.
EDIT: The installed framework have to be added to "Embedded Binaries" in General tab of the project.
I tried everything on this page to add ZXingObjC as a Pod. My goal was to generate an Aztec barcode.
I checked my Header Search Path. As Reddas said, I had to manually add "${PODS_ROOT}/Headers/Public/ZXingObjC". I also added ZXingObjC as an Embedded Binary (in the General Tab).
I checked my bridging file & all was good. I checked my view controllers where I wanted to generate the barcode. The import ZXingObjC was there.
No compile errors. But I can't declare a variable of ZXingObjC.
No luck. Any more suggestions?
EDIT - I went into the Targets, Build Settings and searched for Header Search Paths. I added in BOTH "${PODS_ROOT}/Headers/Public/ZXingObjC" and "${PODS_ROOT}/Headers/Private/ZXingObjC"
This seemed to unclog whatever broke. It works now. Strangely, I can now even delete those entries and it works.

Resources