Implementing copy() in Swift

前端 未结 10 1479
难免孤独
难免孤独 2020-11-27 15:31

I want to be able to copy a custom class in Swift. So far, so good. In Objective-C I just had to implement the NSCopying protocol, which means implementing

10条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 16:36

    Only if you are using ObjectMapper library : do like this

    let groupOriginal = Group(name:"Abc",type:"Public")    
    let groupCopy = Mapper().mapAny(group.toJSON())! //where Group is Mapable
    

提交回复
热议问题