backwards-compatibility

PHP date_parse_from_format( ) alternative in PHP 5.2

强颜欢笑 提交于 2019-12-30 05:04:52
问题 Since date_parse_from_format( ) is available only in PHP 5.3, I need to write a function that mimics its behaviour in PHP 5.2. Is it possible to write this function for PHP 5.2 and make it work exactly the same way that it does in PHP 5.3? Example: For this input: <?php $date = "6.1.2009 13:00+01:00"; print_r(date_parse_from_format("j.n.Y H:iP", $date)); ?> I need this output: Array ( [year] => 2009 [month] => 1 [day] => 6 [hour] => 13 [minute] => 0 [second] => 0 [fraction] => [warning_count]

Check for availability of blocks at runtime on iOS

我与影子孤独终老i 提交于 2019-12-30 04:44:03
问题 I need to test for the availability of blocks at runtime, so I can handle backwards compatibility with iOS 3. Any tips? edit: So far I'm doing if (!NSClassFromString(@"NSBlockOperation")) {...} Seems to be working... 回答1: You will also need to make sure to weak link the libSystem.B.dylib , set your base SDK to 4.0 and deployment target to 3.1.3, as described here. A good overview on how to deal with iOS versioning issues can also be found in this this Cocoa with Love article: Tips & Tricks

Weak Linking - check if a class exists and use that class

帅比萌擦擦* 提交于 2019-12-27 11:02:07
问题 I'm trying to create a universal iPhone app, but it uses a class defined only in a newer version of the SDK. The framework exists on older systems, but a class defined in the framework doesn't. I know I want to use some kind of weak linking, but any documentation I can find talks about runtime checks for function existence - how do I check that a class exists? 回答1: TLDR Current: Swift : if #available(iOS 9, *) Obj-C, iOS : if (@available(iOS 11.0, *)) Obj-C, OS X : if (NSClassFromString(@

Weak Linking - check if a class exists and use that class

廉价感情. 提交于 2019-12-27 11:01:25
问题 I'm trying to create a universal iPhone app, but it uses a class defined only in a newer version of the SDK. The framework exists on older systems, but a class defined in the framework doesn't. I know I want to use some kind of weak linking, but any documentation I can find talks about runtime checks for function existence - how do I check that a class exists? 回答1: TLDR Current: Swift : if #available(iOS 9, *) Obj-C, iOS : if (@available(iOS 11.0, *)) Obj-C, OS X : if (NSClassFromString(@

Python 2 and 3 csv module text-binary mode backwards compatibility

落花浮王杯 提交于 2019-12-26 01:08:20
问题 I would like to create a code which is Python 2.7-3.6 compatible I am trying to fix a problem with the csv module where initially I used outfile=open('./test.csv','wb') in Python 2.7 now I have to use outfile=open('./test.csv','w') like in this question otherwise I will incur in a TypeError: a bytes-like object is required, not 'str' . A the moment I am fixing it using this code: import sys w = 'w' if sys.version_info[0] < 3: w = 'wb' # Where needed outfile=open('./test.csv',w) Not very nice,

Python 2 and 3 csv module text-binary mode backwards compatibility

泪湿孤枕 提交于 2019-12-26 01:07:38
问题 I would like to create a code which is Python 2.7-3.6 compatible I am trying to fix a problem with the csv module where initially I used outfile=open('./test.csv','wb') in Python 2.7 now I have to use outfile=open('./test.csv','w') like in this question otherwise I will incur in a TypeError: a bytes-like object is required, not 'str' . A the moment I am fixing it using this code: import sys w = 'w' if sys.version_info[0] < 3: w = 'wb' # Where needed outfile=open('./test.csv',w) Not very nice,

Trying to make iOS 13 project compatible with iOS 12

两盒软妹~` 提交于 2019-12-25 17:37:51
问题 I am trying to make an Xcode project that was set up for iOS 13 work with a target of iOS 10 or even 12. I'm using Xcode 10 for Swift 3 compatibility. According to the advice here: Xcode 11 backward compatibility I have added @available(iOS 13.0, *) in the places it was recommended to add it, and I have also declared var window : UIWindow? in the AppDelegate class. // MARK: UISceneSession Lifecycle @available(iOS 13.0, *) func application(_ application: UIApplication,

Trying to make iOS 13 project compatible with iOS 12

风格不统一 提交于 2019-12-25 17:37:27
问题 I am trying to make an Xcode project that was set up for iOS 13 work with a target of iOS 10 or even 12. I'm using Xcode 10 for Swift 3 compatibility. According to the advice here: Xcode 11 backward compatibility I have added @available(iOS 13.0, *) in the places it was recommended to add it, and I have also declared var window : UIWindow? in the AppDelegate class. // MARK: UISceneSession Lifecycle @available(iOS 13.0, *) func application(_ application: UIApplication,

Checking whether UI_USER_INTERFACE_IDIOM exists at runtime

泄露秘密 提交于 2019-12-24 10:45:39
问题 I am working on a universal app that should be able to run on iPad and iPhone. The Apple iPad docs say to use UI_USER_INTERFACE_IDIOM() to check if I am running on iPad or iPhone, but our iPhone is 3.1.2 and will not have UI_USER_INTERFACE_IDIOM() defined. As such, this code breaks: //iPhone should not be flipped upside down. iPad can have any - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)

Backwards compatibility when changing base class

一曲冷凌霜 提交于 2019-12-24 09:27:35
问题 In .NET, do I maintain binary compatibility when I set a new base class for a class that earlier didn't have any base class (inherits from System.Object)? 回答1: A quick test suggests it's okay, but personally I'd be very nervous of doing this without recompilation. You would basically be in a state which you couldn't reproduce from source code without going through the same steps - build the library, build the calling code, change the library, rebuild just the library code. Behaviour can