Universal application (iPad + iPhone), focused on older (iOS <4) devices - conditionally accepts a protocol?

I am writing a universal application that will work on both the iPad and iPhone. I also need it to target older devices (those that can't run 4.0), so 3.1 is mandatory.

I have already installed the base SDK in the latest available version (4.2), and Target for deployment is 3.1. I do a lot of runtime checks to call the appropriate methods only on the device / version I need.

One of the things I use on the iPad is the UISplitViewController. When assigning a delegate to splitViewController, the compiler generates a warning because the class interface does not explicitly use the UISplitViewControllerDelegate protocol, and I'm afraid that if I declare it to do so, the application will crash on older devices where there is no UISplitViewController / UISplitViewControllerDelegate.

What is the best way to suppress a compiler warning? Should I declare an empty UISplitViewControllerDelegate? If so, can I do this conditionally at runtime? Or should I just bring the appropriate class interface to the protocol and not worry about older devices?

Best

+3
3

C:

foo.delegate = (id<UISplitViewControllerDelegate>)self;
+1

, , , , . :

.h, @protocol. , - .h( #import <UIKit/UIKit.h>).

- , " ", , @protocol(MyProtocolName). ( ), , Objective-C .

, , , , . , , , .

, . - , , , , , iOS 3.1 4.2.

+1

, , 4.2.

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 40200
// code for iOS 4.2++
@interface PersonDetailViewController : UITableViewController <EditViewControllerDelegate, EditPickerViewControllerDelegate, UITextFieldDelegate, UIActionSheetDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIPrintInteractionControllerDelegate>{
#else
// code for iOS til 4.1
@interface PersonDetailViewController : UITableViewController <EditViewControllerDelegate, EditPickerViewControllerDelegate, UITextFieldDelegate, UIActionSheetDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate>{
#endif

... , InterfaceBuilder . ar IB.

, - ?

0

Source: https://habr.com/ru/post/1772784/