问题描述
我有这行代码,但是它是swift的较旧版本,并且我听说语法已更改。代码如下。在Xcode 11中告知其当前语法将非常有帮助。
我也对变化进行了很多研究,但找不到任何东西
dispatchQueue.main.async中的代码是较旧的,我需要更新的语法
语法(从旧版本开始)如下:
private void addProjectLibrary(IJavaProject project,File lib) throws IOException,URISyntaxException,MalformedURLException,CoreException {
// copy the jar file into the project
InputStream jarLibraryInputStream = new BufferedInputStream(new FileInputStream(lib));
IFile libFile = project.getProject().getFile(lib.getName());
libFile.create(jarLibraryInputStream,false,ipm);
// create a classpath entry for the library
IClasspathEntry relativeLibraryEntry = new org.eclipse.jdt.internal.core.ClasspathEntry(
IPackageFragmentRoot.K_BINARY,IClasspathEntry.CPE_LIBRARY,libFile.getLocation(),ClasspathEntry.INCLUDE_ALL,// inclusion patterns
ClasspathEntry.EXCLUDE_NONE,// exclusion patterns
null,null,// specific output folder
false,// exported
ClasspathEntry.NO_ACCESS_RULES,// no access rules to combine
ClasspathEntry.NO_EXTRA_ATTRIBUTES);
// add the new classpath entry to the project's existing entries
IClasspathEntry[] oldEntries = project.getRawClasspath();
IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
System.arraycopy(oldEntries,newEntries,oldEntries.length);
newEntries[oldEntries.length] = relativeLibraryEntry;
project.setRawClasspath(newEntries,ipm);
}
解决方法
您必须导入NotificationCenter
,它将为:
DispatchQueue.main.async {
NotificationCenter.default.post(name: Name Here,object: nil or Any)
}