@@ -41,11 +41,11 @@ pub fn msgSendByName(comptime ReturnType: type, target: anytype, sel_name: [:0]c
41
41
return msgSend (ReturnType , target , selector , args );
42
42
}
43
43
44
- /// Convenience fn for sending an alloc message to a Class object followed by an init message to the returned Class instance
45
- pub fn allocAndInit ( class : Class ) ! id {
46
- const alloc_sel = try sel_getUid ( "alloc" );
47
- const init_sel = try sel_getUid ("init " );
48
- return msgSend (id , msgSend ( Class , class , alloc_sel , .{}), init_sel , .{});
44
+ /// Convenience fn for sending an new message to a Class object
45
+ /// Which is equivilent to sending an alloc message to a Class object followed by an init message to the returned Class instance
46
+ pub fn new ( class : Class ) ! id {
47
+ const new_sel = try sel_getUid ("new " );
48
+ return msgSend (id , class , new_sel , .{});
49
49
}
50
50
51
51
/// Convenience fn for sending a dealloc message to object
@@ -125,9 +125,9 @@ test {
125
125
testing .refAllDecls (@This ());
126
126
}
127
127
128
- test "alloc/init /dealloc NSObject" {
128
+ test "new /dealloc NSObject" {
129
129
const NSObject = try getClass ("NSObject" );
130
- const new_obj = try allocAndInit (NSObject );
130
+ const new_obj = try new (NSObject );
131
131
try dealloc (new_obj );
132
132
}
133
133
@@ -147,7 +147,7 @@ test "register/call/deregister Objective-C Class" {
147
147
},
148
148
);
149
149
150
- const instance = try allocAndInit (TestClass );
150
+ const instance = try new (TestClass );
151
151
152
152
try testing .expectEqual (
153
153
@as (c_int , 3 ),
0 commit comments