晚上,在我的应用程序中我有几个UITextfield.每个人都必须确认不同的限制.
例如,我有一个日期字段,zipCode字段,SSN字段等.
从Apple文档中我发现:
分配委托对象以处理重要任务,例如:
确定是否允许用户编辑文本字段的内容.
验证用户输入的文本.
响应键盘返回按钮的敲击.
将用户输入的文本转发到应用的其他部分.
在一个控制器对象中存储对文本字段的引用.
所以我很确定我必须使用代表和func textFieldDidEndEditing(_:).
我想到的唯一方法是在switch内部使用一个语句func textFieldDidEndEditing(_:)来确认代表的差异限制.
是否有更好,更安全,更快速的模式来面对这个问题?
晚上,是否可以将所有打印和调试打印保存在一个文件中?
即使不是从 Xcode 启动,我也想拥有我的应用程序所做操作的日志。
我正在考虑覆盖 print 和 debugPrint 方法并将输入写入文件。
谢谢
我正在尝试更改 SwiftUI 中 ActionSheet 的文本颜色和背景颜色。
这是我的actionSheet的代码:
.actionSheet(isPresented: $viewModel.isCustomItemSelected) {
ActionSheet(
title: Text("Add Item"),
message: Text("Which item would you like to add?"),
buttons: [
.default(Text("Todo")),
.default(Text("Event")),
.cancel(Text("Cancel"))
])
}
Run Code Online (Sandbox Code Playgroud)
无论我尝试什么,比如色调颜色、前景色等。它都不会改变颜色。正确的改变方法是怎样的呢?我想 SwiftUi 没有任何 API 来设置它的样式,但我确信这应该是任何解决方法。
晚间,
我正在尝试使用类型为T的属性x构建实体A.
T是我创建的枚举.
我应该如何设置xcdatamodel以使用属性的自定义类型?
我目前的设置是:
attribute x, type: Undefined, CustomClass: T.
Run Code Online (Sandbox Code Playgroud)
但我有错误:
x ....核心数据必须具有已定义的类型.
特殊目的:
x是一种"情绪"属性,可能有3种不同的情绪,这就是我选择枚举的原因.
晚上,我正在开发一个基于SWAPI的应用程序(星球大战api:https://swapi.co/documentation )
我得到了ATS错误:App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
我无法理解原因.我baseURL是https格式
struct NetworkManager {
let baseURL = "https://swapi.co/api/"
let session = URLSession(configuration: .default)
func fetchEndpoint(endpoint: Endpoint, completion: @escaping (_ response: Result) -> Void) {
self.fetchURL(url: baseURL + endpoint.URL(), completion: completion)
}
func fetchURL(url: String, completion: @escaping (_ response: Result) -> Void) {
let url = …Run Code Online (Sandbox Code Playgroud) 我的应用程序我有一个StackView包含三个不同的视图:角色,星舰和车辆.
现在,我想在某种情况下,只会出现一个View而另外两个不会出现.
我不是说隐藏和显示,而是安装和卸载.为什么?因为如果我保持我的视图安装我的Xcode崩溃.
有小费吗?
我无法将紧排空间添加到选项卡栏属性文本中。有问题的 UITabBar 是一个自定义 tabBar,您可以找到下面的代码。
我正在使用“属性键”字典向项目标题添加属性,但我遇到了紧缩空间问题。
class ProfileTabBar: UITabBar {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setStyle()
}
required override init(frame: CGRect) {
super.init(frame: frame)
self.setStyle()
}
func setStyle() {
self.tintColor = Style.shared.primary1
// Disable the default border
self.layer.borderWidth = 0.0
self.clipsToBounds = true
// Create a new bottom border
let bottomLine = CALayer()
let screenWidth = UIScreen.main.bounds.width
//let viewForFrame = self.superview ?? self
//let screenWidth = viewForFrame.bounds.width
bottomLine.frame = CGRect(x: 0.0, y: self.frame.height - 1, width: screenWidth, height: 2.0) …Run Code Online (Sandbox Code Playgroud) 我有一个通过 Cocoapods 分发的 Umbrella 框架作为供应商框架并以发布模式编译。
它与模拟器完美配合,但我对嵌套在伞层中的子框架上的代码符号有问题。
这是错误:
dyld: Library not loaded: @rpath/Subframework.framework/Subframework
Referenced from: /private/var/containers/Bundle/Application/02AD328F-9E78-4D53-9C39-0C8639B00D81/sdkInteTest.app/Frameworks/Umbrella.framework/Umbrella
Reason: no suitable image found. Did find:
/private/var/containers/Bundle/Application/02AD328F-9E78-4D53-9C39-0C8639B00D81/sdkInteTest.app/Frameworks/Umbrella.framework/Frameworks/Subframework.framework/Subframework: code signature in (/private/var/containers/Bundle/Application/02AD328F-9E78-4D53-9C39-0C8639B00D81/sdkInteTest.app/Frameworks/Umnrella.framework/Frameworks/Subframework.framework/Subframework) not valid for use in process using Library Validation: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.
Run Code Online (Sandbox Code Playgroud)
然后,如果我启动应用程序以使用以下脚本签署子框架:
pushd ${TARGET_BUILD_DIR}/${PRODUCT_NAME}.app/Frameworks/Umbrella.framework/Frameworks
for EACH in *.framework; do
echo "-- signing ${EACH}"
/usr/bin/codesign --force --deep --sign "${EXPANDED_CODE_SIGN_IDENTITY}" --entitlements "${TARGET_TEMP_DIR}/${PRODUCT_NAME}.app.xcent" --timestamp=none $EACH
done
popd
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
/Users/xxx/Library/Developer/Xcode/DerivedData/sdkInteTest-bbfpzsxuhjomfmaumywyncnbwbla/Build/Intermediates.noindex/sdkInteTest.build/Debug-iphoneos/sdkInteTest.build/Script-F9547ACC224017BF0030EA0B.sh: line 3: pushd: /Users/xxx/Library/Developer/Xcode/DerivedData/sdkInteTest-bbfpzsxuhjomfmaumywyncnbwbla/Build/Products/Debug-iphoneos/sdkInteTest.app/Frameworks/Umbrella.framework/Frameworks: …Run Code Online (Sandbox Code Playgroud) 我正在尝试将新的Combine框架与通知中心一起使用,如Apple在此视频中所述:https: //developer.apple.com/videos/play/wwdc2019/721/
您可以在幻灯片21中找到它。
看来我的项目没有阅读Combine框架api。
import Combine
import Foundation
let trickNamePublisher = NotificationCenter.default.publisher(for: .newTrickDownloaded)
Run Code Online (Sandbox Code Playgroud)
而且我收到此错误:
类型'NotificationCenter'的值没有成员'publisher'
我的应用程序中有一个共享视图,可以在不同的地方调用。这个视图的根是一个滚动视图,但有时它会忽略顶部安全区域并折叠在导航栏下方。
这里有两个屏幕截图可以更好地显示问题:
正如您在第二个屏幕截图中看到的,滚动视图针对导航下折叠的所有屏幕进行了扩展。我怎样才能避免这种情况?