我想在swift中过滤字典:
var data: [String: String] = [:]
data = data.filter { $0.1 == "Test" }
Run Code Online (Sandbox Code Playgroud)
上面的过滤器代码在swift 2下编译但产生以下错误:
无法将类型'[(String,String)]'的值赋给类型'[String:String]'的值
这是swift编译器中的一个错误,还是这不是在swift中过滤字典的正确方法?
非常感谢你提前!
I have just installed Xcode11 and when i try to create new fresh project with SwiftUI check mark selected it returns error.
Not able to build and run successfully.
File 'ContentView.swift' is part of module 'SwiftUI'; ignoring import
ContentView.swift
Use of undeclared type 'View'
SceneDelegate.swift
Use of unresolved identifier 'UIHostingController'
I have tried removing all derived data and also set command-line tools to 11
运行Xcode 10并且似乎无法找到有关构建项目时出现的此错误的更多信息.
有想法该怎么解决这个吗?
这是错误之前的最后一行:
Desktop/CheerApp!/ CheerApp!/Assets.xcassets命令CompileAssetCatalog失败并带有非零退出代码 -
扩展:
CompileAssetCatalog /Users/michaelansell/Library/Developer/Xcode/DerivedData/CheerApp!-ehbjnqaldsycfegiviymewkplqhm/Build/Products/Debug-iphonesimulator/CheerApp!.app /Users/michaelansell/Desktop/CheerApp!/CheerApp!/Assets.xcassets(在目标中) :CheerApp!)cd/Users/michaelansell/Desktop/CheerApp!/Applications/Xcode.app/Contents/Developer/usr/bin/actool --output-format human-readable-text --notices --warnings --export-dependency-info/Users/michaelansell/Library/Developer/Xcode/DerivedData/CheerApp!-ehbjnqaldsycfegiviymewkplqhm/Build/Intermediates.noindex/CheerApp!.build/Debug-iphonesimulator/CheerApp!.build/assetcatalog_dependencies --output-partial-info-plist/Users/michaelansell/Library/Developer/Xcode/DerivedData/CheerApp!-ehbjnqaldsycfegiviymewkplqhm/Build/Intermediates.noindex/CheerApp!.build/Debug-iphonesimulator/CheerApp!.build/assetcatalog_generated_info.plist --app-icon AppIcon --compress-pngs --enable-on-demand-resources YES - -optimization space --filter-for-device-model iPhone11,2 --filter-for-device-os-version 12.0 --sticker-pack-identifier-prefix Mike.CheerApp-.sticker-pack.--target-device iphone --target-device ipad --minimum-deployment-target 11.4 --platform iphonesimulator --product-type com.apple.product-type.application --compile/Users/michaelansell/Library/Developer/Xcode中/ DerivedData/CheerApp!-ehbjnqaldsycfegiviymewkplqhm /编译/产品/调试,iphonesimulator /
我已经使用UIPinchGestureRecognizer UIPanGestureRecognizer及UIRotationGestureRecognizer与UILabel实现的Instagram,如缩放和拖动功能,但现在我想显示布局的GUID时一样UILabel是中心,它会显示布局的GUID像下面的例子是例如Instagram的的阻力.旋转时它还会显示布局指南UILabel
实现此功能的最佳和最准确的方法是什么.
这就是我已经做过的事情
这是我为简单的拖放功能所做的代码.
SnapGesture类
import UIKit
/*
usage:
add gesture:
yourObjToStoreMe.snapGesture = SnapGesture(view: your_view)
remove gesture:
yourObjToStoreMe.snapGesture = nil
disable gesture:
yourObjToStoreMe.snapGesture.isGestureEnabled = false
advanced usage:
view to receive gesture(usually superview) is different from view to be transformed,
thus you can zoom the view even if it is too small to be touched.
yourObjToStoreMe.snapGesture = SnapGesture(transformView: your_view_to_transform, gestureView: your_view_to_recieve_gesture)
*/
class SnapGesture: NSObject, UIGestureRecognizerDelegate {
// MARK: …Run Code Online (Sandbox Code Playgroud) 我已经使用列出了简单的数据列表List。我想添加下拉菜单以刷新功能,但是我不确定哪种方法是最好的。
下拉刷新视图才可以看到,当用户尝试从同一像我们的第一个指数下拉在做UITableView与UIRefreshControl在UIKit
这是在中列出数据的简单代码SwiftUI。
struct CategoryHome: View {
var categories: [String: [Landmark]] {
.init(
grouping: landmarkData,
by: { $0.category.rawValue }
)
}
var body: some View {
NavigationView {
List {
ForEach(categories.keys.sorted().identified(by: \.self)) { key in
Text(key)
}
}
.navigationBarTitle(Text("Featured"))
}
}
}
Run Code Online (Sandbox Code Playgroud) 我试图用我自己的视图覆盖状态栏并且这样做我通过做类似的事情(也在旋转之后)为我的视图计算框架:
UIScreen *screen = [UIScreen mainScreen];
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
Run Code Online (Sandbox Code Playgroud)
对于iOS8 +(因为UIScreenios8依赖于取向):
CGRect frame = [screen.coordinateSpace convertRect:statusBarFrame toCoordinateSpace:screen.fixedCoordinateSpace];
[self setFrame:frame];
Run Code Online (Sandbox Code Playgroud)
对于iOS7:
[self setFrame:statusBarFrame];
Run Code Online (Sandbox Code Playgroud)
它适用于iOS8及以下版本,但在使用Xcode 7 beta 4和iOS 9 SDK构建我的应用程序时,在横向或颠倒启动应用程序时出现问题(如果应用程序以纵向方式启动,则工作正常)...
即.当我在颠倒时启动应用程序时,应该覆盖状态栏的自定义uiwindow将始终位于屏幕的底部,任何想法可能出错?
我已经将 ScrollView 与 HStack 一起使用,现在我需要在用户最终滚动时加载更多数据。
var items: [Landmark]
Run Code Online (Sandbox Code Playgroud)
我有我在我appeding项的使用的阵列HStack使用ForEach
ScrollView(showsHorizontalIndicator: false) {
HStack(alignment: .top, spacing: 0) {
ForEach(self.items) { landmark in
CategoryItem(landmark: landmark)
}
}
}
Run Code Online (Sandbox Code Playgroud)
在不使用加载更多按钮等自定义操作的情况下,在SwiftUI 中管理更多加载的最佳解决方案是什么。
我在Python上用eroku设置了TwiMl.当我从用户B呼叫用户A时,用户A也没有得到呼叫和VOIP,而用户B得到了像"感谢呼叫"这样的机器人消息.
当我尝试placeCall用户B时PostMan,用户B接到电话,并得到像"感谢呼叫"这样的机器人消息.
PostMan网址:https://myapp.herokuapp.com/placeCall
我的要求是,当我从应用程序用户B呼叫用户A时,它将接到电话并且两者都能够进行通信.
需求
Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
Werkzeug==0.9.6
httplib2==0.9
itsdangerous==0.24
six==1.*
twilio
wsgiref==0.1.2
Run Code Online (Sandbox Code Playgroud)
这是我的Python TwiMl代码.
import os
from flask import Flask, request
from twilio.jwt.access_token import AccessToken
from twilio.jwt.access_token.grants import VoiceGrant
from twilio.rest import Client
import twilio.twiml
ACCOUNT_SID = 'ACxxxxxxxx'
API_KEY = 'SKxxxxxxxx'
API_KEY_SECRET = 'TSxxxxxxxx'
PUSH_CREDENTIAL_SID = 'CRxxxxxxxx'
APP_SID = 'APxxxxxxxx'
app = Flask(__name__)
@app.route('/test', methods=['GET', 'POST'])
def test():
req_json = request.get_json(force=True)
UserName = req_json['username']
Password = req_json['password']
return str(UserName)
@app.route('/accessToken')
def token(): …Run Code Online (Sandbox Code Playgroud) 我现在正在查看文本,我想每秒使用一次警报来更新该文本。
这是我完成的代码。
struct CountDownView : View {
var body: some View {
VStack{
Text("Update text with timer").lineLimit(nil).padding(20)
}.navigationBarTitle(Text("WWDC"), displayMode:.automatic)
}
}
Run Code Online (Sandbox Code Playgroud) 我添加了spacer(minLength:5),但是我可以指定 minlenght 来指定文本之间的间距。我已经附上了一个屏幕截图,以供参考,我想减少内部hstack之间的间距。
HStack {
Image("Rhea").resizable().cornerRadius(25).frame(width: 50.0, height: 50.0)
VStack(alignment: .leading) {
Text("How to enjoy your life without money").bold().font(.system(size: 20))
HStack {
Text("Lets create")
Spacer(minLength: 5)
Text("3K views")
Spacer(minLength: 5)
Text("3 hours ago")
}
}
}
Run Code Online (Sandbox Code Playgroud)