Comments (6)
When using a Swift class on Objective-C with a custom name you should use the same name as in Swift, on runtime the object will be created with the custom name provided, for example:
Chicken *chicken = [Chicken alloc] init];
NSLog("%@", chicken); // < RWTChicken 0x423432>
I think it was added to the style guide just to make more concise with the Objective-C guide.
More info:
#13
http://petehare.com/adding-obj-c-prefixes-to-swift-class-for-interoperability/
https://developer.apple.com/library/prerelease/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html
from swift-style-guide.
I guess it makes sense but it just seems odd as using @objc
on methods has the opposite effect in that the name provided in @objc
for a method is the name used in Objective-C.
How does the above help if there's a Chicken
class in two separate modules referenced in the same Objective-C file? How does one specify which Chicken
is to be used?
from swift-style-guide.
Sorry I didn't understand your question but as an overall what Apple say about specifying name is:
"... if the name of your Swift class contains a character that isnβt supported by Objective-C, you can provide an alternative name to use in Objective-C..."
So I'm not sure if we should add a custom name, it doesn't seems that was made for that, if you don't add it will generate the object with namespace so you don't risk to have a conflict.
from swift-style-guide.
Ok, my question is:
- I'm using two third party modules.
- Each of these modules have a
Chicken
class. - I want to reference both in the same Objective-C file.
How does that work? When I do [Chicken new]
which module is used?
from swift-style-guide.
I agree with @aaronrogers on this, it caused a great deal of confusion when I initially read the section on Class Prefixes.
The way it is written seems to suggest to add the additional name with prefix in the parenthesis, so you could use the class name with prefix in your Objective-C code. However, that's not the case, if one tries to reference the Chicken Swift type with RWTChicken, the code would not compile.
The prefixed class name is only used during runtime. Thus, I think the section should be rewritten to be more clear on this.
from swift-style-guide.
Our tutorials are all Swift anyway, so you're right to point out the possible confusion here.
from swift-style-guide.
Related Issues (20)
- In Multi-line String Literals, string color is different HOT 2
- Make the linter a dotfile HOT 2
- [email protected] HOT 1
- New line in functions. Not good. HOT 2
- Please add `no_extension_access_modifier` as a default SwiftLint rule HOT 1
- Please Add SwiftUI style guide
- https://ideas.accredible.com/changelog/functionality-for-a-messagenotification-to-be-added-over-an-issued-credential
- edge://credits/ HOT 1
- Clean code
- Function Declarations HOT 1
- 4-space indentation. HOT 2
- False positive from array_constructor custom rule
- how to write switch statement HOT 1
- Preferred type inference of static vars inside extensions HOT 4
- Pls update Readme file to reflect the newest changes in `if let` syntax introduced in Swift 5.7 HOT 1
- unused_import does not seem to be working HOT 1
- Function Calls vs Function Declarations HOT 2
- `unused_import` should be listed in the `analyzer_rules`
- SwiftLint 'attributes' rule flags property wrappers HOT 2
- Function calls format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swift-style-guide.