【发布时间】:2022-01-12 06:17:03
【问题描述】:
我不是 iOS 开发者,而是选择目标 c 的 rn 开发者。
我有一个 NSdictionry,看起来像这样
NSDictionary *selfInfo = @{
@"id": selfPartcipant.id,
@"name": selfPartcipant.name,
@"picture": selfPartcipant.picture,
@"audioEnabled": @(selfPartcipant.audioEnabled),
@"videoEnabled": @(selfPartcipant.videoEnabled),
@"isPinned": @(selfPartcipant.isPinned)
};
在这里,selfPartcipant.name 或 selfPartcipant.picture 可以为 nil(这会导致代码中断)。当值为 nil 时,我想放空字符串。
javascript中的等价物应该是这样的
const a = {
name: selfPartcipant.name || '',
picture: selfPartcipant.picture || '',
...other properties
}
我怎样才能做到这一点?
【问题讨论】:
标签: ios objective-c react-native