我的iOS项目中有url
变量,当我在DEBUG模式下构建项目时,我希望它指向http://localhost:3000/api
,但是当我为RELEASE构建项目时,我希望url
变量指向http://example.com/api
所以我已经草拟了以下内容,
#ifdef DEBUG
// want to use this variable on DEBUG build
NSURL *url = [NSURL URLWithString:@"http://localhost:3000/api/"];
#endif
// want to use this variable on RELEASE build
NSURL *url = [NSURL URLWithString:@"http://example.com/api/"];
但是Xcode抱怨说我已经宣布了url
变量。
答案 0 :(得分:4)
您应该在设定值之前定义变量 试试这段代码:
NSURL *url = [NSURL URLWithString:@"http://localhost:3000/api/"];
NSURL *url = [NSURL URLWithString:@"http://example.com/api/"];
答案 1 :(得分:3)
为什么不这样做:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<table ng-app="myApp" ng-controller="myController as ctrl">
<tr ng-repeat="(key, range) in ctrl.vars">
<td ng-switch="ctrl.getTypeOf(range)">
<div ng-switch-when="string">It's a string</div>
<div ng-switch-when="object">It's an object</div>
<div ng-switch-when="number">It's a number</div>
<div ng-switch-when="array">It's an array</div>
<div ng-switch-when="null">It's null</div>
<div ng-switch-when="undefined">It's undefined</div>
<div ng-switch-default>It's something else</div>
</td>
</tr>
</table>
答案 2 :(得分:3)
试
'use strict'
import { task, parallel, series, src, dest, watch, plugins } from './gulp';
import { startStagingServer } from './servers';
import { solution } from './solution.map';
const path = require('path');
task('serve', parallel(startStagingServer, watchStyles);
function watchStyles() {
watch([ solution.src.styles ], series(formatStyles, compileStyles))
}
function formatStyles(done) {
return src([ solution.src.styles ])
.pipe(plugins.csscomb())
.pipe(dest(solution.src.mount)) // the root of the solution
}
function compileStyles() {
return src([ solution.src.styles ])
.pipe(plugins.sass().on('error', plug.sass.logError))
.pipe(dest(path.join(solution.dest.stage, 'serve')));
}
答案 3 :(得分:1)
嗯,你做了宣布它。想一想:这是条件代码。那么,如果定义#ifdef DEBUG
// want to use this variable on DEBUG build
NSURL *url = [NSURL URLWithString:@"http://localhost:3000/api/"];
#else
// want to use this variable on RELEASE build
NSURL *url = [NSURL URLWithString:@"http://example.com/api/"];
#endif
,代码实际上会是什么样子?它看起来像这样:
DEBUG
嗯,这是非法的。