Is it possible to Swizzle NSAttributedString.init(string:attributes)?

112 Views Asked by At

I am trying to swizzle NSAttributedString but getting a compile error:

extension NSAttribtuedString {

   @objc convenience init(swizzledString: String, attributes: [NSAttributedString.Key : Any?] {
       .....
   }
}

Error

Method cannot be marked @objc because type of parameter 2 cannot be represented in Objective C

The error makes sense. Any way we can solve this to keep the function signature and swizzle the init function?

1

There are 1 best solutions below

0
Jiri Volejnik On

You get the error, because swift's dictionary type does not exist in objective-c. You would have to use NSDictionary:

@objc convenience init(swizzledString:String, attributes:NSDictionary)