属性“public”只能在非本地范围内使用

时间:2015-01-29 01:40:59

标签: xcode cordova swift compiler-errors

这里出现了一个非常技术性的错误,谷歌没有发现这一点。

我将Cordova添加到Swift项目中。

我添加了一个Bridging Header文件和Cordova构建依赖项,我确实自动完成了工作(Cordva CDV类已自动完成)。

一切正常,直到我突然遇到这个错误:

Attribute 'public' can only be used in a non-local scope

我的项目随处可见错误。我的许多功能也停止了工作。

enter image description here

对于发生的事情或我可以做些什么来修复的任何建议都将非常感激

2 个答案:

答案 0 :(得分:36)

对于未来的读者:

我同意Nate Cook对该问题的分析,但是我的编译器抛出了这个错误,因为我在文件中错过了大括号(public var URLRequest: NSURLRequest)。例如,缺少交换机中默认语句后的大括号。在这种情况下,它会在public enum MyEnum: SomeProtocol { var someVariable { switch self { case .first: return something default: return default } // <------- needs brace here public var URLRequest: NSURLRequest { // Code here. } } 行上抛出错误:

<!doctype html>
<html class="no-js">
  <head>
    <meta charset="utf-8">
    <title>Slackchat</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/>
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory -->
    <!-- build:css(.) styles/vendor.css -->
    <!-- bower:css -->
    <link rel='stylesheet' href='bower_components/semantic-ui/dist/semantic.css' />
    <!-- endbower -->
    <!-- endbuild -->
    <!-- build:css(.tmp) styles/main.css -->
    <link rel="stylesheet" href="styles/main.css">
    <!-- endbuild -->
    <link href='https://fonts.googleapis.com/css?family=Roboto:400,900,700,300,100' rel='stylesheet' type='text/css'>
  </head>
  <body ng-app="slackerchat">
    <!--[if lt IE 7]>
      <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p>
    <![endif]-->
  <div class="ui right vertical inverted labeled icon sidebar menu" id="sidebar">
      <a class="item" href="#/">
        <i class="home icon"></i>
        Home
      </a>
      <a class="item" href="#/login">
        <i class="sign in icon large"></i>
        Sign in
      </a>
      <a class="item" href="#/register">
        <i class="add user icon"></i>
        Register
      </a>
      <a class="item" ng-click="logout()">
        <i class="sign out icon large"></i>
        Sign out
      </a>
    </div>
    <div class="pusher">




  <div class="ui padded grid">
  <div class="sixteen wide column row button raised" id="header-desktop">
      <div class="three wide column" id="logo-column">
        <a href="#/home"><img class="ui medium image left floated" id="logo-home" src="images/logo.svg" alt="slackerchat"></a>
        <a href="#/home"><img class="ui medium image left floated" id="logo-hash" src="images/logo-hash.svg" alt="slackerchat"></a>
        <div class="item" id="channel-dropdown">
          <div class="ui top right pointing dropdown">
            <div class="header">
              <h1 style="color:black;">{{ messagesCtrl.channelName }}</h1>
            </div>
            <div class="menu">
              <div class="item"><i class="user icon"></i><a href="#">Profile</a></div>
              <div class="item"><i class="users icon"></i><a href="#">Followers</a></div>
              <div class="item"><i class="unhide icon"></i><a href="#">Following</a></div>
              <div class="item"><i class="setting icon"></i><a href="#/Settings">Settings</a></div>
              </div>
          </div>
        </div>
      </div>
      <div class="thirteen wide column" id="menu-container">
          <div class="ui list">
              <div class="ui large icon toggle button right floated">
                  <i class="content icon big"></i>
              </div>
          </div>
      </div>-->
    </div>
  </div>


  <ui-view></ui-view>



  </div>


    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID -->
     <script>
       !function(A,n,g,u,l,a,r){A.GoogleAnalyticsObject=l,A[l]=A[l]||function(){
       (A[l].q=A[l].q||[]).push(arguments)},A[l].l=+new Date,a=n.createElement(g),
       r=n.getElementsByTagName(g)[0],a.src=u,r.parentNode.insertBefore(a,r)
       }(window,document,'script','//www.google-analytics.com/analytics.js','ga');

       ga('create', 'UA-XXXXX-X');
       ga('send', 'pageview');
    </script>

    <!-- build:js(.) scripts/vendor.js -->
    <!-- bower:js -->
    <script src="bower_components/jquery/dist/jquery.js"></script>
    <script src="bower_components/angular/angular.js"></script>
    <script src="bower_components/firebase/firebase.js"></script>
    <script src="bower_components/angularfire/dist/angularfire.js"></script>
    <script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
    <script src="bower_components/angular-md5/angular-md5.js"></script>
    <script src="bower_components/semantic-ui/dist/semantic.js"></script>
    <!-- endbower -->
    <!-- endbuild -->

    <!-- build:js({.tmp,app}) scripts/scripts.js -->
    <script src="app.js"></script>
    <script src="auth/auth.controller.js"></script>
    <script src="auth/auth.service.js"></script>
    <script src="users/users.service.js"></script>
    <script src="users/profile.controller.js"></script>
    <script src="channels/channels.controller.js"></script>
    <script src="channels/channels.service.js"></script>
    <script src="channels/messages.service.js"></script>
    <script src="channels/messages.controller.js"></script>
    <!-- endbuild -->

  <!-- SEMANTIC MODAL DROPDOWN -->
  <script>
    $('.dropdown').dropdown({
        // you can use any ui transition
        transition: 'drop'
    });
  </script>

  <script>
    $('.right.sidebar').first()
      .sidebar('setting', 'transition', 'uncover')
      .sidebar('attach events', '.toggle.button')
      .sidebar('attach events', '.menu .item')
    ;
  </script>

</body>
</html>

答案 1 :(得分:7)

如果在嵌套在函数内的类型上声明了public,或者在该上下文中声明的方法类型只有本地范围,则会出现该错误,因此无法将其标记为公共。例如:

func foo() {
    public struct Bar {        
    }
}
// Attribute 'public' can only be used in a non-local scope