寻找方法或图书馆这样的事情:
GameObject nextBrotherNode= gameObject.transform.getNextSibling();
Run Code Online (Sandbox Code Playgroud) 我发现了类似的问题,但是-containsObject没有像我期望的那样工作.
我的问题是NSMutableArray -containsObject当它不应该,当尝试生成随机的UNIQUE颜色并添加到数组时,该方法返回true.
检查是否NSMutableArray包含具有相同值的对象的最佳方法是什么.
NSMutableArray *color_arr=[NSMutableArray array];
UIColor *t;
for(int i=0; i<100; i+=1)
{
int r = arc4random()%256;
int g = arc4random()%256;
int b = arc4random()%256;
t=[UIColor colorWithRed:r green:g blue:b alpha:255];
if (![color_arr containsObject:t])
[color_arr addObject:t];
//[t release];//is t need to be released here on non-arc project? well Im not sure.
}
NSLog(@"total:%d",[color_arr count]);
Run Code Online (Sandbox Code Playgroud)
NSLog()总说数组数为1. 我在下面得到了一个测试代码.
(通过这个例子,我遇到了一个接口,如果没有保留就不能静态分配.)
通过这个代码块,我理解了真正保留的是什么.
我想确定是否会泄漏,我应该在其他地方发布它.我根本不想每次重新初始化阵列.并使其静止.(内存不利但速度有利)
我应该在某处释放这个保留的静态数组吗?它是一个安全的代码还是我完全删除静态和保留单词,并且只是使用arrayObjects方法通常使用init?那么你更喜欢我?
-(NSUInteger)getCoordYByX:(int)ax
{
NSUInteger ret_=-1;
static NSArray *coordsX=nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
coordsX=[[NSArray arrayWithObjects:
[NSNumber numberWithInt:50],
[NSNumber numberWithInt:170],
[NSNumber numberWithInt:190],
[NSNumber numberWithInt:210],
[NSNumber numberWithInt:350],
nil]retain];
/*it is more longer. cropped for test purposes*/
});
ret_=[[coordsX objectAtIndex:ax] unsignedIntegerValue];
return ret_;
Run Code Online (Sandbox Code Playgroud)
}
我想不要在Xcode5中的try块停止调试器.只是看起来像(如果发生任何错误,忽略此行/忽略此行的调试器)
@try {
//this line sometimes throws EXC_BAD_ACCESS error
a = [object1 isKindOfClass:[MyClass class]];
}
@catch(NSException *ex)
{
continue;
}
Run Code Online (Sandbox Code Playgroud) 我是一个经典的程序员,是泛型新手,这是一个asp.net MVC5示例应用程序,用于学习使用流畅的migrator lib集成授权(用户/角色)的目的。我想在创建表时将一些示例数据添加到表中(使用迁移器控制台工具)。
收到编译错误:USERNAME在当前上下文中不存在,
我应该添加到using部分或任何以下示例中:Insert.IntoTable方法?
(谢谢)
namespace SampleApp.Migrations
{
[Migration(1)]
public class AuthMigrations:Migration
{
public override void Up()
{
Create.Table("users").
WithColumn("ID").AsInt32().Identity().PrimaryKey().
WithColumn("USERNAME").AsString(128).
WithColumn("EMAIL").AsCustom("VARCHAR(128)").
WithColumn("PASSWORD_HASH").AsString(128);
Create.Table("roles").
WithColumn("ID").AsInt32().Identity().PrimaryKey().
WithColumn("NAME").AsString(128);
Create.Table("role_users").
WithColumn("ID").AsInt32().Identity().PrimaryKey().
WithColumn("USER_ID").AsInt32().ForeignKey("users", "ID").OnDelete(Rule.Cascade).
WithColumn("ROLE_ID").AsInt32().ForeignKey("roles", "ID").OnDelete(Rule.Cascade);
//Error:The name 'USERNAME' does not exist in the current context
Insert.IntoTable("users").Row(new { USERNAME:"superadmin",EMAIL:"superadmin@mvcapp.com",PASSWORD_HASH:"dfgkmdglkdmfg34532+"});
Insert.IntoTable("users").Row(new { USERNAME:"admin",EMAIL:"admin@mvcapp.com",PASSWORD_HASH:"dfgkmdglkdmfg34532+"});
}
public override void Down()
{
Delete.Table("role_users");
Delete.Table("roles");
Delete.Table("users");
}
}
Run Code Online (Sandbox Code Playgroud)
和
namespace SampleApp.Models
{
public class User
{
public virtual int Id { get; set; }
public virtual string Username …Run Code Online (Sandbox Code Playgroud) fluent-nhibernate fluent-migrator fluent-nhibernate-mapping asp.net-mvc-5
我试图设置长度并初始化一个类的向量成员.但似乎唯一可能的是,初始化行是不合适的.你喜欢哪个 ?(谢谢)
//a vector, out of class set size to 5. initilized each value to Zero
vector<double> vec(5,0.0f);//its ok
class Bird{
public:
int id;
//attempt to init is not possible if a vector a class of member
vector<double> vec_(5, 0.0f);//error: expected a type specifier
}
Run Code Online (Sandbox Code Playgroud) 得到了一个名为GeneralUtils.m的文件及其头文件.我在几个IOS项目中使用它作为共享方法.
问题:一些项目正在编制成功.但是其中一个项目在编译时抛出错误:比我将m文件扩展名更改为mm文件.顺便说一句;顺便说一下;其他项目不再编译和重命名,再次将mm扩展为"m".
我想了解逻辑.为什么我的一些IOS项目希望它的扩展名为m而另一个希望它作为mm文件扩展名
错误详情 :
Undefined symbols for architecture armv7:
"randIntBetween(int, int)", referenced from:
-[Blah method1] in File1.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud) objective-c ×3
c++ ×2
contains ×1
initializer ×1
ios ×1
iphone ×1
memory-leaks ×1
nextsibling ×1
nsarray ×1
static ×1
try-catch ×1
vector ×1
xcode ×1