You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$(SECTION2 $(LNAME2 usage-example, Full Usage Example))
224
224
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
-
231
225
$(P
232
226
This example will create an Objective-C string, `NSString`, and log the
233
227
message using `NSLog` to stderr.
234
228
)
235
229
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`,
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:`)
263
244
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`)
265
246
method is used to release an deallocate the string. Since D doesn't
266
247
support $(LINK2 https://developer.apple.com/library/mac/releasenotes/ObjectiveC/RN-TransitioningToARC/Introduction/Introduction.html, ARC)
267
248
it's needed to manually release Objective-C instances.
268
249
)
269
250
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
-
280
251
---
281
252
extern (C) void NSLog(NSString, ...);
282
253
---
@@ -288,13 +259,7 @@ $(HEADERNAV_TOC)
288
259
)
289
260
290
261
---
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();
298
263
---
299
264
300
265
$(P Allocate an instance of the class, `NSString`.)
0 commit comments