The documentation says it's available in MacOS 1.08.
So what's the story? What about for iOS5?
It's a very important selector because self[5] will actually turn into [self objectAtIndexedSubscript:5] unless I am missing something.
Doesn't work in NSOrderedSet but works in NSArray.
What am I missing?
While objectAtIndexedSubscript: is not available previous to iOS 6, NSArray and NSDictionarysubscripting is available. That means that you can use syntax like this:
myArray[2] = #"thingie";
myDictionary[#"roger"] = #"barry";
And it will deploy back to iOS 4.
However NSOrderedSet subscripting will not work on iOS 5 and previous. For that, you will need to provide a category that redirects objectAtIndexedSubscript: calls to objectAtIndex:.
Addendum: Apple's docs for NSMutableOrderedSet are also incorrect. It states that index subscripting does an insert, when in reality is does a replace (as one would expect).
No, only since iOS 6 unfortunately.
Apple has separate documentations for the OS X and the iOS APIs. You have to check the right one: objectAtIndexedSubscript:.
Availability
Available in iOS 6.0 and later.
If you need your code to run on iOS 5, you'll need to replace
myOrderedSetOfHilariousAcronyms[2] = #"ROFL";
with
[myOrderedSetOfHilariousAcronyms setObject:#"ROFL" atIndex:2];
I look at the NSOrderedSet.h file and I saw this:
- (id)objectAtIndexedSubscript:(NSUInteger)idx NS_AVAILABLE(10_8, 6_0);
So it doesn't work for IOS5.
Related
According to the documentation UIUserNotificationActionContext has been deprecated on iOS 10 and according to the deprecation message we should Use UserNotifications Framework's -[UNNotificationCategory actions] or -[UNNotificationCategory minimalActions]
The problem is that minimalActions does not exist as a property in UNNotificationCategory, according to both the documentation and the header file (Funnily, a relevant page documenting minimalActions exists without being linked by anything else). So the question is, how does one set the minimal actions in iOS 10 beta 8? What am I missing here?
The minimalActions property of UNNotificationCategory existed in earlier betas, but I'm afraid it was removed in Xcode 8 beta 3, which explains why nothing links to that minimalActions page any more. Instead, set the regular actions property, and iOS will either show up to four or the first two depending on the context.
I use Swift classes in my old Objective-C project. When debugging the swift codes called from objective-c I find that Xcode debugger can't show the value of [AnyObject].
If I change the array type to a specific type, say [String], the debugger can then show the values. So I feel this may be a swift bug. But since I am new to swift I am not so sure. Can anyone cast some light on it? Thanks.
I reported this bug to apple, they let me try Xcode 7.3 beta 5 to see if that fixed the problem. Unfortunately it didn't. So I think I can say for sure that this is a bug.
Update: this bug has been fixed in Xcode 7.3
I'm attempting to use this approach, described by Marco Arment, for checking if a class exists before using it. With the correct settings, classes are automatically weak-linked when it's appropriate. As Marco describes, "you can safely subclass or have pointers to whatever you want (as long as you’re careful not to instantiate them when they’re not available)".
My app runs fine on iOS 5. I've followed the conditions mentioned at the link:
Base SDK is Latest iOS (iOS 5.1)
Deployment Target is iOS 4.0
Compiler for C/C++/Objective-C is Apple LLVM compiler 3.1 (also tried LLVM GCC 4.2)
Any time I reference NSMetadataQuery I'm making sure the class exists first:
if ([NSMetadataQuery class] != nil) …
Despite all this my app crashes immediately on launch if I try to run it on an iPod touch with iOS 4.2.1:
dyld: Symbol not found: _OBJC_CLASS_$_NSMetadataQuery
I've tried commenting out all the code any my app runs fine. As soon as I add back in a single reference to NSMetadataQuery, it crashes. I've even tried this:
if ([NSMetadataQuery class] != nil) NSLog(#"OK");
Simply including that line, and no other reference to NSMetadataQuery, crashes the app. Even more strange, checking for other iOS 5 classes doesn't cause any problems:
if ([UIDictationPhrase class] != nil) NSLog(#"OK");
That works fine, as expected.
I have been able to work around the problem using the uglier NSClassFromString() to make sure the class exists, but I'd love to know why the other approach isn't working.
I don't have an explanation to this but I ran into the same problem as you. No matter what I/you do, NSMetadataQuery just won't be weak linked...
Refer to this answer, which is really the best one in another question:
https://stackoverflow.com/a/8426591/129202
In short, other auto weak linking seems to work, it's just NSMetadataQuery* that you have to remove from source and replace with id. Instantiate the class with NSClassFromString() etc. No hiccups on other classes like UIDocument however so you can safely use those in the normal sweat free way.
NSMetadataQuery is available in iOS 5.0 and above, so any versions below that has no clue as to what it is. By merely using it in your code, the class name will be added to a symbol table and looked-up when the app launches.
Apparently, my use of Twitter oAuth (token request) doesn't work in iOS 5... how can I keep this code for anything below iOS 5 and use the new Twitter Framework for iOS 5+?
Is it possible to detect iOS versions?
Thanks!
You (almost) never want to query iOS (or even framework) versions. That (usually) means you're solving the wrong problem.
In this case, you really want to know "can I use Twitter.framework?"
Thanks to the magic of weak linking, you can try something like:
if ([TWTweetComposeViewController canSendTweet]) {
// Do something
}
else {
// Use your original code
}
You can also check for lower level framework components, e.g.:
if ([TWRequest class]) {
// Do something
}
else {
// Use your original code
}
(Obviously you will need to link against Twitter.framework and include the requisite headers.)
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0) {
//tweet
}
First and foremost, the other answers are correct-- you should avoid using iOS version number to check if features exist.
HOWEVER: In case you do indeed have a good reason to check iOS version, my all-time favorite answer for checking iOS version number is in this StackOverflow answer. So elegant.
Detect if the Twitter class is in the installed os :
if (NSClassFromString(#"TWTweetComposeViewController")) {
//use Twitter Framework
}
Do not forget to make the Twitter Framework optional in the list of Frameworks.
I'm new to IOS development, sometimes I use a function but ignore its Doc.
So, I may use some functions are only supported on IOS 4 or even IOS 5, but I want to support IOS 3+.
Does it has any way to check if my app support IOS 3+?
I don't want to check line by line, thx.
And BTW, anonymous function like void (^ funcName)(NSString *) is objective-c feature, right? So it is supported on all IOS version, right?
Change your 'Deployment Target' to 3.x to see if any methods you're using aren't supported on that version.
That however is not a substitute for testing on 3.x; so either find a 3.x device or drop support for that version. Also, blocks (the 'anonymous function' you describe) are only available on iOS 4 and above.
If you want to write different sets of code for different version targets, you can use preprocessor directives:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 50000
... 5.x code here ...
#elif __IPHONE_OS_VERSION_MAX_ALLOWED >= 40000
... 4.x code here ...
#else
... 3.x code here ...
#endif
Try running your app on a device running 3.x
by anonymous functions do you mean blocks like:
[self performSomeBlock:^(NSString *smth) {
NSLog(#"%#", smth);
}];
or do you mean just c like definitions (its late so i forgot the legit name)
void doSomething(void *(*func)(NSString *)) {
...
}