Skip to content

Commit 2d3634a

Browse files
authored
Merge pull request #2246 from jacob-carlborg/objc_class_methods
Update the Objective-C documentation with support for class methods merged-on-behalf-of: Mike Franklin <[email protected]>
2 parents 6ed389c + 906fe11 commit 2d3634a

File tree

1 file changed

+11
-53
lines changed

1 file changed

+11
-53
lines changed

spec/objc_interface.dd

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ $(HEADERNAV_TOC)
66

77
$(P
88
D has limited support for interfacing with Objective-C. It supports
9-
external classes and calling instance methods. It is only available on
10-
OS X, compiling for 64bit.
9+
external classes and calling instance and class methods. It is only
10+
available on macOS, compiling for 64bit.
1111
)
1212

1313
$(P
@@ -191,7 +191,7 @@ $(HEADERNAV_TOC)
191191
where `<Framework>` is the name of the framework to link with, without
192192
the `.framework` extension. The two `-L` flags are required because the
193193
linker expects a space between the `-framework` flag and the name of
194-
the framework. DMD cannot handle this and will instead interpet the
194+
the framework. DMD cannot handle this and will instead interpret the
195195
name of the framework as a separate flag.
196196

197197
$(SECTION3 $(LNAME2 framework-paths, Framework Paths))
@@ -222,61 +222,32 @@ $(HEADERNAV_TOC)
222222

223223
$(SECTION2 $(LNAME2 usage-example, Full Usage Example))
224224

225-
$(P
226-
Since the only parts of Objective-C that is currently supported is
227-
calling instance methods, this example demonstrates how the Objective-C
228-
runtime can be used to achieve a running example.
229-
)
230-
231225
$(P
232226
This example will create an Objective-C string, `NSString`, and log the
233227
message using `NSLog` to stderr.
234228
)
235229

236-
---
237-
extern (Objective-C)
238-
interface Class
239-
{
240-
NSString alloc() @selector("alloc");
241-
}
242-
---
243-
244-
$(P
245-
This interface is used to emulate the $(LINK2 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/#//apple_ref/c/tdef/Class, `Class`)
246-
type available in the Objective-C runtime. The instance method `alloc`
247-
will be used to emulate a class method in `NSObject`,
248-
$(LINK2 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/#//apple_ref/occ/clm/NSObject/alloc, alloc).
249-
)
250-
251230
---
252231
extern (Objective-C)
253232
interface NSString
254233
{
234+
static NSString alloc() @selector("alloc");
255235
NSString initWithUTF8String(in char* str) @selector("initWithUTF8String:");
256236
void release() @selector("release");
257237
}
258238
---
259239

260240
$(P
261-
This is a simplified declaration of the $(LINK2 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/, `NSString`)
262-
class. The $(LINK2 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/#//apple_ref/occ/instm/NSString/initWithUTF8String:, `initWithUTF8String:`)
241+
This is a simplified declaration of the $(LINK2 https://developer.apple.com/documentation/foundation/nsstring?language=objc, `NSString`)
242+
class. The $(LINK2 https://developer.apple.com/documentation/objectivec/nsobject/1571958-alloc?language=objc, `alloc`)
243+
method allocates an instance of the class. The $(LINK2 https://developer.apple.com/documentation/foundation/nsstring/1412128-initwithutf8string?language=objc, `initWithUTF8String:`)
263244
method will be used to convert a C string in UTF-8 to an Objective-C
264-
string, `NSString`. The $(LINK2 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Protocols/NSObject_Protocol/index.html#//apple_ref/occ/intfm/NSObject/release, `release`)
245+
string, `NSString`. The $(LINK2 https://developer.apple.com/documentation/objectivec/1418956-nsobject/1571957-release?language=objc, `release`)
265246
method is used to release an deallocate the string. Since D doesn't
266247
support $(LINK2 https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html, ARC)
267248
it's needed to manually release Objective-C instances.
268249
)
269250

270-
---
271-
extern (C) Class objc_lookUpClass(in char* name)
272-
---
273-
274-
$(P
275-
The $(LINK2 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ObjCRuntimeRef/#//apple_ref/c/func/objc_lookUpClass, `objc_lookUpClass`)
276-
function is used to get the class definition of the class with the
277-
given name.
278-
)
279-
280251
---
281252
extern (C) void NSLog(NSString, ...);
282253
---
@@ -288,13 +259,7 @@ $(HEADERNAV_TOC)
288259
)
289260

290261
---
291-
auto cls = objc_lookUpClass("NSString");
292-
---
293-
294-
$(P Get the class definition of `NSString`.)
295-
296-
---
297-
auto str = cls.alloc();
262+
auto str = NSString.alloc();
298263
---
299264

300265
$(P Allocate an instance of the class, `NSString`.)
@@ -329,26 +294,19 @@ $(HEADERNAV_TOC)
329294
---
330295
module main;
331296

332-
extern (Objective-C)
333-
interface Class
334-
{
335-
NSString alloc() @selector("alloc");
336-
}
337-
338297
extern (Objective-C)
339298
interface NSString
340299
{
300+
static NSString alloc() @selector("alloc");
341301
NSString initWithUTF8String(in char* str) @selector("initWithUTF8String:");
342302
void release() @selector("release");
343303
}
344304

345305
extern (C) void NSLog(NSString, ...);
346-
extern (C) Class objc_lookUpClass(in char* name);
347306

348307
void main()
349308
{
350-
auto cls = objc_lookUpClass("NSString");
351-
auto str = cls.alloc().initWithUTF8String("Hello World!");
309+
auto str = NSString.alloc().initWithUTF8String("Hello World!");
352310
NSLog(str);
353311
str.release();
354312
}

0 commit comments

Comments
 (0)