gpt4 book ai didi

ios - 如何在 iOS 中向/从 UIPasteboard 写入和读取字符串值?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:48:40 24 4
gpt4 key购买 nike

我有以下测试,失败

NSString * expectedValue = @"achilles";

UIPasteboard *pasteboard = [UIPasteboard pasteboardWithName:@"pb1" create:YES];
pasteboard.persistent = YES;

pasteboard.string = expectedValue;
STAssertEqualObjects(expectedValue, [pasteboard string], @"get written value from pasteboard");

[pasteboard setString:expectedValue];
STAssertEqualObjects(expectedValue, [pasteboard string], @"get written value from pasteboard");

两个断言都失败了,

'achilles' should be equal to '(null)'

我是在错误地写入粘贴板、从粘贴板读取,还是两者都有错误?

最佳答案

我假设问题如下:
UIPasteboardstring 属性定义为 ( see the docs )

@property(nonatomic, copy) NSString *string;  

这意味着如果您为其分配一个字符串,它将被复制,即创建一个新对象。当您读回并将其与原始对象进行比较时,比较一定会失败。

关于ios - 如何在 iOS 中向/从 UIPasteboard 写入和读取字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12437412/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com