Calling protocols from a framework? - cocoa

I am currently using the NinevehGL engine to develop a simple app. This engine has a class called NGLMesh that stores openGL data for an instance of this class. From NinevehGL's documentation for the copyInstance method located at http://nineveh.gl/docs/Protocols/NGLCopying.html it says:
"The NGLCopying is an extension of Cocoa protocol NSCopying.
It defines two basic copying modes to NinevehGL objects:
Copy: Makes a new clone, copying all the used memory.
Copy Instance: Makes a new clone, but clonning just the superficial memory."
I would like to copy one of my NGLMeshs into a new NGLMesh instance using this method, however Im having a hard time understanding protocols and how to call them. Could someone offer some explanation? The internet has proved to be a little confusing thus far.
From what I gather (although Im most likely wrong) I need to "adopt" the NGLCopying protocol in the class that I want to use it with. I cant seem to find much information on how to accomplish this.

A protocol is just a list of messages that a class can respond to. Think of it as an extension of the class's #interface block, only it can be shared by several classes. If you are just trying to copy another class that already conforms to this protocol (such as NGLMesh), you don't need to do anything special — just do [yourNGLMeshObject copy] or [yourNGLMeshObject copyInstance].

Related

Why are some methods not available in Page Objects?

I am using Page Objects, which are great, but I noticed that some methods, more specifically the selenium protocol methods, were not available in the this reference. I end up having to make a custom command as a wrapper, which works fine, but I was just wondering if there was a reason that these methods weren't available or a way to get them to become available without the wrapper methods?
The selenium protocol methods appear under this.api... instead of just being under the this reference.

Get file metadata from Amazon s3

Im trying to figure out how to access the metadata from Amazons3 in Xcode. I found a few examples of code but I am not able to access the S3ObjectMetadatRequest object. Its not even popping up in intellisense. All the other code examples use a lower version of AWS3 sdk for ios. Can anynoe point me in the right direction?
jarmods amnswer is correct there is an object called AWSS3HeadObjectRequest which i would use, But im using the AFNetworking Subclass called "AFAmazonS3Manager". Its a much easier way to implement all the AWS methods plus it expands upon an already greatly managed Networking system. So to be clear jarmods answer is correct but if you want to use the subclass i decided to use the function is "headObjectWithPath".

Get resources in converter?

What is the best way to get resource string or drawable in convert method of MvxConverter?
Can I access to current context or I have to manage static tracking?
Thanks
What is the best way to get resource string or drawable in convert method of MvxConverter?
There are some standard bindings that get access to resources, e.g.
MvxImageViewDrawableTargetBinding.cs
MvxImageViewImageTargetBinding.cs
There's also at least one example of using resources in a custom binding:
FavoritesButtonBinding.cs
You could do similar code in an MvxValueConverter rather than in a custom binding if you would prefer it (but that converter would not then be usable across multiple platforms).
Can I access to current context?
You can normally get access to Android Context objects using Mvx.Resolve<T> on:
IMvxAndroidGlobals.cs
IMvxAndroidCurrentTopActivity.cs
For i18n text cross-platform alternatives to Android strings are also available - from Vernacular and from Mvx - see http://slodge.blogspot.co.uk/2013/05/n21-internationalisation-i18n-n1-days.html
I have to manage static tracking?
No idea what this is. Sorry

Sharing code between NSDocument and UIDocument

