Xcode: swiftc failed with exit code 1 - ios

I have problem with this function:
func isSmallDevice() -> Bool {
if UIDevice().userInterfaceIdiom == .Phone {
if UIScreen.mainScreen().nativeBounds.height <= 1136 {
return true
}
}
return false
}
Basically if I comment these lines build will succeed and if not it will fail with following error:
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
No other errors or warnings are shown and note that I am not calling this function. I also tried quitting Xcode, deleting derived data and cleaning project.

Related

Swift Compile Error - Undefined symbols for architecture arm64

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...

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

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

Swift compiler error: segmentation fault: 11 on Archive

When archiving my iOS app prior to submission for App Store release, I get an error that says
Command failed due to signal: Segmentation fault: 11
Then there's a huge block of paths and whatnot and at the end is a mention of a function that I have in the app. Here's the function:
func matrixOperationRequiresScalar(operation: MatrixOperation) -> Bool {
switch operation {
case .Addition, .Subtraction, .Multiplication, .Division, .Negative, .Determinant, .Inverse, .Transpose, .EigenOps: return false
case .ScalarMultiplication, .ScalarDivision, .Power: return true
}
}
You can tell that operation is an enum and all cases are covered here.
What can I do to fix this?
The switch you have in your code is missing the default case which is required in swfit. You can easily correct this :
func matrixOperationRequiresScalar(operation: MatrixOperation) -> Bool {
switch operation {
case .Addition, .Subtraction, .Multiplication, .Division, .Negative, .Determinant, .Inverse, .Transpose, .EigenOps: return false
case .ScalarMultiplication, .ScalarDivision, .Power: return true
default: return true
}
}
Source

Xcode swift failed with exit code 254

I am getting this compiler error in my code and I can't figure out why:
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)
Command /Applications/Xcode6-Beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift failed with exit code 254
The error is showing up somewhere in the following code segment:
var animalViewToSwap: AnimalView = animalViewMatrix.objectAtRow(0, andColumn: 0) as AnimalView
var currentRow = 0
var currentColumn = 0
var animalToSwapWith = true
var currentLocation = animalViewMatrix.findLocationOfObject(animalView)
currentRow = Int(currentLocation.row) - 1
currentColumn = Int(currentLocation.column) - 1
var rowDisplacement = 0
var columnDisplacement = 0
switch inDirection{
case "left":
columnDisplacement = withDistance * -1
if (Int(animalViewMatrix.columns) > currentColumn + columnDisplacement)&&(currentColumn + columnDisplacement >= 0)&&(animalViewMatrix.objectAtRow(CInt(currentRow), andColumn: CInt(currentColumn + columnDisplacement)) is AnimalView)
{
animalToSwapWith = true;
}
else { animalToSwapWith = false }
default:
println("error")
animalToSwapWith = false
break
}
(I have more cases that are very similar and am leaving them out for simplicity - the bug isn't in them)
First Error
One bug is in the line: animalToSwapWith = falseand if I set it to true and comment all the rest out besides the variable initialization lines the error goes away. Also if I comment all of it out but instantiate animalToSwapWith to false the error occurs even though it doesn't when it is instantiated to true.
Second Error
There is a second error in the line:if (Int(animalViewMatrix.columns) > currentColumn + columnDisplacement)&&(currentColumn + columnDisplacement >= 0)&&(animalViewMatrix.objectAtRow(CInt(currentRow), andColumn: CInt(currentColumn + columnDisplacement)) is AnimalView) In this line all of these methods have been called earlier in the file with variables of the same types above so knowledge of the methods shouldn't matter.
Conclusion
Is there a reason why these two errors are occurring or is it because swift and Xcode-6 are still in beta testing and it is a bug in Xcode? Also note that when commenting the two errors out from each other one at a time the error message is the same.
This is a Swift compiler bug, apparently testing for two or more implicitly unwrapped optionals causes the compiler to crash under some/many circumstances. Use Apple's Bugreporter to file this issue, mark it as duplicate of rdar://17212295.
Example
Here's a minimal example that crashes with the same error:
let a: String!
let b: String!
if a && b {
println("have both")
}
Compile on command line as follows and witness the same crash:
$ xcrun swift -v -g crash.swift
I was getting the same error and I tracked it down to this: I was extending NSError and in the extension was defining an enum. Moving the enum definition out of the extension fixed the error.
extension NSError {
enum WYBErrorCodes: Int {
case Fatal = 1000
case XmlParse = 1100
case CoreData = 1200
}
[...]
}
I'm getting the same error when adopt NSTextViewDelegate protocol for my class. If I remove that protocol, compilation goes fine. Strange indeed.
For the sake of providing other possible causes and how to fix them; I was trying to set the region of a map view within in dispatch block. If I commented out the setting of the region, the error goes away.
dispatch_once(&centerMapLocation, {
// var theSpan: MKCoordinateSpan = MKCoordinateSpanMake(0.01, 0.01)
// var theRegion: MKCoordinateRegion = MKCoordinateRegionMake(manager.location.coordinate, theSpan)
// self.map.setRegion(theRegion, animated: true)
})
}
I am getting this same error when I try to extend NSArray to have a foreach method:
extension NSArray {
func foreach(f: (AnyObject -> ())) {
for elem in self {
f(elem)
}
}
}
It would appear that extending NSArray with func that takes a function argument will cause the same problems. I worked around the issue by defining a forEachInArray function that takes the NSArray as an argument:
func forEachInArray<T>(array: NSArray, f: (AnyObject -> ())) {
for elem in array {
f(elem)
}
}
In my case, i was calling an objective-c function from swift through bridge. Signature was like -
- (SomeReturnType *)getSomething:(SomeOptions *)options
success:(void (^)(NSArray *response))success
failure:(void (^)(NSError *error))failure;
From swift, i was calling it as follows and getting compile error as "Xcode swift failed with exit code 254" -
ObjCClass().getSomething(nil, success: {(response : Array!) in
}, failure: {(error: NSError!) in
})
changing it to following worked for me -
ObjCClass().getSomething(nil, success: {(response : [AnyObject]!) in
}, failure: {(error: NSError!) in
})
I had this error and the bug was solved in Beta 7 available online today.

Resources