我很好奇为什么像CGRectMake和CGPointMake这样的函数存在并被广泛使用.相反,你可以这样做:
(CGRect){{x, y}, {width, height}}
Run Code Online (Sandbox Code Playgroud)
肯定这是更有效的(虽然我猜不多)因为没有函数调用?
您还可以设置原点和大小,如:
(CGRect){origin, size}
Run Code Online (Sandbox Code Playgroud)
并作为混合物:
(CGRect){origin, {width, height}}
Run Code Online (Sandbox Code Playgroud)
不使用它的原因是什么,更喜欢Make功能?
iphone cocoa-touch core-graphics objective-c compound-literals
我的应用程序中有很多NSMutableString(差不多10-11); 全部定义为ivar/property
@property (nonatomic, retain) NSMutableString *str1;
Run Code Online (Sandbox Code Playgroud)
我在某处读到,最好对字符串使用"copy".真的吗?如果是,我可以在我的应用程序中替换retain复制并删除dealloc中的版本吗?
我还需要考虑其他一些事情吗?
此外,在1个应用程序中拥有10-11 NSMutableString是正常的吗?我的意思是从内存使用角度来看?我的应用程序中也有4-5个NSMutableDictionary.如果没问题,请告诉我.
我已经看到了两种创建全局变量的方法,有什么区别,你什么时候使用它们?
//.h
extern NSString * const MyConstant;
//.m
NSString * const MyConstant = @"MyConstant";
Run Code Online (Sandbox Code Playgroud)
和
//.h
extern NSString *MyConstant;
//.m
NSString *MyConstant = @"MyConstant";
Run Code Online (Sandbox Code Playgroud) 我的项目包含XMPPFramework,其中包含必须与ARC一起使用的文件.但是我的项目是Non ARC,由于链接到它的某些其他库而无法转换.
如何强制编译器仅在某个类上使用ARC?
为什么必须动态分配Objective-c对象?为什么我必须使它成为指向对象的指针,与C++不同,我可以在堆栈上创建它们?谢谢.
cocoa objective-c-runtime foundation static-allocation dynamic-allocation
我正在开发一个iPhone应用程序,我需要使用JSON它从服务器接收数据.在iPhone方面,我将数据转换为NSMutableDictionary.
但是,日期类型数据为空.
我用下面的句子来读日期.
NSString *arriveTime = [taskDic objectForKey:@"arriveTime"];
NSLog(@"%@", arriveTime);
if (arriveTime) {
job.arriveDone = [NSDate dateWithTimeIntervalSince1970:[arriveTime intValue]/1000];
}
Run Code Online (Sandbox Code Playgroud)
当arrivalTime为null时,如何创建if语句.我试过[到达时间长度]!= 0,但我不工作,因为arriTime是一个NSNull并且没有这个方法.
为另一个互联网论坛引用道歉,但我认为这很有趣,并想问:
如果你放弃编程语言的"安全"功能并避免像STL和Boost这样的东西,C++会更快.在原始字节到字节中,C++更快,但是C再也是如此.
当你添加STL的行李,Boost你比编写好的C#代码慢.C#JIT和Java jit的优点是这些安全功能得到了很好的优化.C++安全功能依赖于编译器的优化.
因此,如果您对STL和Boost代码不小心,那么您将拥有应用程序的跛脚.
我同意消除安全功能,但我看过很多高频工作广告,他们都要求Boost体验.当然,Boost对于生成快速代码不是一件坏事吗?或者这个人仅仅在理论上说明如果你只是在字节级操作它会更快?
编辑:引用是关于STL和Boost,因此我添加了STL标记.
从应用程序主包加载图像的最佳方法是什么.我在用
[UIImage imageNamed: "image.png"];
Run Code Online (Sandbox Code Playgroud)
但我听说这在内存使用和性能方面并不好.任何人都可以提出他/她的反馈意见吗?我的应用程序在发布时从主包中读取大量图像.我想让这个过程尽可能高效.
最好的祝福
我对一些我认为简单的事情有一个非常奇怪的错误.
#import <Foundation/Foundation.h>
#import "ViewController.h"
#import "GameObject.h"
@interface GameController : NSObject
@property (strong) GLKBaseEffect * effect;
@property (strong) NSMutableArray * gameObjects;
@property (strong) NSMutableArray * objectsToRemove;
@property (strong) NSMutableArray * objectsToAdd;
+ (GameController *) sharedGameController;
- (void) tick:(float)dt;
- (void) initializeGame: (ViewController*) viewcontroller;//ERROR: EXPECTED A TYPE
- (void) createObject:(Class) objecttype atPoint:(CGPoint)position;
- (void) deleteObject:(GameObject*) object atPoint:(CGPoint)position;
- (void) manageObjects;
@end
Run Code Online (Sandbox Code Playgroud)
为什么会问'ViewController'是否是一个类型?这是我正确实施的课程.它也被导入了.
编辑*
如果它有帮助,这是ViewController.m类.
#import "ViewController.h"
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[[GameController sharedGameController] initializeGame:self];
}
@end
Run Code Online (Sandbox Code Playgroud)
编辑2 ** …
import objective-c circular-dependency header-files forward-declaration
我正在创建一个协议,我正在定义的方法的参数之一是CMTime*.我想转发声明CMTime,而不是包括它.但是,我试过@class CMTime并且它抱怨它在其他地方重新定义为不同类型的符号.文档说这是一个结构.我已经尝试过将其声明为
struct CMTime;
Run Code Online (Sandbox Code Playgroud)
但它仍在抱怨它不知道它是什么.
我有什么想法我做错了吗?
objective-c ×6
iphone ×4
cocoa-touch ×2
performance ×2
boost ×1
build ×1
c ×1
c++ ×1
cocoa ×1
constants ×1
copy ×1
declare ×1
extern ×1
forward ×1
foundation ×1
header-files ×1
image ×1
import ×1
json ×1
nsbundle ×1
nsnull ×1
stl ×1
struct ×1
xcode ×1
xmpp ×1