快速编程语法问题

标签 swift

当两个变量和/或函数之间有句点时,swift 中的含义是什么。我知道这很简单,但我找不到答案,这让我发疯。示例程序如下:

 “let string1 = "hello"
 let string2 = " there"
 var welcome = string1 + string2
 // welcome now equals "hello there”


 let exclamationMark: Character = "!"
 welcome.append(exclamationMark)
 // welcome now equals "hello there!”

摘自:Apple Inc.“The Swift Programming Language”。电子书。 https://itun.es/ca/jEUH0.l

welcome 和 append 之间的句点有什么用?它有什么作用?

最佳答案

这就是您调用函数“append”的方式,例如“welcome”,传递“exclamationMark”作为参数。在 Objective-C 中,这将是:

[welcome append: exclamationMark];

通常,句点是您访问实例的任何成员(方法或属性)的方式。

关于快速编程语法问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31247725/

相关文章:

swift - 具有线性渐变的饼图 - swift

ios - 在 swift 上将 JSON 字符串转换为 JSON 对象

Swift - 使用未解析的标识符 'map'

ios - 从类型初始化对象时的 Swift 编译器 SegFault

ios - 从 viewForHeaderInSection 中的 UIButton 获取数据发送到 add Target 中的方法

ios - 我无法让我的球 SKSpriteNode 显示在辅助 View Controller 的 UIImage(Xcode/Swift 2) 上

swift - 向 UICollectionView 添加单元格时出现问题

swift - 是否可以将输入的文本保存到 SwiftUI 的警报文本字段中,并像这样在应用程序中显示它 -> Text ("alert text input here")?

ios - 由于内存问题而终止 TLViewHierarchyTool checkUIView :block: loop

swift - Alamofire 的通用功能