Skip to content

Instantly share code, notes, and snippets.

View fahied's full-sized avatar

Muhammad Fahied fahied

  • Emirates Airlines
  • Dubai
View GitHub Profile
@fahied
fahied / blockInjection
Last active August 29, 2015 14:08
Injecting block in Objective C Methods using RUNTIME
#import <BILib.h>
#import <objc/runtime.h>
// customClass.m
// under @implementation
//override
+(void)load
{
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
@fahied
fahied / poodsWarning
Created November 7, 2014 10:42
Ignore Xcode warnings when using Cocoapods
Add to your Podfile:
platform :ios
# ignore all warnings from all pods
inhibit_all_warnings!
# ignore warnings from a specific pod
@fahied
fahied / listmethodsObjC
Created November 6, 2014 10:22
Listing Methods at Runtime in Objective C
-(void)listAllClassMethods
{
// Iterate over the class and all superclasses
Class currentClass = [self class];
while (currentClass) {
// Iterate over all instance methods for this class
unsigned int methodCount;
Method *methodList = class_copyMethodList(currentClass, &methodCount);
unsigned int i = 0;
for (; i < methodCount; i++) {
@fahied
fahied / delay
Created October 7, 2014 08:28
delay execution for time
double delayInSeconds = 600.0;
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
[weakself success:vc];
});
@fahied
fahied / afn_authentication
Created September 23, 2014 08:59
add Authentication to AFHTTPRequestOperation
//1. using completion block
[operation setAuthenticationChallengeBlock:
^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) {
NSURLCredential *cred = [NSURLCredential
credentialWithUser:@"username"
password:@"password"
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:cred forAuthenticationChallenge:challenge];
}];
@fahied
fahied / gist:4b6621f4cee24c5c59ad
Created August 30, 2014 09:54
SOLVED: adb not responding. you can wait more or kill adb process manually and click 'restart'
ISSUE:
When try to run/debug programm in Android Studio
adb not responding. you can wait more or kill adb process manually and click 'restart'
Reason:
The adb server cannot start if the port 5037 was occupied by other process. So we need to find which one occupied it and kill the process to release this port.
@fahied
fahied / logger.xml
Created August 28, 2014 13:06 — forked from saml/logger.xml
<configuration>
<!-- this is plain logback config.
documentation: http://logback.qos.ch/manual/appenders.html
set -Dlogger.level like this:
/usr/java/latest/bin/java -Dconfig.file=/apps/YOURAPP/conf/application.conf -cp /apps/YOURAPP/staged/* -Dlogger.level=WARN play.core.server.NettyServer /apps/YOURAPP
-->
@fahied
fahied / multipartPutAFN
Last active August 29, 2015 14:05
Multipart-formdata PUT using AFNetworking
+(void)putMultipartWhereRoute:(NSString*)route jsonData:(NSData*)jsonData images:(NSArray*)images completion:(void (^)(NSError *error, NSDictionary *response))completion
{
NetworkManager *networkManger = [NetworkManager sharedManager];
NSString *serviceURL = [[networkManger.baseURL absoluteString] stringByAppendingString:route];
NSMutableURLRequest *request = [networkManger.requestSerializer multipartFormRequestWithMethod:@"PUT" URLString:serviceURL parameters:nil constructingBodyWithBlock:^(id formData) {
//append json data
[formData appendPartWithFormData:jsonData name:@"note"];
//append images

Common Save Patterns

Standard background save

Assuming that you don't care which NSManagedObjectContext is used, and you just want to make some changes and save them in the background, use the following method. 90% of the time, this is what you'll want.

NSManagedObjectSubclass *myObject = [NSManagedObjectSubclass MR_findFirst];

[MagicalRecord saveWithBlock:^(NSManagedObjectContext *localContext) {
@fahied
fahied / jquery-uiwebview
Created August 26, 2014 09:55
jquery hash or query in UIWebview
// set path for the file to load in uiwebview
NSString *filePath = [resourceDir stringByAppendingPathComponent:@"index.html"];
// convert to NSURL object, remember not to incoude #tag yet, as fileURLWithPath will replacce jquery # with %23
// and will cause trouble to load your page properly
NSURL *fileURL = [NSURL fileURLWithPath:menuPath];
// add hash here
fileURL = [NSURL URLWithString:@"#menu" relativeToURL:fileURL];