Created
April 26, 2016 11:28
-
-
Save vlastachu/a34aa547c203ad04c8d5611b6b46f5a5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//... | |
// change instance property setter to custom at runtime | |
let type = self.view.superview!.superview!.superview!.dynamicType | |
if String.fromCString(class_getName(type)) != "runtimeUIView" { | |
let newtype = objc_allocateClassPair(type, "runtimeUIView", 0) | |
let imp = class_getMethodImplementation(ViewController.self, #selector(ViewController.fakeFrameSetter(_:))) | |
let types = method_getTypeEncoding(class_getInstanceMethod(ViewController.self, #selector(ViewController.fakeFrameSetter(_:)))) | |
class_addMethod(newtype, Selector("setFrame:"), imp, types) | |
object_setClass(self.view.superview!.superview!.superview!, newtype) | |
} | |
public func fakeFrameSetter(value: CGRect) { | |
// should do nothing but print is useful for debug | |
print("don't fucking touch my frame, you piece of cunt!") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// change class property setter to custom at runtime | |
let imp = class_getMethodImplementation(ViewController.self, #selector(ViewController.fakeFrameSetter(_:))) | |
let type = self.view.superview!.superview!.superview!.dynamicType | |
var uselessVariable:UInt32 = 0 | |
withUnsafeMutablePointer(&uselessVariable) { ptr in | |
var methods: UnsafeMutablePointer<Method> = class_copyMethodList(type, ptr) | |
for _ in 0 ... (ptr.memory) { | |
let m: Method = methods.memory | |
if method_getName(m) == Selector("setFrame:") { | |
method_setImplementation(m, imp) | |
} | |
methods = methods.advancedBy(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment