nsurl

How can I retrieve local files with NSURL?

♀尐吖头ヾ 提交于 2019-11-29 03:02:31
I'm here with a question that probably has a really simple answer that I am overlooking... how can I retrieve local files with NSURL? I have this here: override func viewDidLoad() { super.viewDidLoad() var urlpath = NSBundle.mainBundle().pathForResource("bpreg", ofType: "xml") let url:NSURL = NSURL(string: urlpath!)! parser = NSXMLParser(contentsOfURL: url)! parser.delegate = self parser.parse() } But after it successfully builds it hangs on var urlpath. I've searched around and tried a few suggestions here and other places to no avail. Please help? :( You are trying to load a file from your

How to find out if the NSURL is a directory or not

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 23:27:47
I have a NSURL object. It has address of a filesystem element, it is either a file or a directory. I want to be able to tell if the NSURL is a directory or a file. I have already tried this, which doesn"t seem to work! NSURL * temp ....... ;// it is initialized and has a valid value CFURLRef xx = (CFURLRef)CFBridgingRetain(temp); if(CFURLHasDirectoryPath(xx)) NSLog(@"was a file"); else NSLog(@"was a folder"); NSNumber *isDirectory; // this method allows us to get more information about an URL. // We're passing NSURLIsDirectoryKey as key because that's the info we want to know. // Also, we pass

NSData & NSURL - url with space having problem

最后都变了- 提交于 2019-11-28 19:08:05
I have following code in my application. NSData *data=[NSData dataWithContentsOfURL:[NSURL URLWithString:pathOfThumbNail]]; pathOfThumbNail has following path http://70.84.58.40/projects/igolf/TipThumb/GOLF 58B.jpg When I open above path in safari browser - path is changed automatically & image is successfully displayed. http://70.84.58.40/projects/igolf/TipThumb/GOLF%2058B.jpg But in iPhone, due to space in path, image isn't loaded in nsdata. Use: stringByAddingPercentEscapesUsingEncoding: Returns a representation of the receiver using a given encoding to determine the percent escapes

Objective-C: How to add query parameter to NSURL?

醉酒当歌 提交于 2019-11-28 18:36:43
问题 Let's say I have an NSURL ? Whether or not it already has an empty query string, how do I add one or more parameters to the query of the NSURL ? I.e., does anyone know of an implementation of this function? - (NSURL *)URLByAppendingQueryString:(NSString *)queryString So that it satisfies this NSURL+AdditionsSpec.h file: #import "NSURL+Additions.h" #import "Kiwi.h" SPEC_BEGIN(NSURL_AdditionsSpec) describe(@"NSURL+Additions", ^{ __block NSURL *aURL; beforeEach(^{ aURL = [[NSURL alloc]

OSX Swift open URL in default browser

你离开我真会死。 提交于 2019-11-28 16:28:42
How to open a url in system default browser by using Swift as programming language and OSX as plattform. I found a lot with UIApplication like UIApplication.sharedApplication().openURL(NSURL(string: object.url)) but this works just on iOS and not on OSX And the Launch Services , I found has no examples for swift and there is a lot deprecated for OSX 10.10 Any help welcome - thanks. Swift 3 or later import Cocoa let url = URL(string: "https://www.google.com")! if NSWorkspace.shared.open(url) { print("default browser was successfully opened") } Connor Knabe For MacOS, you can use this: let url =

Converting URL to String and back again

落花浮王杯 提交于 2019-11-28 15:12:11
问题 So I have converted an NSURL to a String . So if I println it looks like file:///Users/... etc. Later I want this back as an NSURL so I try and convert it back as seen below, but I lose two of the forward slashes that appear in the string version above, that in turn breaks the code as the url is invalid. Why is my conversion back to NSURL removing two forward slashes from the String I give it, and how can I convert back to the NSURL containing three forward slashes? var urlstring: String =

Swift parsing attribute name for given elementName

强颜欢笑 提交于 2019-11-28 14:43:43
Here is a part of my URL <cities> <country name="Абхазия"> <city id="37188" region="27028" head="" type="3" country="Абхазия" part="" resort="" climate="">Новый Афон</city> <city id="37178" region="10282" head="" type="3" country="Абхазия" part="" resort="" climate="">Пицунда</city> <city id="37187" region="37187" head="" type="3" country="Абхазия" part="" resort="" climate="">Гудаута</city> <city id="37172" region="10280" head="" type="3" country="Абхазия" part="" resort="" climate="">Гагра</city> <city id="37189" region="10281" head="0" type="3" country="Абхазия" part="" resort="0" climate="

Why do I get this error when I try to pass a parameter in NSURL in iOS app?

邮差的信 提交于 2019-11-28 14:36:55
This is what I have in a public method - (IBAction)methodName NSString *quoteNumber = [[self textBox] text]; NSURL *url = [[NSURL alloc] initWithString:@"http://TestSite.com/virdirectory/Webservice1/Service1.asmx/GetQuote?number=%d", quoteNumber]; The error I get is: Too many arguments to method call, expected 1, have 2 What am I doing wrong? Max The initWithString method can only accept a normal NSString, you are passing it a formatted NSString, Take a look at this code: NSURL *url = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://TestSite.com/virdirectory/Webservice1

NSURLProtocol isn't asked to load after YES response to canInitWithRequest

假装没事ソ 提交于 2019-11-28 13:01:30
I'm registering an implementation of NSURLProtocol to do some custom handling of certain URL requests (I tag these requests by setting properties on them). These URL requests are coming from a UIWebView's load method. Create a UI web view (first load after launch) Load content Destroy web view Create a new web view (subsequent loads) Load content I'm seeing significantly different behavior between steps 2 and 5. My NSURLProtocol implementation manages cached data and is designed to handle the requests. If I don't detect my property in a request, I do a second check for a specific URL (for

NSURL with Curly Braces

不问归期 提交于 2019-11-28 12:57:31
NSURL does not support the use of curly braces (i.e. {}) in URLs. My application needs to talk to a server that requires the use of curly braces in the URL. I'm considering using bridges to write the networking code in Python or C++, or even rewriting the C code for NSURL to make it accept curly braces. Percent escapes are not accepted by my remote server. Do I have any other good alternatives? EDIT: Explained why addingPercentEscapesUsingEncoding and the like don't work for me here. Will it work for you if you escape the braces? This code: // escape {} with %7B and %7D NSURL *url = [NSURL