小编ATC*_*ger的帖子

从 try{} catch{} 访问变量

我试图在 try{} catch{} 方法之后访问一个变量(特别是一个 ArrayList)。

try 
{
//Here I would import data from an ArrayList if it was already created.
}
catch
{  
//Create new array list if it couldn't find one.
ArrayList items = new ArrayList();
}
Run Code Online (Sandbox Code Playgroud)

以一种或另一种方式,将创建 ArrayList 项目,我希望能够访问它。我之前尝试初始化 ArrayList ,如下所示:

ArrayList items;
try 
{
//Here I would import data from an ArrayList if it was already created.
}
catch
{  
//Create new array list if it couldn't find one.
ArrayList items = new ArrayList();
}
Run Code Online (Sandbox Code Playgroud)

但是我无法在 try{} …

c# scope try-catch

2
推荐指数
1
解决办法
3234
查看次数

Xcode 在非可选字符串上返回 nil

我有一个接收图像和字符串的函数。当我尝试使用 () 功能将字符串放入更长的字符串时,它告诉我在解开可选项时发现 nil。例外它根本不是可选的,它是一个字符串。我可以打印出该值并正确显示。

func UpdateBusiness(logo: UIImage, category: String) {
        guard let bizID = UserDefaults.standard.string(forKey: defaultKeys.businessID) else {return}
        let thisURL = "http://mywebsite.com/api/v0.1/Business/EditBusinessLogoAndCategory?businessID=\(bizID)&category=\(category)"
        let combinedURL = URL(string: thisURL)!
}
Run Code Online (Sandbox Code Playgroud)

创建 URL 会使系统崩溃。我可以在调试器中看到 category 的值,并且我在这个字符串中没有可选项。它怎么能找到零?

null xcode ios swift

0
推荐指数
1
解决办法
57
查看次数

标签 统计

c# ×1

ios ×1

null ×1

scope ×1

swift ×1

try-catch ×1

xcode ×1