Showing posts with label xcode. Show all posts
Showing posts with label xcode. Show all posts

Thursday, July 14, 2016

ITMS-90205, ITMS-90206

If anyone ever encounters this, do the following two things
1) Add a run script for your extension target.
cd "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/"
if [[ -d "Frameworks" ]]; then
rm -fr Frameworks

fi
2) http://stackoverflow.com/questions/25777958/validation-error-invalid-bundle-the-bundle-at-contains-disallowed-file-fr/25789145#25789145
Set Embedded Content Contains Swift Code: NO for the extension target only.

Credits to my superior who solved the former.

Thursday, July 16, 2015

deleteCookie in swift


var cookieJar:[NSHTTPCookie] = NSHTTPCookieStorage.sharedHTTPCookieStorage().cookies as! [NSHTTPCookie]
        
if cookieJar.isEmpty == false {
    println("\n\n\nnot null\n\n\n")
    for cookie in cookieJar {
        NSHTTPCookieStorage.sharedHTTPCookieStorage().deleteCookie(cookie as NSHTTPCookie)
    }
}

Wednesday, July 15, 2015

Checking for nil

This occurred to me for a week.
In Objective-C, to check for nil, we can just
if (varName) {
    //not nil
} else {
    //nil
}
and do note that one handy thing in objective-c is that when you declare a variable, it assigns 0.

But thanks to optionals in swift, variables are not supposed to be nil.
So I was checking if cookies are persisting. And found out that I always return true, even if the println(cookie) result is
[]


So in Swift, you have to either call isEmpty
if cookieArray?.isEmpty == false{
     //cookie stored
} else {
    //no cookie :(
}

Monday, July 13, 2015

How to have 2 different UIPickerView for 2 different UITextField in the same UIViewController

Initial attempt:
drag 2 UIPickerView and control drag them and apply constraints to fit them to the bottom

However~
this will make your storyboard hard to maintain and messy, especially if you have UI elements that needed to be changed in the future.

The better solution could be:
Create 2 UIPickerView programatically

var statesPickerView: UIPickerView!
var phoneNumberPickerView: UIPickerView!

and then your toolbar(for Done or maybe stepper for form input)

var keyboardToolbar: UIToolbar!
keyboardToolbar = UIToolbar()
        keyboardToolbar.sizeToFit()
        var flexSpace = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.FlexibleSpace, target: nil, action: nil)
        var doneButton: UIBarButtonItem = UIBarButtonItem(title: "Done", style: UIBarButtonItemStyle.Done, target: self, action: Selector("dismissPickerView"))

        var barButtonItemsArray = NSMutableArray()
        barButtonItemsArray.addObject(flexSpace)
        barButtonItemsArray.addObject(doneButton)
        keyboardToolbar.items = barButtonItemsArray as [AnyObject]
        keyboardToolbar.sizeToFit()

add the toolbars to the inputview(picker view)
        self.phoneCodeTextField.inputAccessoryView = keyboardToolbar
        self.statesTextField.inputAccessoryView = keyboardToolbar
        self.phoneNumberPickerView = UIPickerView()
        self.statesPickerView = UIPickerView()

don't forget the delegates
        self.phoneNumberPickerView.dataSource = self
        self.statesPickerView.dataSource = self
        self.phoneNumberPickerView.delegate = self
        self.statesPickerView.delegate = self

 assign the pickerview as the inputview for the UITextFields
        self.phoneCodeTextField.inputView = phoneNumberPickerView
        self.statesTextField.inputView = statesPickerView


Another thing to note, you don't have to set the position or CGRectMake for your pickerview, thanks to the inputView property(e.g. your keyboard is at the bottom anyways).
Awesome <3

Wednesday, July 8, 2015

Steps for a session connection

/* 1. Set the parameters */ /* 2. Build the URL */ /* 3. Configure the request */ /* 4. Make the request */ /* 5. Parse the data */ /* 6. Use the data! */ /* 7. Start the request */

Friday, July 3, 2015

Status bar text

Sometimes your design requires you to use a black navigation controller header. Which will camouflage your status' bar text.

So to change the status' bar text color you are required to do two things:

1) Go to info.plist(note it's the one in the ROOT folder, NOT the one in Supporting Files)
Add a new property "View controller-based status bar appearance" with the value NO

2) go to AppDelegate.swift and add in the following line

UIApplication.sharedApplication().setStatusBarStyle(.LightContent, animated: true)

Wednesday, April 8, 2015

Text field delegates

great resource

http://www.globalnerdy.com/2015/01/03/how-to-program-an-ios-text-field-that-takes-only-numeric-input-with-a-maximum-length/