我有一个JSON格式的日期字符串,它看起来像这样:2013-05-22T10:54:40.437
而我正在尝试将其转换为NSDate.
- (NSString *)dateFromString:(NSString *)datestring{
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"yyyy'-'MM'-'dd'T'HH':'mm':'ss"];
NSDate *date = [dateFormat dateFromString:datestring];
//date is nil here.
NSDateFormatter *newDateFormatter = [[NSDateFormatter alloc]init];
[newDateFormatter setDateFormat:@"MM/dd/yyyy"];
NSString *newString = [newDateFormatter stringFromDate:date];
NSLog(@"Date -- %@",datestring);
return newString;
}
Run Code Online (Sandbox Code Playgroud)
但是dateFromString之后的日期是零.有谁知道我在这里做错了什么?谢谢!
我有一个使用核心数据框架的应用程序.我工作得很好.我刚刚更改了数据模型 - 将属性添加到一个实体.当我尝试构建它时,我收到一个错误:
duplicate symbol _OBJC_METACLASS_$_AccountFolder in:
/Users/XXX/Library/Developer/Xcode/DerivedData/MyApp-bxsswgxdenxgjweotkkkckaoalat/Build/Intermediates/MyApp.build/Debug-iphoneos/MyApp.build/Objects-normal/armv7/AccountFolder-33D7EA63E98D6090.o
ld: 4 duplicate symbols for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
我做了一些搜索,大多数人得到这个错误是从.h到.m的错误输入,或者多次导入相同的.h.我检查了我的代码.我没有那个.而coredata框架仍然存在.
有谁知道还有什么原因?谢谢.
我昨天更新了我的iphone4s和xcode.我正在尝试在手机上调试我的应用程序,因为我的应用程序使用硬件通信.我正在使用Redpark的第三方库(该公司提供Dock到RS232线.)在编译时,它给出了一个错误
ld: file is universal (2 slices) but does not contain a(n) armv7s slice:/Users/...../libRscMgrUniv.a for architecture armv7s
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Run Code Online (Sandbox Code Playgroud)
有没有人知道如何解决这个问题,除非等待Redpark更新库?
我正试图找到一个旋转的矩形UIView的四个角的坐标.
我认为我可以做的一种方法是使用Recognizer.rotation,找到旋转的角度,然后计算起源.但这需要一些几何计算.
- (IBAction)handlePan:(UIRotationGestureRecognizer*)recognizer {
NSLog(@"Rotation in degrees since last change: %f", [recognizer rotation] * (180 / M_PI));
recognizer.view.transform = CGAffineTransformRotate(recognizer.view.transform, recognizer.rotation);
NSLog(@"%@",recognizer);
recognizer.rotation = 0;
NSLog(@"bound is %f and %f, frame is %f and %f, %f and %f.",recognizer.view.bounds.size.width,recognizer.view.bounds.size.height, recognizer.view.frame.size.width,recognizer.view.frame.size.height, recognizer.view.frame.origin.x, recognizer.view.frame.origin.y);
}
Run Code Online (Sandbox Code Playgroud)
我只是想知道是否有其他更简单的方法来获得坐标?谢谢!
编辑:
看起来我们在这里有一个很好的答案(见下面的答案).我设法通过一种愚蠢的方式计算角落 - 使用旋转角度和几何.它有效,但不容易和轻松.我在这里分享我的代码以防万一有人可能想要使用它(即使我怀疑它.)
float r = 100;
NSLog(@"radius is %f.",r);
float AAngle = M_PI/3+self.rotatedAngle;
float AY = recognizer.view.center.y - sin(AAngle)*r;
float AX = recognizer.view.center.x - cos(AAngle)*r;
self.pointPADA = CGPointMake(AX, AY);
NSLog(@"View Center is (%f,%f)",recognizer.view.center.x,recognizer.view.center.y);
NSLog(@"Point …Run Code Online (Sandbox Code Playgroud)