简体   繁体   中英

Property attributes 'nonnull' and 'weak' are mutually exclusive

Recently I upgraded my Xcode to version 7 - XCode 7.0. Now I am getting this message to every IBOutlet of mine:

@property (nonatomic, weak, nonnull) IBOutlet UITableView *tableView;

Property attributes 'nonnull' and 'weak' are mutually exclusive

Whant can I do?

The whole point of weak is that the property becomes nil when the object is deallocated. The whole point of nonnull is that the property can never be nil . That's why you can't apply both.

Either make your property strong nonnull or just weak .

For completeness, I thought I should add a second answer here. Pedantically, weak and nonnull are not truly mutually exclusive if a property has custom getters and setters. For example:

@property(...) Foo *foo;

- (Foo *)foo {
  if (_foo) return _foo;
  return [Foo sharedInstance];
}

- (void)setFoo:(Foo *)newFoo {
  assert(newFoo);
  _foo = newFoo;
}

But there's also no good reason to allow this, because there's no good reason to not allow setting the variable to nil to reset it to the default value. And when you do that, you specify the null_resettable attribute.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM