Giter VIP home page Giter VIP logo

nicklockwood / standardpaths Goto Github PK

View Code? Open in Web Editor NEW
337.0 337.0 50.0 228 KB

StandardPaths is a category on NSFileManager for simplifying access to standard application directories on iOS and Mac OS and abstracting the iCloud backup flags on iOS. It also provides support for working with device-specific file suffixes, such as the @2x suffix for Retina displays, or the -568h suffix for iPhone 5 and can optionally swizzle certain UIKit methods to support these suffixes more consistently.

Home Page: http://charcoaldesign.co.uk/source/cocoa#standardpaths

License: Other

Objective-C 98.97% Rich Text Format 1.03%

standardpaths's People

Contributors

ashton-w avatar nicklockwood avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

standardpaths's Issues

benefits over nsbundle?

i was thinking about using this library but it sort of appears that it is no longer being maintained, so when i went to roll my own solution i found myself wondering why you can't just do something like this and let NSBundle's internals take care of it (swift 3):

func normalizedPathForFile(_ path:String) -> String {
    let base = path.stringByDeletingLastPathComponent()
    let file = path.lastPathComponent().stringByDeletingPathExtension()
    let ext = path.pathExtension()
    return Bundle(path: base)?.path(forResource:file, ofType:ext) ?? path
}

in my testing i put files named "plugin~iphone.xml" and "plugin~ipad.xml" in the documents directory and called it like:
normalizedPathForFile("/full/path/to/documents/dir/plugin.xml")

and it found the correct files on both iphone and ipad

Make swizzling optional

Edit: Doh, this is addressed in the README, but I still think exposing the option in the podspec is good.


It would be nice to make the swizzling on view loading and other places optional.
This could be done with a subspec in the podspec. I'm not sure if the subspec has to include the swizzling, or if it can exclude it.
Alternatively, the swizzling could be tied to a class method to set it all up - but that is a breaking change.

I'm seeing people get confused when they have IBOutlet key-value coding errors in their Interface Builder files and the exception pauses the debugger inside the StandardPaths source code - leading to accusations / rabbit holes before realising the error is in IB.

UI_USER_INTERFACE_IDIOM is not a macro in iOS SDK 8.3

In iOS prior to 8.3:

/* The UI_USER_INTERFACE_IDIOM() macro is provided for use when deploying to a version of the iOS less than 3.2. If the earliest version of iPhone/iOS that you will be deploying for is 3.2 or greater, you may use -[UIDevice userInterfaceIdiom] directly.
 */
#define UI_USER_INTERFACE_IDIOM() ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ? [[UIDevice currentDevice] userInterfaceIdiom] : UIUserInterfaceIdiomPhone)

But in iOS 8.3:

/* The UI_USER_INTERFACE_IDIOM() function is provided for use when deploying to a version of the iOS less than 3.2. If the earliest version of iPhone/iOS that you will be deploying for is 3.2 or greater, you may use -[UIDevice userInterfaceIdiom] directly.
 */
static inline UIUserInterfaceIdiom UI_USER_INTERFACE_IDIOM() {
    return ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)] ?
            [[UIDevice currentDevice] userInterfaceIdiom] :
            UIUserInterfaceIdiomPhone);
}

As a result I can't build ๐Ÿ˜• Errors in StandardPaths.h:

image

iOS version compare in offlineDataPath

I think the iOS version compare in offlineDataPath should be:
if ([[[UIDevice currentDevice] systemVersion] compare:@"5.0.1" options:NSNumericSearch] == NSOrderedAscending)
to allow version older than "5.0.1" to fallback to use /Library/Caches.

NSOrderedAscending == [@"5.0" compare:@"5.0.1" options:NSNumericSearch]
NSOrderedSame == [@"5.0.1" compare:@"5.0.1" options:NSNumericSearch]
NSOrderedDescending == [@"5.0.2" compare:@"5.0.1" options:NSNumericSearch]

requires_arc in podspec

The podspec has the key requires_arc set to false. I'm pretty sure this is wrong.

We don't have a test project integrating via pods. The FileSuffixesTest project has ARC on.

CocoaPods Spec need to be updated

Hi there,

I'm using this library for an AppleTV project and seems the spec on the main Cocoapods for StandardPaths is out of dated, it will be nice if it could be updated.

Offline Data folder for iOS5

Hello,

The docs say that for iOS5 the offlineDataPath will fall back to using Library/Caches/Offline Data.
However in the code it just returns [self cacheDataPath].

Is this a feature of the code or the docs ;-)

Thanks for sharing the code.
Regards,
Steven

Syntax confusion

Hi Nick,
Thanks for sharing this great component! When I read the code,

- (NSString *)temporaryDataPath
{
    static NSString *path;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{

        //temporary directory (shouldn't change during app lifetime)
        path = NSTemporaryDirectory();

        //apparently NSTemporaryDirectory() can return nil in some cases
        if (!path)
        {
            path = [[self cacheDataPath] stringByAppendingPathComponent:@"Temporary Files"];
        }

        //retain path
        path = [[NSString alloc] initWithString:path];
    });

    return path;
}

I don't know why need to add this line

//retain path
path = [[NSString alloc] initWithString:path];

Will you explain it a little bit more?

stringByAppendingScaleSuffix not work with URL's

        NSString *url = @"http://www.example.com/image.jpg";

        NSLog(@"url: %@", url);
        NSLog(@"[url stringByAppendingScaleSuffix]: %@", [url stringByAppendingScaleSuffix]);
        NSLog(@"[url stringByDeletingLastPathComponent]: %@", [url stringByDeletingLastPathComponent]);

Output:
url: http://www.example.com/image.jpg
[url stringByAppendingScaleSuffix]: http:/www.example.com/[email protected]
[url stringByDeletingLastPathComponent]: http:/www.example.com

Function [NSString stringByDeletingLastPathComponent] removes second slash from http://.

It's possible to add NSURL functions to your category?

Does not support localised image resources

Hi Nick,

I think this is an issue, but it is the first time I have had to localise image resources so I might just be missing something.

If an image is localised then it is stored in Base.lproj, fr.lproj etc folders inside the MainBundle of the app.
All the lookup in normalizedPathForFile:ofType seems to be based on the resourcePath which is just got from the MainBundle. So it does not find then find any of the images when it gets with fileExistsAtPath:.

So it then eventually falls back to just the original filename for a normal image lookup.

I am happy to have a bit more of a poke around if you think this is a real issue.

Thanks,
Steven

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.