-
-
Notifications
You must be signed in to change notification settings - Fork 593
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7762 from jacob-carlborg/objc_class_methods
Add support for Objective-C class/static methods merged-on-behalf-of: Mike Franklin <JinShil@users.noreply.github.com>
- Loading branch information
Showing
20 changed files
with
552 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
Support for calling Objective-C class (static) methods has been added. | ||
|
||
Previously to call an Objective-C class method it was necessary to make explicit | ||
calls to the Objective-C runtime. The following code is an example of the old | ||
way to call a class method: | ||
|
||
--- | ||
extern (C) Class objc_lookUpClass(in char* name); | ||
|
||
extern (Objective-C) | ||
interface Class | ||
{ | ||
NSObject alloc() @selector("alloc"); | ||
} | ||
|
||
extern (Objective-C) | ||
interface NSObject | ||
{ | ||
NSObject init() @selector("init"); | ||
} | ||
|
||
void main() | ||
{ | ||
auto cls = objc_lookUpClass("NSObject"); | ||
auto o = cls.alloc().init(); | ||
} | ||
--- | ||
|
||
The above code can now be replaced with the following: | ||
|
||
--- | ||
extern (Objective-C) | ||
interface NSObject | ||
{ | ||
static NSObject alloc() @selector("alloc"); | ||
NSObject init() @selector("init"); | ||
} | ||
|
||
void main() | ||
{ | ||
auto o = NSObject.alloc().init(); | ||
} | ||
--- | ||
|
||
Note the use of the `static` attribute in the method declaration. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.