Skip to content

Commit 20aebf5

Browse files
Refactoring
1 parent 34d952d commit 20aebf5

File tree

24 files changed

+244
-626
lines changed

24 files changed

+244
-626
lines changed

dub.sdl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ toolchainRequirements gdc="no"
99

1010
targetPath "out/"
1111

12+
dependency "numem" version=">=1.0.1"
13+
1214
# Default configuration.
1315
configuration "static" {
1416
platforms "osx" "ios" "tvos" "watchos" "visionos"

source/foundation/nsarray.d

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,24 @@
1111
*/
1212
module foundation.nsarray;
1313
import foundation;
14-
import objc.utils;
1514
import objc;
1615

1716
import core.attribute : selector, optional;
17+
import numem.core.exception;
1818

1919
private alias iter_func(T) = int delegate(T);
2020
private alias iter_i_func(T) = int delegate(size_t, T);
2121

22+
private
23+
int iter_func_t(T)(T item, scope iter_func!T dg) @nogc {
24+
return assumeNoThrowNoGC(dg, item);
25+
}
26+
27+
private
28+
int iter_i_func_t(T)(size_t idx, T item, scope iter_i_func!T dg) @nogc {
29+
return assumeNoThrowNoGC(dg, idx, item);
30+
}
31+
2232
nothrow @nogc:
2333
version(D_ObjectiveC):
2434

@@ -58,7 +68,7 @@ public:
5868
extern(D)
5969
final // @suppress(dscanner.useless.final)
6070
static NSArray!T create(T[] objects) {
61-
return typeof(this).create(objects.ptr, objects.length);
71+
return NSArray!T.create(objects.ptr, objects.length);
6272
}
6373

6474
/**
@@ -165,10 +175,8 @@ public:
165175
extern(D)
166176
final
167177
int opApply(scope iter_func!T dg) {
168-
auto ngc_dg = assumeNothrowNoGC!(iter_func!T)(dg);
169-
170178
foreach (i; 0..length) {
171-
int result = ngc_dg(this[i]);
179+
int result = iter_func_t!T(this[i], dg);
172180
if (result)
173181
return result;
174182
}
@@ -181,9 +189,8 @@ public:
181189
extern(D)
182190
final
183191
int opApplyReverse(scope iter_func!T dg) {
184-
auto ngc_dg = assumeNothrowNoGC!(iter_func!T)(dg);
185192
foreach (i; 0..length) {
186-
int result = ngc_dg(this[i]);
193+
int result = iter_func_t!T(this[i], dg);
187194
if (result)
188195
return result;
189196
}
@@ -196,9 +203,8 @@ public:
196203
extern(D)
197204
final
198205
int opApply(scope iter_i_func!T dg) {
199-
auto ngc_dg = assumeNothrowNoGC!(iter_i_func!T)(dg);
200206
foreach (i; 0..length) {
201-
int result = ngc_dg(i, this[i]);
207+
int result = iter_i_func_t!T(i, this[i], dg);
202208
if (result)
203209
return result;
204210
}
@@ -211,9 +217,8 @@ public:
211217
extern(D)
212218
final
213219
int opApplyReverse(scope iter_i_func!T dg) {
214-
auto ngc_dg = assumeNothrowNoGC!(iter_i_func!T)(dg);
215220
foreach (i; 0..length) {
216-
int result = ngc_dg(i, this[i]);
221+
int result = iter_i_func_t!T(i, this[i], dg);
217222
if (result)
218223
return result;
219224
}

source/foundation/nsbundle.d

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/*
2-
Copyright © 2024, Kitsunebi Games EMV
3-
Distributed under the Boost Software License, Version 1.0,
4-
see LICENSE file.
5-
6-
Authors: Luna Nielsen
7-
*/
8-
91
/**
10-
Bindings to NSBundle
2+
NSBundle
3+
4+
Copyright: Copyright © 2024-2025, Kitsunebi Games EMV
5+
License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
Authors: Luna Nielsen
117
*/
128
module foundation.nsbundle;
139
import foundation;
@@ -83,6 +79,11 @@ public:
8379
*/
8480
@property static NSBundle fromPath(NSString url) @selector("bundleWithPath:");
8581

82+
/**
83+
Returns the NSBundle instance that has the specified bundle identifier.
84+
*/
85+
@property static NSBundle fromID(NSString id) @selector("bundleWithIdentifier:");
86+
8687
/**
8788
The load status of a bundle.
8889
*/

source/foundation/nscoder.d

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/*
2-
Copyright © 2024, Kitsunebi Games EMV
3-
Distributed under the Boost Software License, Version 1.0,
4-
see LICENSE file.
5-
6-
Authors: Luna Nielsen
7-
*/
8-
91
/**
10-
Bindings to NSObject and NSObjectProtocol
2+
NSCoder
3+
4+
Copyright: Copyright © 2024-2025, Kitsunebi Games EMV
5+
License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
Authors: Luna Nielsen
117
*/
128
module foundation.nscoder;
139
import foundation;

source/foundation/nsdictionary.d

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/*
2-
Copyright © 2024, Kitsunebi Games EMV
3-
Distributed under the Boost Software License, Version 1.0,
4-
see LICENSE file.
5-
6-
Authors: Luna Nielsen
7-
*/
8-
91
/**
10-
Bindings to NSDictionary
2+
NSDictionary
3+
4+
Copyright: Copyright © 2024-2025, Kitsunebi Games EMV
5+
License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
Authors: Luna Nielsen
117
*/
128
module foundation.nsdictionary;
139
import foundation;

source/foundation/nsenumerator.d

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/*
2-
Copyright © 2024, Kitsunebi Games EMV
3-
Distributed under the Boost Software License, Version 1.0,
4-
see LICENSE file.
5-
6-
Authors: Luna Nielsen
7-
*/
8-
91
/**
10-
Bindings to NSEnumerator
2+
NSEnumerator
3+
4+
Copyright: Copyright © 2024-2025, Kitsunebi Games EMV
5+
License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
Authors: Luna Nielsen
117
*/
128
module foundation.nsenumerator;
139
import foundation;

source/foundation/nserror.d

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/*
2-
Copyright © 2024, Kitsunebi Games EMV
3-
Distributed under the Boost Software License, Version 1.0,
4-
see LICENSE file.
5-
6-
Authors: Luna Nielsen
7-
*/
8-
91
/**
10-
Bindings to NSError
2+
NSError
3+
4+
Copyright: Copyright © 2024-2025, Kitsunebi Games EMV
5+
License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
Authors: Luna Nielsen
117
*/
128
module foundation.nserror;
139
import foundation;

source/foundation/nsobject.d

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/*
2-
Copyright © 2024, Kitsunebi Games EMV
3-
Distributed under the Boost Software License, Version 1.0,
4-
see LICENSE file.
5-
6-
Authors: Luna Nielsen
7-
*/
8-
91
/**
10-
Bindings to NSObject
2+
NSObject
3+
4+
Copyright: Copyright © 2024-2025, Kitsunebi Games EMV
5+
License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
Authors: Luna Nielsen
117
*/
128
module foundation.nsobject;
139
import foundation;
@@ -24,17 +20,23 @@ version(D_ObjectiveC):
2420
extern(Objective-C)
2521
extern class NSObject : NSObjectProtocol {
2622
@nogc nothrow:
27-
public:
28-
23+
protected:
24+
2925
/**
30-
Returns the class object for the receiver’s class.
31-
*/
32-
static Class class_() @selector("class");
26+
Gets a pointer to the given ivar in the object.
3327
34-
/**
35-
Returns the class object for the receiver’s superclass.
28+
Params:
29+
name = Name of the ivar to get.
30+
31+
Returns:
32+
A pointer to said ivar or $(D null)
33+
if an ivar with that name does not exist.
3634
*/
37-
static Class superclass() @selector("superclass");
35+
extern(D)
36+
T getVariable(T)(const(char)* name) {
37+
return self.getVariable!T(name);
38+
}
39+
public:
3840

3941
/**
4042
Returns a Boolean value that indicates whether the receiving
@@ -253,24 +255,27 @@ string classname(T)(T obj) if(is(T : NSObjectProtocol)) {
253255
/**
254256
Retains a single reference for `value` and returns it.
255257
*/
256-
auto ref inout(T) retained(T)(auto ref inout(T) value) if (isObjcClassInstance!T) {
257-
(cast(T)value).retain();
258+
auto retained(T)(auto ref inout(T) value) if (isObjcClassInstance!T) {
259+
if (value !is null)
260+
(cast(T)value).retain();
258261
return value;
259262
}
260263

261264
/**
262265
Releases a single reference for `value` and returns it.
263266
*/
264-
auto ref inout(T) released(T)(auto ref inout(T) value) if (isObjcClassInstance!T) {
265-
(cast(T)value).release();
267+
auto released(T)(auto ref inout(T) value) if (isObjcClassInstance!T) {
268+
if (value !is null)
269+
(cast(T)value).release();
266270
return value;
267271
}
268272

269273
/**
270274
Queues `value` up for an auto-release and returns it.
271275
*/
272-
auto ref inout(T) autoreleased(T)(auto ref inout(T) value) if (isObjcClassInstance!T) {
273-
(cast(T)value).autorelease();
276+
auto autoreleased(T)(auto ref inout(T) value) if (isObjcClassInstance!T) {
277+
if (value !is null)
278+
(cast(T)value).autorelease();
274279
return value;
275280
}
276281

source/foundation/nsproto.d

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/*
2-
Copyright © 2024, Kitsunebi Games EMV
3-
Distributed under the Boost Software License, Version 1.0,
4-
see LICENSE file.
5-
6-
Authors: Luna Nielsen
7-
*/
8-
91
/**
10-
Bindings to NSObjectProtocol
2+
NSObject (Protocol)
3+
4+
Copyright: Copyright © 2024-2025, Kitsunebi Games EMV
5+
License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
Authors: Luna Nielsen
117
*/
128
module foundation.nsproto;
139
import foundation;

source/foundation/nsset.d

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/*
2-
Copyright © 2024, Kitsunebi Games EMV
3-
Distributed under the Boost Software License, Version 1.0,
4-
see LICENSE file.
5-
6-
Authors: Luna Nielsen
7-
*/
8-
91
/**
10-
Bindings to NSSet
2+
NSSet
3+
4+
Copyright: Copyright © 2024-2025, Kitsunebi Games EMV
5+
License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
6+
Authors: Luna Nielsen
117
*/
128
module foundation.nsset;
139
import foundation;

0 commit comments

Comments
 (0)