objective-c - How to set first argument label in objective c to use in swift?
问题描述
I thought to use first argument label of objective function in swift, it can be done by adding preposition to function name.
- (void) makeRoundedWithCornerRadius: (CGFloat) cornerRadius;
I can use it in swift project like this (It is what I expected)
myView.makeRounded(withCornerRadius: 16)
And I made another function like this
- (void) makeBorderWithColor: (UIColor*) color width: (CGFloat) width;
However when I'm about to use it in swift, first argument label does not show the way I expected. What I expected was
myView.makeBorder(withColor: .red, width: 10)
But it showed like..
myView.makeBorder(with: .red, width: 10)
It eliminates color label. I am very confused and even can't guess the rule.
What is the rule that convert Objective-C function name to Swift's first argument label? And is it other way to make first argument label that I want?
解决方案
You can use method renaming – NS_SWIFT_NAME
keyword:
- (void) makeRoundedWithCornerRadius: (CGFloat) cornerRadius width: (CGFloat) width NS_SWIFT_NAME(makeBorder(withColor:width:));
推荐阅读
- python - 我有两个关于python语法的问题。for 循环和 while 循环
- pandas - XML 解析为 pandas 数据框
- javascript - 在 setInterval 内部使用带有 if 条件的 useState 不起作用
- python - “F”和括号的问题
- python - Python Pandas:使用dict导出到CSV时如何从数据框中删除列表括号?
- ruby-on-rails - Ruby on Rails 的 Bash_profile
- javascript - 在 es6 中处理文本
- oracle - OIM EBS 连接器升级
- r - 如何躲避误差线和点?使用位置参数的问题
- python - 按住键盘而不是多次按下