foundation

NSPredicate format string doesn't work

怎甘沉沦 提交于 2019-12-22 10:14:08
问题 In my code, I want to check and see if a record already exists, so I know whether to create it or update it. But I ran into a problem. The problem is when I use this: NSPredicate *pred = [NSPredicate predicateWithFormat:@"%@ == %@", ATTRIBUTE_ID, idNumber]; [request setPredicate:pred]; This doesn't work. It always claims no results were found. However, it works just fine when I rewrite it like so: NSExpression *lhs = [NSExpression expressionForKeyPath:ATTRIBUTE_ID]; NSExpression *rhs =

Does NSDictionary's objectForKey: rely on identity or equality?

纵然是瞬间 提交于 2019-12-22 06:49:00
问题 Say I have an object called Person which has the property socialSecurityNumber , and this class overrides the isEqual: method to return true when the social security number properties are equal. And say I've put a bunch of instances of Person into an NSDictionary . If I now instantiate a newPerson object which happens to have the same social security number as one already in the dictionary, and I do [myDictionary objectForKey:newPerson] , will it use the isEqual: and return YES, or will it

Is NSObject class a part of the Objective-C runtime library today (instead of being a Foundation component)?

我的梦境 提交于 2019-12-22 05:58:31
问题 Looking at the Mac OS X 10.8's version of the Objective-C runtime library source code, I noticed that it's got a NSObject.mm file. As its name suggests, it's got the NSObject class implementation, as well as built-in autorelease pool and retain count implementations. However, versions of the ObjC runtime library prior to Mountain Lion's one didn't implement the NSObject class (they didn't have a NSObject.mm file, as you can see at the Mac OS X 10.7's Objective-C runtime library source code,

NSURLSessionConfiguration HTTPAdditionalHeaders not set

一曲冷凌霜 提交于 2019-12-22 05:52:51
问题 Authorization header is set in NSURLSessionConfiguration , however it is not attached to NSURLSessionDataTask . Is this a bug in Foundation framework ? NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration]; [configuration setHTTPAdditionalHeaders:@{@"Authorization":@"123"}]; // Initialize session with NSURLSessionConfiguration NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration]; NSMutableURLRequest *request = [

Popover view for iPhone using XCode 5

醉酒当歌 提交于 2019-12-20 15:25:06
问题 I wanted to reuse the popover for iPhone described in this video which is exactly what I need. The problem is that I couldn't bind a UIViewController property to the popover's UIViewController like in the video. One difference with the video is that it has been made using XCode 4.2 and I'm using XCode 5. So the question is: How to make a popover for iPhone like in the video on XCode 5? Here is the XCode 5 project I am struggling with. 回答1: I figured out a way to get popover to work on iPhone

How to use KVO for UserDefaults in Swift?

吃可爱长大的小学妹 提交于 2019-12-20 10:29:43
问题 I'm rewriting parts of an app, and found this code: fileprivate let defaults = UserDefaults.standard func storeValue(_ value: AnyObject, forKey key:String) { defaults.set(value, forKey: key) defaults.synchronize() NotificationCenter.default.post(name: Notification.Name(rawValue: "persistanceServiceValueChangedNotification"), object: key) } func getValueForKey(_ key:String, defaultValue:AnyObject? = nil) -> AnyObject? { return defaults.object(forKey: key) as AnyObject? ?? defaultValue } When

Is there a constant for the maximum CGFloat value?

无人久伴 提交于 2019-12-20 10:16:08
问题 I need to create a CGSize to compute text height of an arbitrary text with arbitrary length. UIKit has this nice method -sizeWithFont:constrainedToSize: and my text is only constrained in width, but not in height. For this, I need to set the maximum possible CGFloat for the height. Is there a constant like "CGFloatMax"? 回答1: CGGeometry defines: #define CGFLOAT_MAX FLT_MAX 回答2: For those using Swift 2, you should use: CGFloat.max For those using Swift 3, you should use: CGFloat

How does one use NSDateFormatter's isLenient option?

时光毁灭记忆、已成空白 提交于 2019-12-20 04:26:08
问题 I can't seem to find any info on this flag, on StackOverflow or elsewhere on the web. Apple's own documentation only says: If a formatter is set to be lenient, when parsing a string it uses heuristics to guess at the date which is intended. As with any guessing, it may get the result date wrong (that is, a date other than that which was intended). Maybe I'm misunderstanding how this is supposed to work, but I can't get it to work at all. My guess was something like this (with a relatively

Dynamically accessing local variables in Objective-C runtime

可紊 提交于 2019-12-20 03:14:13
问题 When attached to the debugger via Xcode, LLDB provides a useful view of local variables (the bottom left of the screenshot): I found an LLDB command frame variable (and gdb's info locals ) that provides a list of the local variables (as seen in the right side of the screenshot above). My hope is that this functionality is possible to perform on the device at runtime. For example, I can access the stack trace using backtrace_symbols() , the current selector via _cmd , and a few others. Has

How to create multiple Local Notifications

馋奶兔 提交于 2019-12-19 10:08:57
问题 I'm trying to create multiple local notifications, in my app, but for some reason only the First Notification Pop's up, the rest just does not work, this is my code. I have a class named criaAlertas , which is responsible for creating the notifications, in that class i have the following method: -(void)setarNotificacao:(NSInteger)quando nome:(UILocalNotification *)notification { UIApplication *myapp = [UIApplication sharedApplication]; notification.fireDate = [NSDate