我们如何检查字符串是否仅由数字组成.我从字符串中取出一个子字符串,并想检查它是否是一个数字子字符串.
NSString *newString = [myString substringWithRange:NSMakeRange(2,3)];
Run Code Online (Sandbox Code Playgroud) 一般问题:当我没有特定的文件格式,但其他人没有为其定义UTI时,我该如何使用该文件格式?
具体情况:我正在为.torrent和.nzb文件创建一个QuickLook插件.(注意:.nzb文件类似于.torrent文件,除了指向一个bittorrent跟踪器,它们指向一个Usenet服务器.)我希望插件显示.nzb/.torrent文件指向哪些数据,哪些文件如果打开它们将被下载,以及任何其他适用的元数据.为此,我必须为这两种文件类型设置统一类型标识符.虽然.torrent文件有指定的com.bittorrent.torrent UTI,但.nzb文件却没有 - NZB格式是由newzbin.com定义的,它不发布自己的应用程序(因此没有定义Mac OS X.统一类型标识符供我使用).
选项似乎是:
CFBundleTypeExtensions在我的Info.plist文件中使用.这似乎也是错误的,因为不仅仅是CFBundleTypeExtensions根据Apple的文档弃用,但我认为我不能混合使用CFBundleTypeExtensions和LSBundleContentTypes(如果LSBundleContentTypes存在,因为它必须是我使用com.bittorrent.torrent UTI,然后CFBundleTypeExtensions被忽略).在这种情况下做什么是正确的?
我有一个父类
@interface Parent : NSObject
@end
Run Code Online (Sandbox Code Playgroud)
还有一个儿童班
@interface Child : Parent
@end
Run Code Online (Sandbox Code Playgroud)
一般来说,我们可以像这样在父指针中存储子对象
Parent *p = [Child alloc]init];
Run Code Online (Sandbox Code Playgroud)
我很惊讶地知道当我像这样将父对象存储在子指针中时
Child *c = [[Parent alloc] init];
Run Code Online (Sandbox Code Playgroud)
尽管编译器给出了警告“语义错误不兼容的指针”,但是当我运行它时,它就像第一种情况一样。我无法理解为什么运行时允许它工作?
在做Objective-c时,我是否必须编写如下函数:
- (int) someFunction: (int) a someParam: (int) b;
Run Code Online (Sandbox Code Playgroud)
或者我可以使用常规C风格:
void someFunction(int a, int b);
Run Code Online (Sandbox Code Playgroud)
如果我可以做C风格,那么在Objective-C风格中做这个有什么好处吗?
在浏览python手册的 6.4 Packages部分时,我遇到了以下行:
__init__.py需要这些文件使Python将目录视为包含包; 这样做是为了防止具有通用名称的目录(例如字符串)无意中隐藏稍后在模块搜索路径上发生的有效模块.
我知道__init__.py将目录标记为包含包是必需的,但我不明白它的含义prevent directories with a common name...from unintentionally hiding valid modules....
有人可以解释为什么__init__.py需要吗?
我正在开发一个应用程序,它读取图像的地理位置,并允许用户修改此信息并将此数据写回.我使用writeImageDataToSavedPhotosAlbum函数成功读取数据,操作并写入库.问题是,相反更新原始图像,它会创建一个新图像.
我怎么能更换或更新该项目?
[...]
NSMutableDictionary *EXIFDictionary = [[[metadata objectForKey:(NSString *)kCGImagePropertyExifDictionary]mutableCopy]autorelease];
NSMutableDictionary *GPSDictionary = [[[metadata objectForKey:(NSString *)kCGImagePropertyGPSDictionary]mutableCopy]autorelease];
NSMutableDictionary *TIFFDictionray = [[[metadata objectForKey:(NSString *)kCGImagePropertyTIFFDictionary]mutableCopy]autorelease];
Byte *buffer = (Byte*)malloc(representation.size);
NSUInteger buffered = [representation getBytes:buffer fromOffset:0.0 length:representation.size error:nil];
NSData *imageData = [NSData dataWithBytesNoCopy:buffer length:buffered freeWhenDone:YES]; //this is NSData may be what you want
if(!EXIFDictionary) {
//if the image does not have an EXIF dictionary (not all images do), then create one for us to use
EXIFDictionary = [NSMutableDictionary dictionary];
}
if(!GPSDictionary) {
GPSDictionary = [NSMutableDictionary …Run Code Online (Sandbox Code Playgroud) 我尝试过以下方法:
contentScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 600, 400)];
[contentScrollView setContentSize:CGSizeMake(600, 400)];
[contentScrollView addSubview:twitterSigninViewController.view];
[contentScrollView setScrollEnabled:YES];
Run Code Online (Sandbox Code Playgroud)
但是,这不会滚动.为什么是这样?
我是iPhone新手NSTimer.我做了一个秒表.现在我想暂停两次之间的时间,也想暂停休息.我的代码如下.
开始时间:
startDate = [[NSDate date]retain];
stopWatchTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/10.0
target:self
selector:@selector(updateTimer)
userInfo:nil
repeats:YES];
Run Code Online (Sandbox Code Playgroud)
停止时间:
[stopWatchTimer invalidate];
stopWatchTimer = nil;
[self updateTimer];
Run Code Online (Sandbox Code Playgroud)
更新时间:
(void)updateTimer
{
NSDate *currentDate = [NSDate date];
NSTimeInterval timeInterval = [currentDate timeIntervalSinceDate:startDate];
NSDate *timerDate = [NSDate dateWithTimeIntervalSince1970:timeInterval];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"mm:ss"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0.0]];
NSString *timeString=[dateFormatter stringFromDate:timerDate];
stopWatchLabel.text = timeString;
[dateFormatter release];
}
Run Code Online (Sandbox Code Playgroud) 我已经在这个问题上抓了一段时间了,并希望额外的一双眼睛会有所帮助:我得到一个"无法找到'AbstractPickerView'的接口声明,'AttackLayer'的超类.麻烦的是我已导入全部必要的头文件,我唯一能想到的是多级继承
这是接口:
@interface AttackLayer : AbstractPickerView <<< this is the one which gets the error
@interface AbstractPickerView: AbstractLayer <UIPickerViewDelegate>
@interface AbstractLayer : CCLayer
Run Code Online (Sandbox Code Playgroud)
有人能看到这里有什么问题吗?
#import <Foundation/Foundation.h>
#import "AbstractPickerView.h"
@interface AttackLayer : AbstractPickerView
{
CCMenu *buyPowerButton;
CCMenu *finishBuyPower;
id playerUI;
}
-(id) init:(PlayerController *)playerControl withObject:(id)object;
-(void)spendAttack:(id)sender;
-(void)spendResist:(id)sender;
-(void)transferPower:(id)sender;
-(void)timeOut;
-(void)commenceAttack:(id)sender;
-(void)appear;
-(void)buyPower:(id)sender;
-(void)reloadButtons;
-(void)buyPowerButtons;
-(void)cleanUpPicker:(id)sender;
@property(nonatomic,retain)id playerUI;
@property(nonatomic,retain) CCMenu *button2;
@property(nonatomic,retain) CCMenu *button3;
@property(nonatomic,retain) CCMenu *buyPowerButton;
@property(nonatomic,retain) CCMenu *finishBuyPower;
@property(nonatomic,retain)CCMenu *starMenu;
@end
Run Code Online (Sandbox Code Playgroud) objective-c ×6
ios ×4
iphone ×4
cocoa ×2
xcode ×2
alasset ×1
c ×1
cocoa-touch ×1
inheritance ×1
ipad ×1
macos ×1
metadata ×1
nsstring ×1
python ×1
uiscrollview ×1