Skip to content
This repository was archived by the owner on May 18, 2022. It is now read-only.

Commit d9af0f7

Browse files
committed
replace allocAndInit with new
1 parent e6309e6 commit d9af0f7

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/main.zig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ pub fn msgSendByName(comptime ReturnType: type, target: anytype, sel_name: [:0]c
4141
return msgSend(ReturnType, target, selector, args);
4242
}
4343

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, .{});
4949
}
5050

5151
/// Convenience fn for sending a dealloc message to object
@@ -125,9 +125,9 @@ test {
125125
testing.refAllDecls(@This());
126126
}
127127

128-
test "alloc/init/dealloc NSObject" {
128+
test "new/dealloc NSObject" {
129129
const NSObject = try getClass("NSObject");
130-
const new_obj = try allocAndInit(NSObject);
130+
const new_obj = try new(NSObject);
131131
try dealloc(new_obj);
132132
}
133133

@@ -147,7 +147,7 @@ test "register/call/deregister Objective-C Class" {
147147
},
148148
);
149149

150-
const instance = try allocAndInit(TestClass);
150+
const instance = try new(TestClass);
151151

152152
try testing.expectEqual(
153153
@as(c_int, 3),

0 commit comments

Comments
 (0)