小编Mac*_*jda的帖子

Xcode 9自定义模板如何更改?

下载Xcode 9 beta后,我发现文件模板系统发生了变化.

例如,我有一个创建2个文件的简单模板(它可能根本不应该以这种方式工作).基本文件名是

___ ___ FILEBASENAME斯威夫特

___ ___ FILEBASENAME View.swift

它创建了TableCell.swift和TableCellView.swift,这里是代码:

//
//  ___FILENAME___
//  ___PROJECTNAME___
//
//  Created by ___FULLUSERNAME___ on ___DATE___.
//___COPYRIGHT___
//

import Foundation
import UIKit

class ___FILEBASENAME___: UITableViewCell {

    let mainView = ___FILEBASENAME___View()

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        setupCell()
        contentView.addSubview(mainView)
        mainView.setupView()
    }

    fileprivate func setupCell() {
        backgroundColor = UIColor.clear
        selectionStyle = .none
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}
Run Code Online (Sandbox Code Playgroud)

并查看文件:

//
//  ___FILENAME___ …
Run Code Online (Sandbox Code Playgroud)

xcode templates swift xcode9-beta xcode9

9
推荐指数
1
解决办法
1917
查看次数

SwiftUI Text 和 LocalizedStringKey 带参数

我正在尝试添加带有参数的 SwiftUI 本地化文本。然而,在整个应用程序中,我们使用本地化键的包装器,所以我们有这样的东西:

static let helloWorldText = NSLocalizedString("helloWorldText", comment: "")
Run Code Online (Sandbox Code Playgroud)

随着使用

label.text = LocalizationWrapper.helloWorldText
Run Code Online (Sandbox Code Playgroud)

或者

Text(LocalizationWrapper.helloWorldText)
Run Code Online (Sandbox Code Playgroud)

而且效果很好。

然后,当涉及到添加带有参数的本地化文本时,它似乎不起作用。

所以我有一把钥匙"helloWorld %@"

我有一个static let helloWorldWithParameter = NSLocalizedString("helloWorld %@", comment: "")

现在我尝试这样做:

Text("\(LocalizationWrapper.helloWorldWithParameter) \(name)")
Text(LocalizedStringKey(LocalizationWrapper.helloWorldWithParameter + " " + name))
Text(LocalizationWrapper.helloWorldWithParameter + " " + name)
Run Code Online (Sandbox Code Playgroud)

它们都不起作用,但Text("helloWorld \(name)")效果很好。

然后我尝试删除 NSLocalizedString 只留下LocalizationWrapper.helloWorldWithParameter一个干净的字符串,但它也没有做任何事情

我怎样才能做到这一点?我看过这个,但有点脏。

nslocalizedstring ios swift swiftui localizedstringkey

3
推荐指数
1
解决办法
3371
查看次数