相关疑难解决方法(0)

静态NSDictionary*const letterValues = @ {.....}在一个方法中无法编译

iPhone的文字游戏中:

应用截图

我正在尝试在自定义视图Tile.m中使用以下代码:

- (void)awakeFromNib
{
    [super awakeFromNib];

    static NSDictionary* const letterValues = @{
                                         @"A": @1,
                                         @"B": @4,
                                         @"C": @4,
                                         // ...
                                         @"X": @8,
                                         @"Y": @3,
                                         @"Z": @10,
                                         };

    NSString* randomLetter = [kLetters substringWithRange:[kLetters rangeOfComposedCharacterSequenceAtIndex:arc4random_uniform(kLetters.length)]];
    int letterValue = [letterValues[randomLetter] integerValue];

    _smallLetter.text = _bigLetter.text = randomLetter;
    _smallValue.text = _bigValue.text = [NSString stringWithFormat:@"%d", letterValue];
}
Run Code Online (Sandbox Code Playgroud)

不幸的是,这给了我编译错误Initializer元素不是编译时常量,我必须删除static关键字以使我的应用程序在Xcode中编译(这里全屏):

Xcode截图

我认为我NSDictionary正确地初始化- 使用新的Objective-C Literals语法.

但为什么我不能static在这里使用?

我认为在这里确保我的letterValues常量只设置一次是合适的吗?

static const objective-c nsdictionary ios

13
推荐指数
3
解决办法
2万
查看次数

在Xcode中编译C++类:编译期间出错:stl vector

我有一个C++类,可以在linux上使用gcc和visual studio中的寡妇进行编译.

boid.h:

#ifndef BOID_CLASS_HEADER_DEFINES_H
#define BOID_CLASS_HEADER_DEFINES_H
#include "defines.h"

class Boid {

public:
     // Initialize the boid with random position, heading direction and color
     Boid(float SceneRadius,float NormalVel);

     .....
protected:
     ...
};

#endif
Run Code Online (Sandbox Code Playgroud)

并在boid.cpp中:

#include "Boid.h"

// Initialize the boid with random position, heading direction and color
Boid::Boid(float SceneRadius,float NormalVel) 
{
    ....
}
Run Code Online (Sandbox Code Playgroud)

但是,当我在Xcode中编译此代码时,我收到以下错误:

Compiling Boid.h: "error: vector: No such file or directory"
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我以为你可以使用C/C++代码并在Xcode中编译它而没有问题?

谢谢

编辑:添加了define.h(还将#endif添加到示例中,但是在原始代码中)

编辑2:在评论出几个包括空的时间后,我得到了一个不同的错误:上面的向量错误.

#ifndef BOID_NAV_DEFINES_H
#define BOID_NAV_DEFINES_H
#include <stdlib.h>
#include <vector>
#include "Vector3d.h"
#include "Point3d.h" …
Run Code Online (Sandbox Code Playgroud)

c++ xcode porting

10
推荐指数
2
解决办法
3万
查看次数

在C++程序中访问Apple Magic Trackpad输入数据

我想阅读触控板多点触控手势并将数据协调到我的C++程序中.我在哪里可以找到一些关于这样做的入门教程?

c++ macos trackpad

6
推荐指数
1
解决办法
1432
查看次数

从C/C++扫描BLE设备

"蓝牙设备访问指南",我读过蓝牙API应该可以从C或C++访问.我在IOBluetooth框架中找到了一些与蓝牙相关的C-header(IOBluetoothUserLib.h,Bluetooth.h),它包含用于定义搜索creteria的枚举和数据,但是我找不到任何采用这种枚举或数据结构的函数作为参数.根据文档,我将不得不创建一个CBCentralManager但我找不到从C或C++这样做的方法.

背景:我们使用OS/X作为开发平台,用于开发支持BLE的微控制器.要更新此微控制器上的固件,我想编写一个BLE引导加载程序,我希望有一个命令行客户端来更新固件.所有的代码都是用C++编写的,我不想为这个小任务学习objectiv-C.

任何指针,文档,示例?

谢谢

托斯滕

c macos core-bluetooth bluetooth-lowenergy

6
推荐指数
1
解决办法
3614
查看次数

在 xcode 中找不到 AppDelegate.m

我目前正在尝试将 Facebook SDK 实施到我的 Unity 应用程序中,但我找不到AppDelegate.m我必须修改才能实施 SDK 的内容。

我尝试在我的 Xcode 文件夹中到处搜索,但似乎无处可寻。

我也在谷歌上搜索,但因为我真的对 Xcode 一无所知(除了构建我的 Unity 项目),我也不明白答案......

感谢,并有一个愉快的一天 !

xcode facebook unity-game-engine

5
推荐指数
1
解决办法
8374
查看次数

iOS:使用bitset <100> b是否正确; 在iOS?

是否可以像在C++中一样bitsetiOS中使用?或者我如何bitsetiOS编码中使用?提前致谢!

xcode ios

1
推荐指数
1
解决办法
462
查看次数

如何在 GCC 中编译 Objective C++?

gobjc在 Ubuntu 16.04 中安装了 GNUStep 。我可以像这样编译 Objective-C 代码:

gcc codefile.m `gnustep-config --objc-flags` -lobjc -lgnustep-base -o codefile
Run Code Online (Sandbox Code Playgroud)

但我想在 GCC 中编译 Objective-C++ 代码。我该怎么做?

linux gcc g++ objective-c++

1
推荐指数
1
解决办法
4042
查看次数