为NSOperationQueue创建一个Setter

时间:2017-11-26 22:41:20

标签: objective-c cocoa setter getter

我必须创建一个原子的[INFO] Error stacktraces are turned on. [INFO] Scanning for projects... [WARNING] [WARNING] Some problems were encountered while building the effective model for synchroProject:synchroProject:war:0.0.1-SNAPSHOT [WARNING] 'build.plugins.plugin.(groupId:artifactId)' must be unique but found duplicate declaration of plugin org.apache.maven.plugins:maven-compiler-plugin @ line 27, column 15 [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 1 resource [INFO] [INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ synchroProject --- [INFO] Changes detected - recompiling the module! [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! [INFO] Compiling 3 source files to C:\Users\anonyme\eclipse-workspace\synchroProject\target\classes [INFO] ------------------------------------------------------------- [ERROR] COMPILATION ERROR : [INFO] ------------------------------------------------------------- [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[15,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[16,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[21,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[22,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[21,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[22,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[29,6] cannot find symbol symbol: class NotNull location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[32,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[35,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[50,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[37,6] cannot find symbol symbol: class NotNull location: class com.sagemcom.tn.entities.PersonneGroupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[40,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.PersonneGroupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[49,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.PersonneGroupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[52,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.PersonneGroupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[37,6] cannot find symbol symbol: class NotNull location: class com.sagemcom.tn.entities.Groupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[40,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.Groupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[43,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.Groupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[46,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.Groupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[52,6] cannot find symbol symbol: class Size location: class com.sagemcom.tn.entities.Groupe [INFO] 22 errors [INFO] ------------------------------------------------------------- [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.259 s [INFO] Finished at: 2017-11-26T23:23:30+01:00 [INFO] Final Memory: 14M/211M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project synchroProject: Compilation failure: Compilation failure: [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[15,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[16,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[21,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[22,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[21,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[22,36] package javax.validation.constraints does not exist [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[29,6] cannot find symbol [ERROR] symbol: class NotNull [ERROR] location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[32,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[35,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[38,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[41,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[44,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Personne.java:[50,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Personne [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[37,6] cannot find symbol [ERROR] symbol: class NotNull [ERROR] location: class com.sagemcom.tn.entities.PersonneGroupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[40,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.PersonneGroupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[49,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.PersonneGroupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/PersonneGroupe.java:[52,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.PersonneGroupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[37,6] cannot find symbol [ERROR] symbol: class NotNull [ERROR] location: class com.sagemcom.tn.entities.Groupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[40,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Groupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[43,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Groupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[46,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Groupe [ERROR] /C:/Users/anonyme/eclipse-workspace/synchroProject/src/com/sagemcom/tn/entities/Groupe.java:[52,6] cannot find symbol [ERROR] symbol: class Size [ERROR] location: class com.sagemcom.tn.entities.Groupe [ERROR] -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project synchroProject: Compilation failure at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288) at org.apache.maven.cli.MavenCli.main(MavenCli.java:199) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1161) at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:168) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207) ... 20 more [ERROR] [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

NSOperationQueue

我有这个吸气剂:

@property (atomic, strong) NSOperationQueue *queue;

但是Xcode说我必须创建一个setter。

我的这个案子应该怎么做?我不知道。

2 个答案:

答案 0 :(得分:2)

两个观察结果:

  1. 如果你要定义自己的setter,它可能看起来像:

    - (void)setQueue:(NSOperationQueue *)queue {
        _queue = queue; 
    }
    

    请记住,如果同时实施两种访问方法(setter和getter),则必须手动合成ivar,例如:

    @synthesize queue = _queue;
    

    @implementation中,因为编译器无法再安全地假设您需要特定名称的ivar。

  2. 您应该重新审视这应该是atomic还是nonatomic。你的getter不是atomic(也不是我的示例设置器),所以你可能只想制作这个nonatomic。成为atomic"意味着合成访问器确保始终通过getter方法完全检索值或通过setter方法完全设置,即使从不同的线程同时调用访问器也是如此。 (来自Programming with Objective-C: Properties are atomic by default)。您通常不需要原子访问器方法,但如果您这样做,您将更改这些实现以进行相应的同步(例如,使用NSLock@synchronized指令,串行队列,读写器模式等)。

    请注意,如果您已将其设为nonatomic,那么您也无需为自定义getter编写自定义setter。如果您为atomic属性实现了自己的getter,则编译器无法合成相应的atomic setter,因为它无法知道如何将其setter与getter同步(因为有很多不同的可能)同步机制)。但是如果你创建你的属性nonatomic,那里不需要同步,编译器可以为你合成简单的,不同步的setter,并且指示你实现setter的警告也会消失。

    < / LI>

答案 1 :(得分:1)

首先,您声明了属性&#34; queue&#34;是一个读/写属性。这没有意义。你真的不希望每个人都分配到#34;队列&#34;。

其次,您将该属性声明为&#34; atomic&#34;。你要么读到&#34; atomic&#34;是的,或者你只是相信我,这是非常罕见的,它是有用的。手写的getter或setter总是非原子的。所以你有一个非原子的getter,并且因为属性本​​身是一个原子读/写属性,你有一个自动生成的原子的setter。您不能将非原子吸气剂与原子设定器结合使用,反之亦然。

如何解决:将属性更改为非原子和只读。一个副作用是你丢失了_queue支持变量(如果实现了所有必需的访问器,你就不会得到支持变量),所以你必须自己声明_queue。