Segmentation fault when using toRaw() - ios

Working on swift programming language. Using XCode 6.1 GM with iOS 8.1 Beta.
In 2 places inside code getting error message:
Method 'fromRaw' has been replaced with a property 'rawValue'. When I replace .toRaw() with .rawValue getting unknown compiler error.
if self._attached != nil && self._attached!.toRaw() == i {
continue
}
...
self._segmentPoints[direction.clockwise().toRaw()].0, self._segmentPoints[direction.counterclockwise().toRaw()].1)
What am I doing wrong? any suggestions on how to use .rawValue?

toRaw and fromRaw are cancel by new version of xcode
replace by "rawValue"
eg:
enum Rank: Int{
case Ace = 1
case Two,Three,Four
case Jack,Queen,King
func simpleDesc() -> String {
switch self {
case .Ace:
return "ace"
case .Jack:
return "jack"
default:
return String(self.rawValue)
}
}
}
let ace = Rank.Jack
let aceRawValue = ace.rawValue
println(aceRawValue)
let b = Rank(rawValue: 5)
println(b!.simpleDesc())

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 }
)
}

Build error in project developed on older version of Xcode and reopened on Xcode 12.5?

I encountered these errors when running my project on the new version of Xcode 12.5:
Cannot convert value of type 'UnsafeMutablePointer' to expected argument type 'UnsafeMutablePointer<CFError?>'
1. Arguments to generic parameter 'Pointee' ('SecTrustResultType' and 'CFError?') are expected to be equal
Previously I had worked on the old versions of Xcode (Version 11 and Swift 5).
private func trustIsValid(_ trust: SecTrust) -> Bool {
var isValid = false
var result = SecTrustResultType.invalid
let status = SecTrustEvaluateWithError(trust, &result) // code string where it gives me this error
if status == errSecSuccess {
let unspecified = SecTrustResultType.unspecified
let proceed = SecTrustResultType.proceed
isValid = result == unspecified || result == proceed
}
return isValid
}
I don't believe this code ever compiled. The second parameter should be a pointer to an Optional error, not a result.
In any case, you can just pass nil as the second parameter. To get a result, call https://developer.apple.com/documentation/security/1396077-sectrustgettrustresult.

EXC_BAD_ACCESS for arrays in Xcode function

I have this function
func pickAttraction(attractionType: Array<Attraction>) -> Attraction {
let randAttr = attractionType[5]
if favoritesNames.contains(randAttr.attractionName) {
return pickAttraction(attractionType: attractionType)
} else {
return randAttr
}
}
and my program crashes (sometimes) on the line starting with "if favoritesNames". On the last time it crashed, the array favoritesNames had 1 string inside, and randAttr.attractionName had a different string. I expected it to return randAttr, but it crashed instead. Does anyone have any idea why?
I also tried
if favoritesNames.contains(randAttr.attractionName) || favoritesNames[0] == randAttr.attractionName {
and I got the same error
I've also tried
func pickAttraction(from attractions: [Attraction]) -> Attraction? {
attractions.filter { !favoritesNames.contains($0.attractionName) }
.randomElement()
}
instead of the other function and I still get the same error
Thank you
I believe let randAttr = attractionType[5] is accessing an index that doesn't exist. Can you verify that there is available data if you access the array at [5]?

Eureka Forms Hide validation errors based on SegmentedRow

I am unable to hide the validation errors based on the value of each SegmentedRow (upon switching).
Edit: Eureka version 4.0.1
What I have tried: Switching over the val and comparing to each ImportSelectionType
I can hide them for an individual SegmentedRow value: code below.
$0.hidden = Condition.function(["segment"], { form in
if let val = form.rowBy(tag: "segment")?.baseValue as? String {
// TODO: make it work in all cases
return val != ImportSelectionType.keystore.title
}
return false
})
How could I make this generic so it will work in all cases?
Edit: ImportSelectionType is declared like so.
enum ImportSelectionType {
case keystore
case privateKey
case mnemonic
case watch
var title: String {
switch self {
case .keystore:
return "Keystore"
case .privateKey:
return "Private Key"
case .mnemonic:
return "Mnemonic"
case .watch:
return "Watch"
}
}
init(title: String?) {
switch title {
case ImportSelectionType.privateKey.title?:
self = .privateKey
case ImportSelectionType.watch.title?:
self = .watch
case ImportSelectionType.mnemonic.title?:
self = .mnemonic
default:
self = .keystore
}
}
}
It seems updating to Eureka 4.1.1 solved the issue.

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

Resources