search

Home  >  Q&A  >  body text

objective-c - @property (nonatomic, copy) void(^doTransferMsg)(NSString *_msg)

不是很明白
@property (nonatomic, copy) void(^doTransferMsg)(NSString *_msg)

这种声明属性方式。只知道void(^doTransferMsg)这是使用block方式声明方法。

大家讲道理大家讲道理2864 days ago690

reply all(2)I'll reply

  • 天蓬老师

    天蓬老师2017-04-21 11:17:54

    Maybe it’s easier to understand this way
    .h

    typedef void(^doTransferMsg)(NSString *_msg);
    @property (nonatomic, copy) doTransferMsg transferMsg;

    .m

    @synthesize transferMsg;
    [self setTransferMsg:^(NSString *str)
    {
      NSLog(@"hello %@",str);
    }];
    transferMsg(@"navy");
    transferMsg(@"navy2");

    reply
    0
  • PHP中文网

    PHP中文网2017-04-21 11:17:54

    You will understand if you think of block as a common type. There is no difference between block and common types here. They just define an attribute of this type.

    reply
    0
  • Cancelreply