简体   繁体   English

如何使用 Swift 中的自动生成密钥从 storyboard 中设置的 UITextView 中检索文本?

[英]How to retrieve text from UITextView set in storyboard using auto generated key in Swift?

I have a directory structure something like this我有一个类似这样的目录结构

MyApp
|-ExternalFrameworks
|-MyApp
|-Storyboards
| |
| |-Dashboard.storyboard
| |-News.storyboard
| |-Social.storyboard
| | |
| | |-Social.strings(English)
| | |-Social.strings(French)

And suppose the autogenerated string is "hn8-xyz" sore some key in the.strings file.并假设自动生成的字符串是“hn8-xyz”,在.strings 文件中有一些键。 I need to extract the value string associated with the key.我需要提取与键关联的值字符串。

I've found the the method to extract the string that is我找到了提取字符串的方法

NSLocalizedString(key: String, tableName: String?, bundle: Bundle, value: String, comment: String)

What I am not able to figure out is, how to assign the bundle property in this method based on my dir structure?我无法弄清楚的是,如何根据我的 dir 结构在此方法中分配 bundle 属性? I am primarily a java dev and not an iOS guy, but I've got this fix to do.我主要是 java 开发人员,而不是 iOS 人,但我有这个修复要做。 Pardon my lack of framing the question as per Swift terminology.请原谅我没有按照 Swift 术语提出问题。

Let me know if more information is needed to answer the question.让我知道是否需要更多信息来回答这个问题。

For most apps, you only have one bundle, the main bundle.对于大多数应用程序,您只有一个捆绑包,即主捆绑包。 If you look at the declaration of the function:如果您查看 function 的声明:

func NSLocalizedString(_ key: String, tableName: String? = nil, bundle: Bundle = Bundle.main, value: String = "", comment: String) -> String

The bundle parameter has a default value of Bundle.main . bundle参数的默认值为Bundle.main You can probably just skip that parameter entirely.您可能可以完全跳过该参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Firebase中检索自动生成的ID /密钥? - How to retrieve the auto generated id/key in Firebase? 如何使用UITextView仅显示原始文本中的几个-Swift - How to display just few from original text using UITextView - swift 如何将自定义 NSTextStorage 设置为从 storyboard 创建的 UITextView object? - How to set a custom NSTextStorage to a UITextView object created from a storyboard? 如何快速设置UITextView for Universal App的程序化自动布局约束 - How To Set Auto Layout Constraints Programmatically for UITextView For Universal App with swift 如何使用Swift从情节提要生成的UIScrollView创建设置器? - How can I create a setter for a UIScrollView generated from the storyboard using Swift? 从UITextView Swift 2获取文本 - Get text from UITextView Swift 2 使用swift(IOS应用程序)自动滚动UITextView - auto scroll for UITextView using swift (IOS app) 使用核心数据Swift从UITextView保存文本 - Saving text from a UITextView using core data Swift 在 Swift 中使用 UIPasteBoard 将文本从 UITextView 复制到剪贴板 - Copy text from UITextView into clipboard using UIPasteBoard in Swift 如何通过使用 Swift 单击按钮以编程方式将文本输入 UITextView - How to programmatically enter text into a UITextView by Clicking a Button using Swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM