mercredi 5 août 2015

Errors in retrieving all Parse data from a class


I am retrieving multiple items from Parse and would like to loop through them and add them to an array. Below is my code. I have several errors:

  Cannot invoke append with an argument list of type '(String)'
  Argument for generic parameter 'T' could not be inferred

//end errors

var query = PFQuery(className:"myClass")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]?, error: NSError?) -> Void in

    if error == nil {
    // The find succeeded.
    // Do something with the found objects
    if let objects = objects as? [PFObject] {

                for object in objects {


if let stringObject = object["values"] as? String {
                            self.myArray.append(stringObject)
                        }
                    }

                    }


        } else {

            println("Error: \(error!) \(error!.userInfo!)")
        }
    }

I'd be grateful for any help.

Here is where I create the array:

var myArray: Array = [String]()



via Chebli Mohamed

Store paragraphs of text (including line breaks) in cloud kit and query


I have another newbie question. Hopefully one of you programming gurus can help me with it.

I'm trying to fetch multiple paragraphs of text (e.g. a news article) from CloudKit. I don't know how to format the text so that it includes a line break. I've been told that I should use CKAsset instead of a String on the CloudKit record, but I don't understand how it's supposed to be formatted.

Can anyone help me understand this more?

Thanks in advance.



via Chebli Mohamed

Swift - UIAlertView - Bold text in message


I want to highlight some words in my UIAlertView message, either by making it bold, or, by underline.

let message = "This is normal text.\nBold Title:\n This is normal text"

let alert = UIAlertView(title: "Title", message: message, delegate: self, cancelButtonTitle: "Cancel", otherButtonTitles: "OK")

alert.show()

How could I make "Bold Title" bold (or underline) in message?



via Chebli Mohamed

IOS / Swift2 - List all files in directory


I have a server running nginx. I have a directory in my server where I have several audio files. I replaced my real url by "url".

How can I list them. I want to make a table with all of the files in that directory.

When I print weContent I get:

403 Forbidden

override func viewDidLoad() {
    super.viewDidLoad()

    let url = NSURL(string: "url")!

    //self.webView.loadRequest(NSURLRequest(URL: url))

    let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) -> Void in

        // Will happen when task completes

        if let urlContent = data {

            let webContent = NSString(data: urlContent, encoding: NSUTF8StringEncoding)

            print(webContent)

            dispatch_async(dispatch_get_main_queue(), { () -> Void in

                self.webView.loadHTMLString(String(webContent!), baseURL: nil)

            })

        } else {

            // Show error message

        }

    }

    task.resume()

}

Thank you



via Chebli Mohamed

Why: "Attempting to load .. while deallocating... :UISearchController:"


I have storyboard (ViewControllerA) that has a button that pushes ViewControllerB. VCB is

ViewControllerB has a "back" method as follows: (I've tried this both v1 and v2)

v1:

- (IBAction)back:(id)sender {
    [self.navigationController popViewControllerAnimated:YES];
completion:nil];
}

v2:
- (IBAction)back:(id)sender {
    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
}

Both methods give the following warning -- as well as some unexpected behavior.

The warning is:

Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior ()

I used Apple's sample (membership required) to add the new UISearchController.

I tried using the back methods in the base controller, the main controller and the search controller. All give me the same result.

Has anyone come across this? How do I resolve it?



via Chebli Mohamed

apple llvm 6.1 error invalid library name -stdlib=libc++ compiler-default


When I reference C++ codes in an O-C file, I modify the .m file to .mm according to articles on the internet. Then I build the project. Unfortunately, I got the error msg below:

apple llvm 6.1 error invalid library name -stdlib=libc++ compiler-default

I have tried all the compilers in Building Settings->C++ Language but they don't work. I have tried multiple syntaxes but they didn't work.

Why is this happening and how can I solve it?



via Chebli Mohamed

How can i check image contain data or not in this Response


This is my response API. The image data dynamically changes,with more image at a time or else no image at a time. I have check as ([image_array count]==0) but app crash due to empty array.
Error

reason: '*** -[__NSArrayI objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
    0   CoreFoundation                      0x0243edf6 __exceptionPreprocess + 182

API RESPONSE


{
    response =     {
        Details =         {
            ID = 4;
            address = "";
            ancestors =             (
            );
            "comment_count" = 0;
            "comment_status" = closed;
            description = "";
            "description_pt" = "";
            duration = 2;
            "event_address" = "";
            "event_location" = ",";
            "event_location_option" = "";
            "event_place_address" = "";
            "event_place_email" = "";
            "event_place_location" = "";
            "event_place_phone" = "";
            "event_place_website" = "";
            filter = raw;
            guid = "";
            images =             (
            );
            "like_count" = 0;
            "like_status" = FALSE;
            location = "";
            "menu_order" = 0;
            "ping_status" = closed;
            pinged = "";
            "place_event_count" = "";
            "place_event_id" = "";
            "place_id" = "";
            "post_author" = 5;
            "post_category" =             (
            );
            "post_content" = "";
            "post_content_filtered" = "";
            "post_date" = "2015-07-31 ";
            "post_date_gmt" = "2015-07-31 ";
            "post_excerpt" = "";
            "post_mime_type" = "";
            "post_modified" = "2015-07-31 ";
            "post_modified_gmt" = "2015-07-31 ";
            "post_name" = 48;
            "post_parent" = 0;
            "post_password" = "";
            "post_status" = publish;
            "post_title" = "";
            "post_type" = events;
            "tags_input" =             (
            );
            time = "17:50:30";
            title = "";
            "title_pt" = "";
            "to_ping" = "";
            video = "";
            website = "";
        };
        Message = "Post Details";
        httpCode = 10;
    };
}



via Chebli Mohamed