I have created a document-based app that uses Core Data. I created the mac version first, and now that it's working properly, I am moving on to create an iOS version of it.
I just can't get my head around how to maximize code reuse between the iOS/mac versions, with respect to the Core data bit, since they don't use the same classes.
My document class that handles saving and such is a subclass of NSPersistentDocument. My intention is that a well-designed model class should work in both environments, especially since I don't do all that much fancy stuff with regards to Core data.
Now, since NSPersistentDocument isn't available in iOS, I hit a wall. I tried to get around this by using #if TARGET_OS_MAC and TARGET_OS_IPHONE and in that manner make it a subclass of UIManagedDocument in the iOS version. That obviously would have been convenient, but I can't seem to make it work like that. And it's really looks quite messy, since there are a lot of other stuff that has to be conditionalized as well.
I also tried building the classes atop of NSDocument/UIDocument instead, implementing the Core data hooks myself, but it also looks quite messy, leaving me thinking it's not the right way to go.
The question:
To me, it seems like a good idea to reuse the same document class between the iOS/mac versions, but maybe I'm being naive.
What's the best way to do this?
Should I forget about the code sharing and create a separate document class for the iOS version that emulates all the methods present in the mac version?
Am I right that the code you're wanting to share is model-related? I suggest refactoring that code to a separate object, which both an NSDocument and UIDocument contain (as rickster suggested above).
I use a DocumentRoot Core Data entity with its own NSManagedObject subclass, but if there are no properties you want to manage using Core Data, you can just subclass NSObject.
This may sound strange, but NSDocument and UIDocument are actually controller classes. (To be specific, they're part of the model-controller.) Their jobs are to load the model, set up windows, and save the model. If you need to provide an interface for higher-level access to model objects, it could be in a document root or model helper class instead.
Similarly NSPersistentDocument's job is to configure the managed object context and the persistent store and handle loading and saving. It doesn't necessarily need to provide a complete interface for accessing the model.
(Bringing this over from my comment.)
In general, the situation where you have two classes which must inherit from different superclasses but which also want to share a lot of code is composition. Put the shared code in a separate class; your NSDocument and UIDocument subclasses can each keep an instance of that class, and message it whenever they need to invoke that shared code. (Though as #noa mentions, you might want to consider whether all of that code belongs in your document class to begin with.)
Of course, then you might end up writing a bunch of methods that read like:
- (id)doSomething {
return [sharedController doSomething]
}
That can get to be a pain... so you might want to look into Objective-C's message forwarding system.

NSURLConnection methods no more available in IOS5

I was looking at the NSURLConnection class which could be used to establish a sync or async connection to an URL and then retrieve its data... a lot of changes have been made to this class with IOS 5 and I've seen they introduced some formal protocols related to authentication or download, but I don't see, for example, if the connection:didReceiveResponse: message (that was previously sent to the delegate and that it is no more available) is still available in some protocols.. How do you implement an async connection and retrieve, for example, HTTP headers as soon as the Response is received? I'm sure there is a way better than using NSURLConnection along with the connection:didReceiveResponse: message.. methods like stringWithContentsOfURL do always load content synchronously? What do you use to implement async downloads in your apps avoiding deprecated methods and reacting to events such as _http response received_m etc ? Do you launch synchronous downloads in background tasks, if possible?
NSURLConnectionDelegate has become a formal protocol (it was an informal protocol in previous versions). In this protocol, the following (non-deprecated) methods are declared:
connection:didFailWithError:
connectionShouldUseCredentialStorage:
connection:willSendRequestForAuthenticationChallenge:
Furthermore, there are two subprotocols that conform to NSURLConnectionDelegate:
NSURLConnectionDataDelegate is used for delegates that load data to memory, and declares the following methods, some of which I’m sure you’ll find familiar:
connection:willSendRequest:redirectResponse:
connection:didReceiveResponse:
connection:didReceiveData:
connection:needNewBodyStream:
connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:
connection:willCacheResponse:
connectionDidFinishLoading:
NSURLConnectionDownloadDelegate is used for delegates that store data directly to a disk file, and declares the following methods:
connection:didWriteData:totalBytesWritten:expectedTotalBytes:
connectionDidResumeDownloading:totalBytesWritten:expectedTotalBytes:
connectionDidFinishDownloading:destinationURL:
As you can see, you can still use your previous delegates, possibly with some minor modifications.
For more information, see the iOS 4.3 to iOS 5.0 API Differences document and NSURLConnection.h in your local Xcode installation. When a new SDK version is released, it’s not uncommon for the documentation inside the header files to be more reliable than the documentation available on the developer library. It takes a while for the latter to be up-to-date.
I just encountered this same issue. Looks like sending an asynchronous request is more simplified with blocks and NSOperationQueue.
+ (void)sendAsynchronousRequest:(NSURLRequest *)request queue:(NSOperationQueue *)queue completionHandler:(void (^)(NSURLResponse*, NSData*, NSError*))handler
This means that the delegate is now only used for authentication and failure issues.
NO!
They are NOT limited to use for authentication and failure issues if you look carefully through the Apple's library.
Since introducing +(void)sendAsynchronousRequest:queue:completionHandler: to NSConnection class object, Many things which can perform as many NSConnectionDelegate method as before can now be used in formal protocols called "NSConnectionDataDelegate" & NSConnectionDownloadDelegate, opening a new room to add more feature to NSURLConnection methods. (from iOS5 on)
So I think it is an improvement, not limiting their use.
Even I havent found the documentation on the Apple website
https://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSURLConnection_Class/Reference/Reference.html
https://developer.apple.com/library/ios/#documentation/Foundation/Reference/NSURLConnectionDelegate_Protocol/Reference/Reference.html
It should have been available over here

Resources