我有一个名为 var geoLocList = [GeolocationModel]()
的数组和一个名为 var geoLocs = GeolocationModel()
的对象 Severity Code Description Project File Line Suppression State
Error The "LinkAssemblies" task failed unexpectedly.
Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'Android.Gms.Common.Internal.SafeParcel.Zza' (defined in assembly 'Xamarin.GooglePlayServices.Places, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') with scope 'Xamarin.GooglePlayServices.Basement, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. When the scope is different from the defining assembly, it usually means that the type is forwarded. ---> Mono.Cecil.ResolutionException: Failed to resolve Android.Gms.Common.Internal.SafeParcel.Zza
at Mono.Linker.Steps.MarkStep.HandleUnresolvedType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference)
at Mono.Linker.Steps.MarkStep.MarkFields(TypeDefinition type, Boolean includeStatic, Boolean markBackingFieldsOnlyIfPropertyMarked)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
at MonoDroid.Tuner.MonoDroidMarkStep.MarkType(TypeReference reference)
at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
at Mono.Linker.Steps.MarkStep.Initialize()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at Mono.Linker.Pipeline.Process(LinkContext context)
at MonoDroid.Tuner.Linker.Process(LinkerOptions options, ILogger logger, LinkContext& context)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
--- End of inner exception stack trace ---
at Java.Interop.Tools.Diagnostics.Diagnostic.Error(Int32 code, Exception innerException, String message, Object[] args)
at Xamarin.Android.Tasks.LinkAssemblies.Execute(DirectoryAssemblyResolver res)
at Xamarin.Android.Tasks.LinkAssemblies.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() ElGas.Android
后面附加的geoLocs
的值。
问题是,我试图根据相同的ID将geoLocList
中的索引替换为geoLocList
的最新值。
我仍然是iOS应用开发的新手。 老实说,我不太了解下面的代码。我从浏览过的一些参考资料中找到了某个地方,并认为这样做可以成功。但是我错了。
这是代码
geoLocs
答案 0 :(得分:0)
这是一个使用问题中的if
子句的示例,该子句可能会帮助您找到代码中的错误。我是使用Xcode游乐场编写的。
import Cocoa
struct Geo: CustomStringConvertible { //Simple struct used instead of GeolocationModel
var id: Int //Identifier
var text: String
var description: String {. // added for better print() output
return "\(id) - \(text)"
}
}
var geoList = [Geo]()
var geo1 = Geo(id: 1, text: "First")
print("\(geo1) created")
if let index = geoList.index(where: { $0.id == geo1.id }){
geoList.remove(at: index)
print("geo removed")
}
geoList.append(geo1)
print("List contains: \(geoList)")
var geo2 = Geo(id: 1, text: "Second")
print("\(geo2) created")
if let index = geoList.index(where: { $0.id == geo2.id }){
geoList.remove(at: index)
print("geo removed")
}
geoList.append(geo2)
print("List contains: \(geoList)")
运行此命令时的输出是
1-首次创建
列表包含:[1-第一]
1-第二次创建。
已删除地理位置
列表包含:[1-第二]。