Storing NSArray in UIPasteboard

后端 未结 2 1214
小鲜肉
小鲜肉 2021-01-13 08:45

I have several text files which I want to transfer between 2 Apps. (ie. free and paid versions of the same App).

I\'m using UIPasteboard to do this. The contents of

2条回答
  •  庸人自扰
    2021-01-13 09:32

    As of iOS 8.3, UIPasteboard still has this bug. I wrote an extension for UIPasteboard to handle this:

    extension UIPasteboard {
        func arrayForPasteboardType(pasteboardType: String) -> NSArray? {
            switch valueForPasteboardType(pasteboardType) {
            case let array as NSArray:
                return array
            case let data as NSData:
                if let array = NSPropertyListSerialization.propertyListWithData(data, options: 0, format: nil, error: nil) as? NSArray {
                    return array
                }
            default:
                break
            }
    
            return nil
        }
    }
    

提交回复
热议问题