假设我有一个名为 Employee
的类
@interface Employee : NSObject
@property(nonatomic,strong) NSString *empImageURL;
@property(nonatomic,strong) NSString *empName;
@property(nonatomic,strong) NSString *empDOB;
@property(nonatomic,strong) NSString *empJobTitle;
@end
通过在 plist 中使用 maxcount
指定类型,我可以将图像/URL/字符串传递给 UIActivityViewController
类。
如何将 Employee 对象的实例传递给自定义操作扩展?
最佳答案
使用 NSCoding 将员工编码为 NSData 并发送。您必须实现 initWithCoder
和 encodeWithCoder
-(id)initWithCoder:(NSCoder*)coder {
if((self = [super init])) {
_empImageURL = [coder decodeObjectForKey:@"empImageURL"];
...
}
return self;
}
-(void)encodeWithCoder:(NSCoder*)coder {
[coder encodeObject:_empImageURL forKey:@"empImageURL"];
...
}
编码为数据:
data = [NSKeyedArchiver archivedDataWithRootObject:employee];
解码数据:
employee = [NSKeyedUnarchiver unarchiveObjectWithData:data];
有关使用 NSCoding 的更多详细信息,您可以查看此 tutorial .
关于ios - 如何将 NSData/除图像/URL 之外的任何信息传递到 iOS8 中的 Action Extensions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24645979/