Reputation: 1529
Strange issue, I am using the standard check to see if the device has 3D Touch. It is wrapped with iOS9 check, which is passing, but not passing the .Available
if statement
on my iPhone 6S, which is running iOS9.1 and has 3D Touch enabled in Settings.
if #available(iOS 9.0, *) {
if traitCollection.forceTouchCapability == .Available {
registerForPreviewingWithDelegate(self, sourceView: view)
constantChange = cstInfoBar.constant + 20
}
}
I have set a breakpoint and I am receiving the following:
(lldb) po traitCollection.forceTouchCapability
error: <EXPR>:1:17: error: 'forceTouchCapability' is only available on iOS 9.0 or newer
traitCollection.forceTouchCapability
^
<EXPR>:1:17: note: add 'if #available' version check
traitCollection.forceTouchCapability
^
<EXPR>:1:17: note: add @available attribute to enclosing instance method
traitCollection.forceTouchCapability
^
<EXPR>:1:17: note: add @available attribute to enclosing extension
traitCollection.forceTouchCapability
^
<EXPR>:9:9: warning: initialization of variable '$__lldb_error_result' was never used; consider replacing with assignment to '_' or removing it
var $__lldb_error_result = __lldb_tmp_error
~~~~^~~~~~~~~~~~~~~~~~~~
The registerForPreviewingWithDelegate(self, sourceView: view)
works outside of the if statement
but not a good option to implement!
FURTHER INVESTIGATIONS
I tested the code in my MainViewController and it worked perfectly. This is an odd situation, I have found a work around for the moment.
Upvotes: 2
Views: 583
Reputation: 337
I had the same problem: I was doing this check in viewDidLoad
, which is before the object has traitCollection
information. Deferring checks and logic until viewDidLayoutSubviews
worked for me.
Upvotes: 2