Last active
August 29, 2015 14:18
-
-
Save jonathanpeppers/8a7df676fc473135f4e8 to your computer and use it in GitHub Desktop.
NSObject in C#
This file contains hidden or 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
public class NSObject | |
{ | |
private IntPtr _handle; | |
public NSObject() | |
{ | |
IntPtr classHandle = Class.GetHandle("NSObject"); | |
var alloc = new Selector("alloc"); | |
var init = new Selector("init"); | |
_handle = Messaging.IntPtr_objc_msgSend(classHandle, alloc.Handle); | |
_handle = Messaging.IntPtr_objc_msgSend(_handle, init.Handle); | |
} | |
~NSObject() | |
{ | |
Dispose(); | |
} | |
public void MakeItRain(string currency) | |
{ | |
var selector = new Selector("makeItRain:"); | |
var currencyString = new NSString(currency); | |
Messaging.void_objc_msgSend_IntPtr(_handle, selector.Handle, currencyString.Handle); | |
currencyString.Dispose(); | |
} | |
public void Dispose() | |
{ | |
GC.SuppressFinalize(this); | |
var release = new Selector("release"); | |
Messaging.void_objc_msgSend(_handle, release.Handle); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment