Swift Compile Error - Undefined symbols for architecture arm64 - ios

I'm getting this error on my Swift iOs app when I try to compile:
Undefined symbols for architecture arm64:
"checkForiOS14 #1 () -> Swift.Bool in App_Clip.NoteView.(reminderSymbolName in _82CBB329F1D225F83535F59E6FD7F4C3).getter : Swift.String", referenced from:
App_Clip.NoteView.(reminderSymbolName in _82CBB329F1D225F83535F59E6FD7F4C3).getter : Swift.String in NoteView.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The property it is referring to is a computed property/private var in a view to check the version of iOS:
private var iosVersion = UIDevice.current.systemVersion
private var reminderSymbolName: String {
if checkForiOS14() {
return "checkmark.circle"
} else {
return "checklist"
}
func checkForiOS14() -> Bool {
if let version = Double(iosVersion) {
if version <= 14.9 {
return true
} else {
return false
}
}
return false
}
}
I have done all the basic stuff, deleting derived data, cleaning my build folder, restarted my mac, I even went back to a commit that builds and copied the changed files to the new commit, but this error will not go away. I am not using any pods, but I am using some SPM packages. Any idea what is going wrong?

There's built-in availability checks you can use for this purpose:
private var reminderSymbolName: String {
if #available(iOS 14.9, *) {
return "checkmark.circle"
} else {
return "checklist"
}
}
See https://nshipster.com/available/

Well, isn't that always how it goes? You try everything, post on Stack, and then literally minutes later you fix it? Apparently the answer was taking my method out of the computed property and making it private, like so:
private func checkForiOS14() -> Bool {
if let version = Double(iosVersion) {
if version <= 14.9 {
return true
} else {
return false
}
}
return false
}
private var reminderSymbolName: String {
if checkForiOS14() {
return "checkmark.circle"
} else {
return "checklist"
}
}
Hope this helps you if you are stuck like I was...

Related

Replace deprecated `SecTrustGetCertificateAtIndex` in iOS 15?

I'm getting a deprecation warning in iOS 15 SDK, but the suggested replacement is not a one-to-one replacement. This is what I have for evaluating the SSL trust chain:
func valid(_ trust: SecTrust, forHost host: String) -> Bool {
guard valid(trust, for: [SecPolicyCreateSSL(true, nil)]),
valid(trust, for: [SecPolicyCreateSSL(true, host as CFString)]) else {
return false
}
let serverCertificatesData = Set(
(0..<SecTrustGetCertificateCount(trust))
.compactMap { SecTrustGetCertificateAtIndex(trust, $0) }
.map { SecCertificateCopyData($0) as Data }
)
let pinnedCertificatesData = Set(
certificates.map { SecCertificateCopyData($0) as Data }
)
return !serverCertificatesData.isDisjoint(with: pinnedCertificatesData)
}
The warning I get in Xcode 13 beta is:
'SecTrustGetCertificateAtIndex' was deprecated in iOS 15.0: renamed to 'SecTrustCopyCertificateChain(_:)'.
Use 'SecTrustCopyCertificateChain(_:)' instead.
However, SecTrustGetCertificateAtIndex (docs) returns SecCertificate where SecTrustCopyCertificateChain (docs) returns a CFArray. How can this properly be updated in the usage I provided?
iOS 14.5 => iOS 15 SDK Diff indicates that the only additions are these (as of Xcode 13 Beta 1)
SecBase.h
Added errSecInvalidCRLAuthority
Added errSecInvalidTupleCredentials
Added errSecCertificateDuplicateExtension
SecTrust.h
Added SecTrustCopyCertificateChain()
They didn't add any new sibling type to SecCertificate. As you already noted that it returns a CFArray.
func SecTrustCopyCertificateChain(_ trust: SecTrust) -> CFArray?
So for this part of your code -
let serverCertificatesData = Set(
(0..<SecTrustGetCertificateCount(trust))
.compactMap { SecTrustGetCertificateAtIndex(trust, $0) }
.map { SecCertificateCopyData($0) as Data }
)
It seems worth a try that SecTrustCopyCertificateChain might return a CFArray of SecCertificate instances? Unfortunately I can't debug this right now.
Maybe try something like this -
if let certificates = SecTrustCopyCertificateChain(trust) as? [SecCertificate] {
let serverCertificatesData = Set(
certificates.map { SecCertificateCopyData($0) as Data }
)
}

Use of unresolved identifier 'className': Xcode recognises all classes defined in files except one

I have these Swift files. Each one contains a class with a similar name.
In the file CMErrorHandler, I have this code:
if let _ = CMSessionManager.sharedInstance.tokenExpiration {
sessionExpired = CMSessionManager.sharedInstance.tokenExpiration!.isLessThanDate(dateToCompare: Date())
}
let error = CMError(code: errorCode, title: errorTitle, message: errorDescription)
if error.code == 1160 || error.code == 401 || sessionExpired {
//Session expired --> Logout
showAlertAndPop(title: (error.title)!, message: (error.message)!, action: {
// The code inside the disconnect function has been commented
// Check comment inside of function
CMProfileManager.sharedInstance.disconnect()
})
// return
}
The code that uses CMSessionManager class works fine:
if let _ = CMSessionManager.sharedInstance.tokenExpiration {
sessionExpired = CMSessionManager.sharedInstance.tokenExpiration!.isLessThanDate(dateToCompare: Date())
}
But, the code that uses CMProfileManager throws an error:
CMProfileManager.sharedInstance.disconnect()
The error:
Use of unresolved identifier CMProfileManager
I don't understand, why can Xcode find CMSessionManager and cannot find CMProfileManager if both are defined in the same way and in the same location.
class CMProfileManager {
static let sharedInstance = CMProfileManager()
}
Clean build if does not resolve .. restart your Xcode.. Check the "Target Membership" of the CMProfileManager.swift file in the right panel. Is your target checked

iOS error: cannot find the symbol when linking in Swift

I have following code in Swift in A.swift file:
/// **A.swift**
protocol Johnkui: class {
var name: TruncatedView? { get set }
}
/// typealias TruncatedView = String
class TruncatedView: UIView {
}
extension UIView {
private struct TruncatedViewKey {
static var navigationViewKey = "navigationViewKey"
}
var name: TruncatedView? {
set {
objc_setAssociatedObject(self, &TruncatedViewKey.navigationViewKey, newValue, objc_AssociationPolicy.OBJC_ASSOCIATION_ASSIGN)
}
get {
return objc_getAssociatedObject(self, &TruncatedViewKey.navigationViewKey) as? TruncatedView
}
}
}
and B.swift file has following code:
/// B.swift
class JJ: UIView, Johnkui {
}
When compiling these two files, a linking error was reported:
Undefined symbols for architecture x86_64:
"__TFE9SwiftTestCSo6UIViewm4nameGSqCS_13TruncatedView_", referenced from:
__TTWC9SwiftTest2JJS_7JohnkuiS_FS1_m4nameGSqCS_13TruncatedView_ in ViewController.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
However, when combining these two files into one, the error is gone, and I cannot find out the reason for this result, what's your explanation?

I'm trying to archive a meteor-built ios app, but Xcode but I keep getting 'Ambiguous use of […]'

I built this project from a meteor app (with meteor build ios...).
I've set it to use the legacy version of Swift (otherwise I get a lot of errors). But when I try to archive it, i get this error in different locations.
func cancel() { // Error: Ambiguous use of 'dispatch_sync(_:block)'
dispatch_sync(queue) {
self._cancel()
}
}
func dispatch_sync(queue: dispatch_queue_t, block: () throws -> ())throws { // 1. Found this candidate
var caughtError: ErrorType?
dispatch_sync(queue) {
do {
try block()
} catch {
caughtError = error
}
}
if let caughtError = caughtError {
throw caughtError
}
}
func cancel() { // 2. Found this candidate
dispatch_sync(queue) {
self._cancel()
}
}
I'm not sure how to solve it, could you help me?
PS: I'm using the latest version of Xcode with MacOS Sierra. And Meteor 1.4.1.2
Rename your function dispach_sync into, for instance, dispatch_sync_mine

Undefined symbols Swift.UnsafeMutableBufferPointer

After downloading Xcode 8 and migrating to Swift 3 I'm not longer able to archive the project. At the same time the project builds without any issues.
Error that I get:
Undefined symbols for architecture armv7:
"Swift.UnsafeMutableBufferPointer.(subscript.materializeForSet :
(Swift.Int) -> A).(closure #1)", referenced from:
function signature specialization of generic specialization
with
Swift.UnsafeMutableBufferPointer :
Swift.MutableCollection in Swift and
Swift.UnsafeMutableBufferPointer :
Swift.RandomAccessCollection in Swift> of Swift._siftDown (inout A,
index : A.Index, subRange : Swift.Range, by : inout
(A.Iterator.Element, A.Iterator.Element) -> Swift.Bool) -> () in
OrderCoordinator.o
function signature specialization of generic specialization
with
Swift.UnsafeMutableBufferPointer :
Swift.MutableCollection in Swift and
Swift.UnsafeMutableBufferPointer :
Swift.RandomAccessCollection in Swift> of Swift._heapSort (inout A,
subRange : Swift.Range, by : inout (A.Iterator.Element,
A.Iterator.Element) -> Swift.Bool) -> () in OrderCoordinator.o
function signature specialization of generic specialization
with
Swift.UnsafeMutableBufferPointer :
Swift.MutableCollection in Swift and
Swift.UnsafeMutableBufferPointer :
Swift.RandomAccessCollection in Swift> of Swift._partition (inout A,
subRange : Swift.Range, by : inout (A.Iterator.Element,
A.Iterator.Element) -> Swift.Bool) -> A.Index in OrderCoordinator.o
ld: symbol(s) not found for architecture armv7 clang: error: linker
command failed with exit code 1 (use -v to see invocation)
I was able to get rid of error by commenting array sorting code in following function:
func didFinishWithResults(_ results: [PhotoProcessorResult]) {
guard let album = albumService.currentAlbum else { return }
//let sortedResults = results.sorted(by: { $0.fileIndex < $1.fileIndex })
let updateItems = zip(sortedResults, album.assetItems).map { (photoProcessorResult, assetItem) -> UpdateItem in
UpdateItem(path: photoProcessorResult.filePath, position: photoProcessorResult.fileIndex, isCover: assetItem.isCover)
}
albumService.updateAlbumWithItems(updateItems) { (success, errorDescription) in
if success {
self.handleAlbumUpdate()
} else {
self.showFailureAlert(errorDescription) {
self.startProcessingAlbum(self.albumService.currentAlbum)
}
}
}
}
While I resolved issue by sorting data using NSArray, I don't like this solution.
Will be grateful for any suggestions.
Since it compiles i don't think there is anything wrong with your code. The fact that it says "Undefined symbols for architecture armv7" and is failing to archive tells me that something is going on with your project, but unfortunately there are many ways to cause this problem. arm7 is iphone 5 so your project is probably setup correctly only for arm64. Try the solutions mentioned here: Undefined symbols for architecture armv7
If here is problem only for the this line:
let sortedResults = results.sorted(by: { $0.fileIndex < $1.fileIndex })
You can change to it:
let sortedResults = results.sorted { (first, second) -> Bool in
return first.fileIndex < second.fileIndex
}
Did it solve your problem?
Issue disappeared after updating to XCode 8.1.
Thanks everyone :)

Resources