swift-string 相关问题


Alamo Fire 和 Swift 无法将类型“[String : String]”的值转换为预期参数类型“HTTPHeaders?”

func requestWithRetries(tag:String, url:String, maxRetry:Int = 3,expectJSONArray:Bool,completion:@escaping jsonCompletion) { var headers = [String:String]() 让 params = [String:AnyObjec...


java中的Boolean.valueOf(String)和BooleanUtils.toBoolean(String)?

我有一个 Boolean.valueOf(String) 和 BooleanUtils.toBoolean(String) 之间不同的问题 。 我使用我的应用程序就像代码 BooleanUtils.toBoolean(defaultInfoRow.getFolderType()) 一样


使用 Swift 调用 Flickr API

我试图从 Flickr API 获取一些 JSON 数据,但我的 Swift 代码无法正常工作。 这是基于 Jameson Quave 关于使用 Swift 发出 API 请求的教程 func GetFlickrData(标签:字符串...


在 XCFramework 中难以访问 Swift Framework 中的 Objective-C 类

我有一个 Swift 框架,我想添加一个 Objective C 包装器以从 Objective C 项目进行访问(出于某种原因,这是要求)。 我已经封装了 Swift 类以支持 Objec...


如何在 Swift 中捕获异步闭包内的局部变量?

我在 Swift 5.5 和 iOS 15 中有以下代码 func getReviewIds() { var reviewIds: [Int] = [] 任务 { 让 ids = 等待 getReviewIdsFromGoogle() reviewIds.append(


Xcode 突然无法获取 Swift 包修订版:“无法获取修订版”

我在 Xcode 中打开了一个依赖于 RxSwift 的项目,该项目通过内置 Swift 包管理器作为 Swift 包包含在内。 几周前我创建该项目时效果很好。 不...


如何在 Swift 中转换闭包签名内的参数类型?

我正在尝试用 Swift(目前是 Swift 2)编写一个轻观察者类。这个想法是在实体组件系统中使用它,作为组件之间相互通信的一种手段,而无需


致命错误:在 Firebase Storage Swift SDK 中解包可选值时意外发现 nil

我的 Swift 应用程序在 FirebaseStorage/Storage.swift 第 49 行遇到致命错误,其中使用 FirebaseApp.app() 创建 Firebase Storage 实例!。错误指出“致命...


在swift项目中使用UIViewRepresentable时如何更新View

我正在努力在 swift 项目中展示 React-native-View。我通过异步操作下载bundlde文件,将bundle文件保存在app目录中,并用它来创建


如何以模板文字类型返回?

我使用这样的模板文字类型: 输入 HelloSomething = `你好 ${string}` 常量字符串='世界' 函数 sayHello(string: string): HelloSomething { 返回“你好”+字符串 } (游乐场...


我在代码中遇到此错误:Swift/ContigeousArrayBuffer.swift:600: Fatal error: Index out of range

我正在构建一个测验应用程序,但收到此错误:Swift/ContigouslyArrayBuffer.swift:600:致命错误:索引超出范围。这是被标记的代码片段: choice2.setTitle(


Swift 动态框架错误 Class is not a member of type of class SDKA.SDKA

我是创建 Swift 框架的新手,我正在尝试创建一个新的动态框架 (B.xcframework),它也使用另一个动态框架 (A.xcframework)。到目前为止我所做的是添加A。


是否可以在 Swift 中的结构变量上添加观察者?

我需要跟踪结构类型变量的更新。 是否可以在 Swift 中的结构变量上添加观察者? 例子: 结构 MyCustomStruct { 变量错误:错误? var someVar:Strin...


可选子数组中的 foreach 循环内的 Swift foreach 循环

我是 Swift 新手,所以如果我有一些术语不正确,请原谅我。 我有一个膳食计划的日历视图。父数组生成给定月份的天数,子数组包含...


Swift 中的网络管理器

我正在尝试创建一个 CRM 应用程序,为此我在树莓派上创建了一个数据库,并使用 PHP 在 url 上创建 JSON 结果。 现在我已经在 swift 中创建了以下网络管理器,但是


我想将数组数据从 Swift 传递到 Metal 的 Uniform 片段着色器

我正在尝试将 Uniform 中的数组数据从 Swift 传递到 Metal 的片段着色器。我能够毫无问题地传递非数组的普通浮点数。 结构如下 结构 Unifo...


另一个模型中的模型列表仅保存列表中所有项目中最后添加的项目

对于 (int x=0; x for (int x=0; x<listaEquipes.length; x++) { await _loadEquipe(listaEquipes[x].id.toString()); TabelaListaEquipes _reg = TabelaListaEquipes(); _reg.equipeId = listaEquipes[x].id.toString(); _reg.equipe = listaAtletaEquipe; //print (_reg.equipe![0].nome.toString()); listaEquipesGeral.add(_reg); } 此型号: class TabelaListaEquipes { String? equipeId; List<TabelaInscricoes>? equipe; TabelaListaEquipes( { this.equipeId, this.equipe}); } 现在我看到最后一个reg保存在列表的所有iten中,为什么? 这就对了: listaEquipesGeral[0].equipe == listEquipesGeral[1].equipe ...仍然添加了最后一项。为什么?? _loadEquipe 函数,它也有效,我已经测试过了, List<TabelaInscricoes> listaAtletaEquipe = []; Future<void> _loadEquipe(equipId) async { setState(() { listaAtletaEquipe.clear(); carregandoEquipe = true; }); TabelaInscricoes _result = TabelaInscricoes(); CollectionReference _dbCollection = FirebaseFirestore.instance.collection('campeonatos').doc(resultSelect.campId).collection('divisoes').doc(resultSelect.divId).collection('equipes').doc(equipId).collection('atletas'); await _dbCollection.orderBy('pos2', descending: false).get().then((QuerySnapshot querySnapshot) async { if (querySnapshot.docs.isNotEmpty) { querySnapshot.docs.forEach((element) async { _result = TabelaInscricoes.fromJson(element.data()! as Map<String, dynamic>); if (_result.campId == resultSelect.campId && _result.divId == resultSelect.divId) { _result.id = element.id; _result.filePath = ""; setState(() { listaAtletaEquipe.add(_result); }); } }); for (int x = 0; x<listaAtletaEquipe.length; x++) { for (int y = 0; y<listaAtletas.length; y++) { if (listaAtletaEquipe[x].atletaId.toString() == listaAtletas[y].id.toString()) { setState(() { listaAtletaEquipe[x].nome = listaAtletas[y].nome; listaAtletaEquipe[x].fotoNome = listaAtletas[y].fotoNome; listaAtletaEquipe[x].filePath = listaAtletas[y].filePath; listaAtletaEquipe[x].dataN = listaAtletas[y].dataN; listaAtletaEquipe[x].fone1 = listaAtletas[y].fone1; listaAtletaEquipe[x].fone2 = listaAtletas[y].fone2; listaAtletaEquipe[x].nTitulo = listaAtletas[y].nTitulo; listaAtletaEquipe[x].info = listaAtletas[y].info; listaAtletaEquipe[x].email = listaAtletas[y].email; }); } } } for (int x=0; x<listaAtletaEquipe.length; x++) { if (listaAtletaEquipe[x].fotoNome.toString().isNotEmpty) { await MyStorage.getUrl(context, "atletas/${listaAtletaEquipe[x].fotoNome.toString()}").then((value) { setState(() { listaAtletaEquipe[x].filePath = value; }); }); } } setState(() { carregandoEquipe = false; }); }else { setState(() { carregandoEquipe = false; }); } }); } AtletaEquipes 型号操作系统列表: class TabelaInscricoes{ bool? carregando = true; String? id; String? campId; String? divId; String? atletaId; String? nome_responsavel; String ?posicao; String? filePath; Uint8List? imageFile; String? usuario; String? nInscricao; String? nome; String? dataN; String? nTitulo; String? fone1; String? fone2; String? info; String? email; String? fotoNome; String? pos2; String? selected; TabelaInscricoes({ this.carregando, this.nome, this.dataN, this.nTitulo, this.fone1, this.fone2, this.info, this.email, this.id, this.campId, this.divId, this.posicao, this.nome_responsavel, this.nInscricao, this.atletaId, this.selected, this.pos2, this.fotoNome, this.filePath, this.imageFile, this.usuario}); Map<String, dynamic> toJson() => { 'campId': campId, 'divId': divId, 'atletaId': atletaId, 'nome_responsavel': nome_responsavel, 'posicao': posicao, 'usuario': usuario, 'nInscricao': nInscricao, 'pos2': pos2, 'selected': selected }; TabelaInscricoes.fromJson(Map<String, dynamic> json) : campId = json['campId'], divId = json['divId'], atletaId = json['atletaId'], nome_responsavel = json['nome_responsavel'], posicao = json['posicao'], nInscricao = json['nInscricao'], pos2 = json['pos2'], selected = json['selected'], usuario = json['usuario']; } 这里发生了什么,listaEquipesGeral 总是保存最后添加的所有项目。 我明白了,解决方案是在模型内的列表中逐项添加: for (int x=0; x<listaEquipes.length; x++) { await _loadEquipe(listaEquipes[x].id.toString()); TabelaListaEquipes _reg = TabelaListaEquipes(); _reg.equipeId = listaEquipes[x].id.toString(); _reg.equipe = []; //here above the solution, include for to put item by item, and it works for (int y = 0; y<listaAtletaEquipe.length; y++) { _reg.equipe!.add(listaAtletaEquipe[y]); } //print (_reg.equipe![0].nome.toString()); listaEquipesGeral.add(_reg); }


Kotlin - 主要和次要构造函数

class SmartDevice(val 名称: String, val 类别: String) { var deviceStatus = "在线" 构造函数(名称:字符串,类别:字符串,状态代码:Int):this(名称,类别){ ...


在使用 TypeScript 进行 React 时,输入字段在“值”处给出错误

从“react”导入{SetStateAction,useState} const 登录表单 =() =>{ const [名称,setName] = useState(); const [全名,setFullname] = useState import { SetStateAction, useState } from "react" const Loginform =() =>{ const [name, setName] = useState<String | null>(); const [fullname, setFullname] = useState<String | null>(); const inputEvent =(event: { target: { value: SetStateAction< String |null | undefined >; }; })=>{ setName(event.target.value) } const Submit = ()=>{ setFullname(name) } return <> <h1>Enter Your Name </h1> <input type="text" placeholder="Enter your name" onChange={inputEvent} value={name}/> <button onClick={Submit}>Submit</button> <h1>Hi {fullname==null? "Guest" :fullname}</h1> </> } export default Loginform <input type="text" placeholder="Enter your name" onChange={inputEvent} value={name}/> 上一行中的“value”属性显示错误 这是错误详细信息: (property) React.InputHTMLAttributes<HTMLInputElement>.value?: string | number | readonly string[] | undefined Type 'String | null | undefined' is not assignable to type 'string | number | readonly string[] | undefined'. Type 'null' is not assignable to type 'string | number | readonly string[] | undefined'.ts(2322) index.d.ts(2398, 9): The expected type comes from property 'value' which is declared here on type 'DetailedHTMLProps<InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>' 也尝试写 return as any。或者尝试添加 string[],但出现错误。 进行以下调整: 将 String 替换为 string,因为原始 Typescript 类型是小写的 (number, string, boolean, etc) TypeScript 报告此错误,因为属性值不接受 null 作为值,而是接受 undefined。将代码更新为: const [name, setName] = useState<string>() 这会使用 string 作为默认类型来初始化状态。 初始状态隐式地被视为 undefined,因为如果未显式提供,TypeScript 会将类型的默认值设置为 undefined。 为了简单起见,您不需要解构事件。使用内联函数,如下例所示: <input type="text" placeholder="Enter your name" onChange={(e) => setName(e.target.value)} value={name}/> 我使用你的代码创建了一个 CodeSanbox,它似乎只需要很少的修改就可以正常工作。 您可以在这里找到沙盒 这是我想出的代码 import { SetStateAction, useState } from "react"; const Loginform = () => { const [name, setName] = useState<string | null>(); const [fullname, setFullname] = useState<string | null>(); const inputEvent = (event: { target: { value: SetStateAction<string | null | undefined> }; }) => { setName(event.target.value); }; const Submit = () => { setFullname(name); }; return ( <div> <h1>Enter Your Name </h1> <input type="text" placeholder="Enter your name" onChange={inputEvent} value={name} /> <button onClick={Submit}>Submit</button> <h1>Hi {fullname == null ? "Guest" : fullname}</h1> </div> ); }; export default Loginform;


Julia 语法错误@kwdef,默认值为字符串

此代码会产生语法错误。我无法在 @kwdef 结构中使用默认值? @kwdef 结构 MyStruct indir::String = "./", outdir::String = "./结果", 阈值...


如何生成带有货币符号(例如 $)而不是货币代码(USD、EUR)的价格字符串?

这是我当前的代码: fun getMonthlyPriceString(yearlyPriceMicros: Long,currencyCode: String): String { val 格式:NumberFormat = NumberFormat.getCurrencyInstance() 格式。


如何返回内在的字符串操作类型?

要返回模板文字类型,需要返回一个模板文字: 输入 HelloSomething = `你好 ${string}` const str = '世界' 函数 sayHello(str: string): HelloSomething { 返回`...


如何防止Xcode重新缩进影响块注释?

在 Xcode 中,假设我在 Swift 文件中有任意一段代码,例如: 静态函数 getDocumentsDirectory() -> URL { let paths = FileManager.default.urls(for: .documentDirectory, in: .


Python 中的 AWS Lambda 函数,生成字符串流

所以我想利用这个.net代码,我在卡盘中接收响应并单独处理每个块 公共异步任务 InvokeLambdaFunctionAsync(string functionName, string pay...


无法将 Generic<string> 转换为 Generic<TArg>,即使我在检查 Generic<string> 是否可分配给 Generic<TArg>

和标题差不多。我有这个代码: if (typeof(Option).IsAssignableTo(typeof(Option))) { 返回新结果(无(),(选项)结果.GetErr(...


在 Android Studio 中找不到错误符号

String sAux=getResources().getString(R.string.ShareText); sAux+=” ”; sAux+="https://play.google.com/store/apps/details?id="; sAux+=getPackageName(); sAux+=” ”; ...


swift wkwebview httponly cookies 设置值

在wkwebview中我们可以设置cookie的httponly值吗?我们有什么办法可以快速做到这一点吗? 如果让 newCookie = HTTPCookie(属性: [ .域名:&qu...


JSON API 错误-无法读取数据,因为它丢失。- 在 iOS 中,swift

我有 JSON 数据字符串结构,例如, 数据: { “项目”: [ { “种类”:“自定义搜索#结果”, "title": "XHAOYEAHX 40,60,110,150pcs鞋C...


为什么 sonarqube 存在安全问题?

我有以下方法: 公共列表 getZipFileList(String fullPath) 抛出 IOException { logger.debug("====> ZipService: getZipFileList <====");


是否可以从zoned_time获取time_point?

我尝试在 std::string 中有选择地获取当地时间/UTC。 我尝试过的: (1) 获取 UTC 的 std::string 使用 std::format 可以正常工作: 自动 utc = std::chrono::system_clock::now(); std::字符串...


SwiftUI:ui 插槽和插槽道具?

我从 Swift(来自前端)开始测试项目,并对视图和视图构建器有疑问 供参考:在前端框架Vue.js中有一个槽和槽的概念


如何在 Groovy 中声明字符串数组?

如何在 Groovy 中声明字符串数组?我正在尝试如下但它抛出一个错误 def String[] osList = new String[] 行中没有数组构造函数调用的表达式: 我在做什么...


通过更少的 Java API 调用来映射 Google 云端硬盘内容的有效方法

大家好,我有一个代码,用于列出共享驱动器中存在的文件(以便稍后下载并创建相同的文件夹路径) 目前我做这样的事情: 哈希映射 大家好,我有一个代码,用于列出共享驱动器中存在的文件(以便稍后下载并创建相同的文件夹路径) 目前我正在做这样的事情: HashMap<String, Strin> foldersPathToID = new HashMap<>(); //searching all folders first saving their IDs searchAllFoldersRecursive(folderName.trim(), driveId, foldersPathToID); //then listing files in all folders HashMap<String, List<File>> pathFile = new HashMap<>(); for (Entry<String, String> pathFolder : foldersPathToID.entrySet()) { List<File> result = search(Type.FILE, pathFolder.getValue()); if (result.size() > 0) { String targetPathFolder = pathFolder.getKey().trim(); pathFile.putIfAbsent(targetPathFolder, new ArrayList<>()); for (File file : result) { pathFile.get(targetPathFolder).add(file); } } } 递归方法在哪里: private static void searchAllFoldersRecursive(String nameFold, String id, HashMap<String, String> map) throws IOException, RefreshTokenException { map.putIfAbsent(nameFold, id); List<File> result; result = search(Type.FOLDER, id); // dig deeper if (result.size() > 0) { for (File folder : result) { searchAllFoldersRecursive(nameFold + java.io.File.separator + normalizeName(folder.getName()), folder.getId(), map); } } } 搜索功能是: private static List<com.google.api.services.drive.model.File> search(Type type, String folderId) throws IOException, RefreshTokenException { String nextPageToken = "go"; List<File> driveFolders = new ArrayList<>(); com.google.api.services.drive.Drive.Files.List request = service.files() .list() .setQ("'" + folderId + "' in parents and mimeType" + (type == Type.FOLDER ? "=" : "!=") + "'application/vnd.google-apps.folder' and trashed = false") .setPageSize(100).setFields("nextPageToken, files(id, name)"); while (nextPageToken != null && nextPageToken.length() > 0) { try { FileList result = request.execute(); driveFolders.addAll(result.getFiles()); nextPageToken = result.getNextPageToken(); request.setPageToken(nextPageToken); return driveFolders; } catch (TokenResponseException tokenError) { if (tokenError.getDetails().getError().equalsIgnoreCase("invalid_grant")) { log.err("Token no more valid removing it Please retry"); java.io.File cred = new java.io.File("./tokens/StoredCredential"); if (cred.exists()) { cred.delete(); } throw new RefreshTokenException("Creds invalid will retry re allow for the token"); } log.err("Error while geting response with token for folder id : " + folderId, tokenError); nextPageToken = null; } catch (Exception e) { log.err("Error while reading folder id : " + folderId, e); nextPageToken = null; } } return new ArrayList<>(); } 我确信有一种方法可以通过很少的 api 调用(甚至可能是一个调用?)对每个文件(使用文件夹树路径)进行正确的映射,因为在我的版本中,我花了很多时间进行调用 service.files().list().setQ("'" + folderId+ "' in parents and mimeType" + (type == Type.FOLDER ? "=" : "!=") + "'application/vnd.google-apps.folder' and trashed = false").setPageSize(100).setFields("nextPageToken, files(id, name)"); 每个子文件夹至少一次......并且递归搜索所有内容需要很长时间。最后,映射比下载本身花费的时间更多...... 我搜索了文档,也在此处搜索,但没有找到任何内容来列出具有一个库的所有驱动器调用任何想法? 我想使用专用的 java API 来获取共享 GoogleDrive 中的所有文件及其相对路径,但调用次数尽可能少。 提前感谢您的时间和答复 我建议您使用高效的数据结构和逻辑来构建文件夹树并将文件映射到其路径,如下所示 private static void mapDriveContent(String driveId) throws IOException { // HashMap to store folder ID to path mapping HashMap<String, String> idToPath = new HashMap<>(); // HashMap to store files based on their paths HashMap<String, List<File>> pathToFile = new HashMap<>(); // Fetch all files and folders in the drive List<File> allFiles = fetchAllFiles(driveId); // Build folder path mapping and organize files for (File file : allFiles) { String parentId = (file.getParents() != null && !file.getParents().isEmpty()) ? file.getParents().get(0) : null; String path = buildPath(file, parentId, idToPath); if (file.getMimeType().equals("application/vnd.google-apps.folder")) { idToPath.put(file.getId(), path); } else { pathToFile.computeIfAbsent(path, k -> new ArrayList<>()).add(file); } } // Now, pathToFile contains the mapping of paths to files // Your logic to handle these files goes here } private static List<File> fetchAllFiles(String driveId) throws IOException { // Implement fetching all files and folders here // Make sure to handle pagination if necessary // ... } private static String buildPath(File file, String parentId, HashMap<String, String> idToPath) { // Build the file path based on its parent ID and the idToPath mapping // ... }


为什么 swift 闭包默认是不可转义的?

我发现默认情况下的快速闭包是非转义闭包,但没有找到任何解释为什么会这样。 谁能解释一下这个吗?


无法从 API 获取访问令牌

我是 Swift 新手,刚刚遇到一个问题。欢迎任何帮助和建议,我也见过 Alomofire,但由于一些错误我无法设置 Alamofire,我也需要 Alam 的帮助...


如何在 macOS 10.12+ 上自定义 NSTableView 标题?

MacOS 10.12+、Xcode 8+、Swift 3: 我想以编程方式自定义 NSTableView 标头的字体和绘图。我知道有关于此的较旧问题,但我找不到任何内容


在 Swift 中,在 try-catch 或 do-catch 中声明的 defer 语句何时执行

defer 语句应该在声明它的块之后执行。如果 defer 语句是在 try-catch 的 try 块或 do-catch 的 do 块内声明的,那么它会


如何使用 Swift 包管理器在 SQLite.swift 中启用 FTS5 支持

我有一个使用 SPM 构建的项目,在其中我使用 SQLite.swift 库 (src)。在我的 Package.swift 文件中,我有以下依赖项: 让包=包( ... 依赖项:[ .


C++:将 std::string 分配给缓冲区数组

在处理必须与 C 代码互操作的代码时,我经常遇到这个问题,其中有一个 std::string ,您需要将其内容复制到普通的 char 缓冲区,如下所示: 结构体T {...


如何在 tvOS (AppleTV) 上运行的视图控制器中设置按钮的初始焦点?

我在 tvOS 的 Swift 游戏中添加了一些按钮。 覆盖 func didMoveToView(视图: SKView) { 让按钮1 = UIButton(框架:CGRectMake(330,800,300,100)) 按钮1(imageBuySelected, forSta...


用于阻塞(CPU 密集)任务的异步函数?

我在 Swift 中有一个缓慢的阻塞函数,我想以非阻塞(异步/等待)方式调用它。 这是原始的阻止代码: // 原来的 func TotalSizeBytesBlocking() -> UInt64 { 变种


在 Swift 中显示带有约束的 UITabBarViewController 的“教程”?

我需要的教程示例: 它是 MYPassthrough 库。 问题是它仅适用于框架,但我需要约束(直接绑定到适当的视图而不进行框架计算) 特...


3D Touch 不适用于 swift 设备

我想在我的应用程序中添加一个需要 3D 触摸的功能,但它说forceTouchCapability 不可用。 我在三个虚拟设备(iPhone 14 - iPhone 14 Pro - iPhone 11)上尝试过,它是好的...


多次异步调用时,Swift 模型视图不会更新@Published var

尝试更新代码以刷新 OAuth 中的令牌后,我无法刷新视图。 我的屏幕: 结构我的屏幕:查看{ @ObservedObject var viewModel = MyViewModel() var body: 一些视图 { ...


UICollectionView - 不在内部滚动,而是在整个屏幕中滚动

我正在用 Swift 构建我的第一个应用程序。我有 RestaurantViewController。屏幕的一半被餐厅名称、描述、标志、atd 填满。 在这下面我有 UICollectionView(),充满


Swift - JSONDecoder 中的内存泄漏

我在 iOS 应用程序解码服务器响应时发现了一些内存泄漏。这些内存泄漏并不总是发生。我正在使用以下代码来解码响应。代码是 insi...


在Combine Swift 中声明初始值后,Sink.receive() 不会被调用

问题: 我在代码示例中使用了 Publisher,该代码示例是我根据此处的代码示例编写的,[https://developer.apple.com/documentation/combine/observableobject][1]。我希望打印声明我...


更改每个案例的 UI 测试区域

我正在使用 swift-snapshot-testing 库进行快照测试。对我来说,使用不同的本地化进行所有测试以在文本更改时检查所有 UI 非常重要。 例如,t...


背景颜色未正确应用

我有这个自定义控件。 公共类面板:ContentView { 公共静态只读 BindableProperty CaptionProperty = BindableProperty.CreateAttached(nameof(Caption), typeof(string),


如何在Swift中访问第二个和第三个元素

嗨,我想显示前三名玩家的分数,但即使可以访问第一个元素,以下代码也不起作用。如果你能帮忙那就太好了。谢谢。 结构


© www.soinside.com 2019 - 2024. All rights reserved.