conform

Class-Only Protocols in Swift

孤街醉人 提交于 2019-12-20 11:03:30
问题 I want some of my classes (not all) to conform using 'Class-Only Protocols' from docs. What I am doing is protocol RefreshData: class, ClassA, ClassB { func updateController() } and I am getting the errors non class type 'RefreshData cannot inherit from classA non class type 'RefreshData cannot inherit from classB I'm not sure I am following exactly as in the docs. Does anyone have any ideas about this? 回答1: Swift 4 allows you to combine types, so you can have your protocol and then create,

How to create an object depending on a String in Swift?

三世轮回 提交于 2019-12-10 05:02:23
问题 Here is my code what I would like to refactor: let myCell = MyCustomTableViewCell() self.createCell(myCell, reuseIdentifierString: "myCellIdentifier") the MyCustomTableViewCell conforms to the SetCell protocol so it works fine. and the SetCell protocol is not an @obj_c protocol. This is a swift protocol private func createCell<T where T:SetCell>(classType: T, reuseIdentifierString: String) -> UITableViewCell { var cell = _tableView.dequeueReusableCellWithIdentifier(reuseIdentifierString) as T

Extend/Modify NHibernate classes at runtime

二次信任 提交于 2019-12-05 13:32:52
Apologies if there's an on point answer already out there but I haven't found it. I'm using NH3 and I've got a use case where I want to add a Set onto any entity who's class implements a specific interface. I have a configuration builder class so I can make these changes before creating the session factory. Given this reduced example: public class Person : IHasExtraItems { public Person() { this.ExtraItems = new HashSet<ExtraItem>(); } public virtual Guid Id { get; set; } public virtual string Name { get; set; } public virtual DateTime Birthdate { get; set; } public virtual ICollection