After updating my XCode, I get a Strideable error - ios

So, I recently updated my MacOS to Catalina and installed XCode 11.5. Before that I had High Sierra and the maximum version of XCode that High Sierra supports (don't remember the version number).
So, an app I had built on that combo worked fine in XCode, but now after the update when I open I cannot run the app, because I get a Strideable error. I have the following code in one of my controllers which worked fine before this:
extension Date : Strideable {
public func advanced(by n: Int) -> Date {
return Calendar.current.date(byAdding: .day, value: n, to: self) ?? self
}
public func distance(to other: Date) -> Int {
return Calendar.current.dateComponents([.day], from: other, to: self).day ?? 0
}
}
I basically use this for a calendar I am implementing inside the app.
So, now when I try to run the app I get these two errors:
Protocol 'Strideable' requires 'advanced(by:)' to be available in iOS 11.0.0 and newer
Protocol 'Strideable' requires 'distance(to:)' to be available in iOS 11.0.0 and newer
As you can see I have both these functions implemented.
Inside my app's Deployment Info I have iOS 11.0 as minimum requirement for the app.
Besides, the current version of the app is published on the App Store and working fine. What can be the issue here?

Ok, I am not sure why, but apparently at some point there was an update for Strideable, so the only thing I had to do was delete my Strideable extension.
Once I did that, the app worked without any issues.

Related

iOS app crashes with Symbol Not Found HKVerifiableClinicalRecordQuery in xcode 13.3

I have an app that runs fine on iPhone iOS 15 but crashes on simulator iOS 13. The
call to HKVerifiableClinicalRecordQuery is wrapped in a #available block but the library tries to be uploaded at launch time:
Referenced from: /Users/johndoe/Library/Developer/Xcode/DerivedData/appHere-ebozeeuyrbpizofrvpxydtfbydkf/Build/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework
Expected in: /System/Library/Frameworks/HealthKit.framework/HealthKit
in /Users/johndoe/Library/Developer/Xcode/DerivedData/appHere-ebozeeuyrbpizofrvpxydtfbydkf/Build/Products/Debug-iphonesimulator/MyFramework.framework/MyFramework
This is very similar but kind of old now: https://developer.apple.com/forums/thread/12110
All entitlements seem right as the same app without changes work fine in xcode 13.1 + iOS 13.
Apple release notes don't show anything special with HK so I wonder what could this be.
The snippet of code where the call is done is this:
func requestVerifiableHealthRecords() {
if #available(iOS 15, *) {
let healthStore = HKHealthStore()
let credentialTypes = ["https://smarthealth.cards#immunization"]
let dateInterval = DateInterval(start: .distantPast, end: .now)
let predicate = HKQuery.predicateForVerifiableClinicalRecords(withRelevantDateWithin: dateInterval)
let query = HKVerifiableClinicalRecordQuery(recordTypes: credentialTypes, predicate: predicate) {
// some code here
}
healthStore.execute(query)
}
}
But as I mentioned above, crash happens at launch time, this piece of code is never even close to being executed. The simulator shows the splash screen and nothing more. Debug navigator shows start then __abort_with_payload.
The concerning line is this one:
Expected in: /System/Library/Frameworks/HealthKit.framework/HealthKit
Why is even looking for a framework in MacOS, in any case, it should be looking it in xCode bundle and it shouldn't fail/crash.
I think the error is misleading, it must be something else but I still can't figure it out.
Found the issue for this one. Hopefully can help anyone with similar crash.
Select your crashing target
Select Build Phases tab
Expand Link Binary With Libraries and change Embed setting to be Optional for the offending framework. In this case HealthKit framework
Build again and crash should've been gone now.

Xcode 11 "'==' is only available in iOS 13.0 or newer" error

I tried to build my project in Xcode 11 and it throws 26 identical errors
<unknown>:0: error: '==' is only available in iOS 13.0 or newer
The errors happen on Compile Swift source files stage upon calling CompileSwift normal arm64 /long/path/to/MyClass.swift .... There is no context help pointing to anything within the files. The files are quite different but look harmless and does not share anything in common.
After a lot of pain, I found the 4-month old app version compiles fine. So I did git bisect and found the offending commit, and then this code:
struct Config: Equatable {
let formatDescription: CMFormatDescription
let orientation: CGImagePropertyOrientation
}
Turns out CMFormatDescription did become Equatable only in iOS 13, while the app deployment target is iOS 11. It probably felt back to [NSObject isEqual:] in Xcode 10, but it became complicated in Xcode 11. Since Swift automatically generates Equatable conformance under the hood it had troubles in pointing the exact place of the error. The solution is to add your own Equatable implementation for CMFormatDescription:
extension CMFormatDescription: Equatable {
public static func == (lhs: CMFormatDescription, rhs: CMFormatDescription) -> Bool {
return CMFormatDescriptionEqual(lhs, otherFormatDescription: rhs)
}
}

ARSessionConfiguration unresolved in Xcode 9 GM

I have created an ARKit project using a beta version of Xcode 9, which I was able to run on my real device without issues.
Yesterday, I upgraded to Xcode 9 GM, and without touching anything, Xcode shows multiple errors, saying it does not know ARSessionConfiguration i.e.:
Use of undeclared type 'ARSessionConfiguration'
and:
Use of undeclared type 'ARWorldTrackingSessionConfiguration'
...for this code:
let session = ARSession()
var sessionConfig: ARSessionConfiguration = ARWorldTrackingSessionConfiguration()
I have imported ARKit and am using the ARSCNViewDelegate in my ViewController.
When opening the project from the beta version of Xcode, it does not show the errors and I can again run the app on my phone.
Any idea how I can fix this?
ARWorldTrackingSessionConfiguration has been deprecated and renamed to ARWorldTrackingConfiguration: See here
Also, ARSessionConfiguration has been deprecated and renamed to ARConfiguration, which is now an abstract base class.
Use AROrientationTrackingConfiguration when you don't want world tracking, instead of using a generic ARConfiguration. Thus:
let configuration = AROrientationTrackingConfiguration()
You can also check if world tracking is supported on a device:
if ARWorldTrackingConfiguration.isSupported {
configuration = ARWorldTrackingConfiguration()
}
else {
configuration = AROrientationTrackingConfiguration()
}
In Xcode 9 GM, looks like ARWorldTrackingSessionConfiguration has been renamed to ARWorldTrackingConfiguration:
https://developer.apple.com/documentation/arkit/arworldtrackingconfiguration
Reference to this change:
https://github.com/markdaws/arkit-by-example/issues/7
ARSessionConfiguration has been renamed to ARConfiguration:
https://developer.apple.com/documentation/arkit/arconfiguration

NSAttributedStringKey.attachment versus NSAttachmentAttributeName

I'm having problems with NSAttributedStringKey.attachment versus NSAttachmentAttributeName. Here's the relevant code:
var key: Any?
if #available(iOS 11, *) {
key = NSAttributedStringKey.attachment
}
else {
key = NSAttachmentAttributeName
}
One of two things are happening. In the actual place where I'm trying to use this code (a Cococapod of my own design, with a deployment target of iOS 8 and now building with Xcode 9), I get an error:
Type 'NSAttributedStringKey' (aka 'NSString') has no member 'attachment'
Or, if I just make a new example project and set the deployment target at iOS 8, I get:
'NSAttachmentAttributeName' has been renamed to 'NSAttributedStringKey.attachment'
This is not the behavior I'd expect with #available. Thoughts?
This String vs struct difference is between Swift 3 (uses Strings such as NSAttachmentAttributeName) and Swift 4 (uses struct static attributes such as NSAttributedStringKey.attachment), not between iOS <11 and iOS >=11. For instance, you can use NSAttributedStringKey.attachment and similar in any supporting version of iOS (e.g. .attachment is available since iOS 7) within a Swift 4 project. #available doesn't apply because it's a Swift language version difference rather than an OS version difference.
Ensure your pod is set to the correct Swift version and it should then work as expected. You can tell CocoaPods that by adding a .swift-version file at the top of your project:
$ echo 4.0 >.swift-version
This magical version file is mentioned in passing in a CocoaPods blog post from last year: http://blog.cocoapods.org/CocoaPods-1.1.0/

UIView/UICoordinateSpace convert rect/point clash in swift 3

So I've recently had to convert my project to Swift 3, and while a bit of a pain, it has mostly gone ok. However I am now down to one final set of errors that I can't work out!
Im using
self.convert(point, to: v)
to convert a point between views, but Xcode keeps giving me build errors saying that
'convert(_:to:)' is only available on iOS 8.0 or newer
This seems to be due to the method definition
public protocol UICoordinateSpace : NSObjectProtocol {
#available(iOS 8.0, *)
public func convert(_ point: CGPoint, to coordinateSpace: UICoordinateSpace) -> CGPoint
...
}
clashing with the normal UIView one
extension UIView {
...
open func convert(_ point: CGPoint, to view: UIView?) -> CGPoint
...
}
I can't for the life of me work out how to resolve this! Has anyone come across this or have any idea how to fix it?!
You can manually set the iOS Deployment Target to 7.0, and Xcode builds the app as targeted to 7.0. (I don't know apps built with that manner can be approved for App Store.)
So, you can test that behaviour with your Xcode 8.
And you can silence Xcode with this:
self.convert(point, to: v as UIView?)
With new renaming rule of Swift 3, some imported methods may have the same signature in Swift, and I'm afraid some of them may not have this sort of workaround, and may not be solved by changing target version.
Ok, if anyone else has this issue, turns out it's because pre-iOS 8 is no longer supported. If you update your project to recommended settings, it will set your minimum iOS version to 8 and everything will be happy :)

Resources