Skip to content

Instantly share code, notes, and snippets.

View arto-heino's full-sized avatar

Arto Heino arto-heino

View GitHub Profile
@arto-heino
arto-heino / httpGetPods.swift
Created October 31, 2016 10:11
print objects swift
if let array = json as? [Any] {
for object in array {
print(object)
}
}
@arto-heino
arto-heino / httpGet.swift
Created October 31, 2016 12:07
json parsing with swift
JSON -
[[{"Title":"testi27","Original filename":"rainforest.mp3","Description":"joo","Tags":"testi\r\n\u00e4\u00e4ni\r\njoo","Category":"","Sound Type":"soundscapes","Creation date":"2016-10-27 12:20:42","File extension":"mp3","File size(KB)":"154.8","Created by":"podcast","Collection name":"ylepodcast","Collection ID":"5","Download link":"http:lii.fi"}],[{"Title":"Adrenaline","Original filename":"Adrenaline.mp3","Description":"there goes descriptions","Tags":"Category:Music\r\nMusic","Category":"","Sound Type":"soundscapes","Location - longitude":"www.imgur.com","Length (sec)":"132","Creation date":"2016-10-27 13:29:28","File extension":"mp3","File size(KB)":"5301.0","Created by":"podcast","Collection name":"Testi","Collection ID":"17","Download link":"http:lii.fi"}]]
Swift -
Alamofire.request("link_to_json/", method: .get, parameters:parameters)
.responseJSON{response in
if let json = response.result.value {
if let array = json as? [Any] {
func httpGetApi () {
let parameters: Parameters = ["username": "username", "password": "password"]
Alamofire.request("url", method: .post, parameters:parameters, encoding: JSONEncoding.default)
.responseJSON{response in
if let json = response.result.value as? [String: String] {
self.setApiKey(apiKey: json["api_key"]!)
}else{
self.setMessage(statusMessage: "Ei toimi")
class PodcastTableViewController: UITableViewController, DataParserObserver {
var podcasts = [Podcast]()
override func viewDidLoad() {
super.viewDidLoad()
self.podcasts = [Podcast]()
let dataParser = HttpRequesting()
dataParser.httpGetPodCasts(parserObserver: self)
func httpGetApi () {
let parameters: Parameters = ["username": "username", "password": "password"]
Alamofire.request("addr", method: .post, parameters:parameters, encoding: JSONEncoding.default)
.responseJSON{response in
if let json = response.result.value as? [String: String] {
self.setApiKey(apiKey: json["api_key"]!)
}else{
self.setMessage(statusMessage: "Ei toimi")
class PodcastTableViewController: UITableViewController, DataParserObserver {
var podcasts = [Podcast]()
override func viewDidLoad() {
super.viewDidLoad()
self.podcasts = [Podcast]()
let dataParser = HttpRequesting()
dataParser.httpGetPodCasts(parserObserver: self)
PodcastTableViewController.swift
class PodcastTableViewController: UITableViewController, DataParserObserver {
var podcasts = [Podcast]()
override func viewDidLoad() {
super.viewDidLoad()
self.podcasts = [Podcast]()
I have two arrays, questions and answers. I need to merge them together so in question there are its answer if it have answer.
This is how it should look like:
array(‘questions’ =>
array(‘id’=> 1,
’question’ => ‘How sick you are’,
‘answer’ => 3))
And if there are no answer it should only show the question.
@arto-heino
arto-heino / kysymykset.php
Created June 7, 2017 14:45
kysymykset_vasgtaukset
for($i=0;$i<count($kysymykset);$i++){
if(count($vastaukset) > 0){
foreach($vastaukset as $key){
if ($kysymykset[$i]['TherapygroupQuestions']['id'] == $key['TherapygroupAnswers']['question_id']) {
$kysymykset_vastaukset[$i] = array_merge($kysymykset[$i]['TherapygroupQuestions'], array('vastaus' => $key['TherapygroupAnswers']['vastaus'], 'vastaus_id' => $key['TherapygroupAnswers']['id']));
}
}
}else{
$kysymykset_vastaukset[$i] = array_merge($kysymykset[$i]['TherapygroupQuestions']);
}
@arto-heino
arto-heino / merge_questions.php
Created June 14, 2017 08:16
Problem with array mergin.
$questions = array('TherapygroupQuestions' =>
array('id' => 1,'question' => "How much this hurt?"),
array('id' => 2, 'question' => "How much your feet hurt?"),
array('id' => 3, 'question' => "How much your hand hurt?")
);
$answers = array('TherapygroupAnswers' =>
array('id' => 3, 'question_id' => 1, 'answer' => 1),
array('id' => 5, 'question_id' => 3, 'answer' => 5)
);