我有一个应用程序,从他们的联系人列表中选择一个人,并采取他们的名字,姓氏和电子邮件.然后它将名字保存到nsmutablearray并将其放入uitableview单元格中.一旦在模拟器中选择了联系人,我的问题就出现了.
码:
.H:
#import <UIKit/UIKit.h>
#import <AddressBookUI/AddressBookUI.h>
@interface FirstViewController : UIViewController < ABPeoplePickerNavigationControllerDelegate, UITableViewDelegate, UITableViewDataSource>
- (IBAction)showPicker:(id)sender;
@property (weak, nonatomic) IBOutlet NSString *firstName;
@property (weak, nonatomic) IBOutlet NSString *email;
@property (weak, nonatomic) IBOutlet NSString *lastName;
@property (weak, nonatomic) IBOutlet UITableView *myTableView;
@property (strong, nonatomic) NSMutableArray *contacts;
@end
Run Code Online (Sandbox Code Playgroud)
.M:
#import "FirstViewController.h"
@interface FirstViewController ()
@end
@implementation FirstViewController
@synthesize firstName;
@synthesize email;
@synthesize lastName;
@synthesize contacts;
@synthesize myTableView;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, …Run Code Online (Sandbox Code Playgroud) 有没有办法在编译时执行以下操作?
int anInteger = 0;
__if_object(anInteger) {
// send object some messages
}
__if_primitive(anInteger) {
// do something else
}
Run Code Online (Sandbox Code Playgroud)
可以使用的虚拟情况是在下面定义__add_macro.
#define __add_macro(var, val) __something_goes_here__
int i = 1;
MyInteger* num = [[MyNumber alloc] initWithValue:1]
__add_macro(i, 4);
__add_macro(num, 4);
// both should now hold 5
Run Code Online (Sandbox Code Playgroud)
澄清/简
我想用一个宏没办法做到这一点.但是我仍然需要它来警告宏是否在错误的数据类型上使用.这两种类型是:object和non-object).
要检查它是否是一个对象,这有效:
#define __warn_if_not_object(var) if(0){[(var) class];}
Run Code Online (Sandbox Code Playgroud)
我需要的:
#define _warn_if_object(var) if(0){__something_here__}
Run Code Online (Sandbox Code Playgroud)
同样,我需要在编译时发生这种情况.它可以抛出错误或警告.
谢谢