Skip to content

Instantly share code, notes, and snippets.

@klundberg
Last active November 19, 2016 04:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save klundberg/cb6d5205feb180c37345 to your computer and use it in GitHub Desktop.
Save klundberg/cb6d5205feb180c37345 to your computer and use it in GitHub Desktop.
import UIKit
class ViewController: UIViewController {
// error: 'UISearchController' is only available on iOS 8.0 or newer
var searchController: UISearchController?
// error: Stored properties cannot be marked potentially unavailable with 'introduced='
@available(iOS 8.0, *)
var conditionallyAvailableSearchController: UISearchController?
// Workaround that works
private var _searchController: UIViewController?
@available(iOS 8.0, *)
private var workingSearchController: UISearchController? {
get {
return _searchController as? UISearchController
}
set {
_searchController = newValue
}
}
}
@klundberg
Copy link
Author

Can't mark the class as @available(iOS 8.0, *) since the class i'm encountering this in needs to work on iOS 7 too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment