mercredi 6 juillet 2016

Declare instance variable in Swift : optional vs forced unwrapping vs initial value


This is a basic question about the best practice in swift to declare a swift class with instance variable, all the values will be received from Firebase callback. What is the best approach among these choices or let me know if there another better way:

Solution 1:

class User: NSObject {
    var name:String = ""

    override init() {
        super.init()
    }
}

Solution 2:

class User: NSObject {
    var name:String!

    override init() {
        super.init()
    }   
}

Solution 3:

class User: NSObject {
    var name:String?

    override init() {
        super.init()
    }   
}

Solution 4:

class User: NSObject {

    var name:String

    override init() {
        super.init()
        // Now I need to init name variable here
    } 
}

Mapbox iOS GL black background layer issue


I try to implement raster tiles in mapbox-iOS-SDK gl 3.2.3

This is my local style source:

{
"version": 8,
"name": "2GIS tiles",
"sources": {
    "mainSource": {
        "type": "raster",
        "tiles": [
                  "http://tile1.maps.2gis.com/tiles?x={x}&y={y}&z={z}&v=1"
                  ],
        "tileSize": 128
    }
},
"layers": [
           {
           "id": "background",
           "type": "background",
           "paint": {
               "fill-color": "#FFF9E8"
           }
           },
           {
           "id": "mainLayer",
           "type": "raster",
           "source": "mainSource",
           "paint": {
               "raster-fade-duration": 100
           }
           }
           ]
}

And here what I get click-me

So, while scrolling or panning the map - black background appeared sometimes while tiles are loading.

How can I solve this? Is it possible to change the black color?


Voice recognition on iOS/android? [on hold]


I need to achieve the following scenario on iOS and Android:

For word "hello", the user speaks "hello", the phone recognises it, and tells how well it matches it.

I performed research online and understood that this was a Shazam-scenario and there were articles that explained how it works e.g. creating Fast Fourier Transformation and hashes. The following article provides some detailed explanation about this: http://royvanrijn.com/blog/2010/06/creating-shazam-in-java/

My question is: do I have to implement this ground up by my myself? is there any better way to achieve this for new developers like me?

Any guidance will be appreciated!


How can I find my Apple Developer Team id and Team Agent Apple ID?


I am trying to transfer an app. I am having troubles finding my team agent apple id and my team id. I have found it before and I have searched for 30 min without any luck now that i need it.

The person trying to transfer the app to me gets to view in this image and I don't know where to find this info.

The person trying to transfer the app to me gets to this view and I don't know where to find this info.

Sorry if this isn't in the right spot on SO. I don't know where the best place would be.


Rebuild project without stopping debugging


I have a Visual C++ solution which includes a StartUp project and many DLL projects which are dynamically loaded and unloaded by the StartUp project. I'd like to rebuild a DLL project without stopping the current debugging session. However trying this will prompt me with the "Do you want to stop debugging?" popup.

Manually running msbuild on the project will fail with:

"D:MySolutionMyDLLProjectdllproject.vcxproj" (default target) (1) ->
(Link target) ->
  LINK : fatal error LNK1201: error writing to program database 'D:MySolutioncompiledDebugDBMyDLLProjectDebugdllproject.pdb'; check for insufficient disk space, invalid path, or insufficient privilege [D:MySolutionMyDLLProjectdllproject.vcxproj]

Is there a way to circumvent this?


Why do FindNextFile & FindFirstFile print these 2 strange strings at start?


Here is the program: #include <stdio.h> #include <iostream> #include <windows.h> using namespace std; int main() { WIN32_FIND_DATA FindFileData; HANDLE hFind; const char c[] = "C:\Users\*.*"; hFind = FindFirstFile(c, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) { printf("FindFirstFile failed (%d)n", GetLastError()); return 1; } else { cout << "The first file found is " << FindFileData.cFileName << endl; } for (int i = 0; i < 12; i++) { if (!FindNextFile(hFind, &FindFileData)) { printf("FindNextFile failed (%d)n", GetLastError()); } else { cout << "The next file found is " << FindFileData.cFileName << endl; } } FindClose(hFind); return 0; } Prints this: No matter what directory I goto, it always prints the first two lines with file . and .. ? why is that?

Codeblock error for tuple in c++


I have written the following code in Codeblocks (C++): #include <bits/stdc++.h> using namespace std; int main(void) { vector<int> v; tuple<int,int,int> t1 = make_tuple(1,2,3) tuple<char,int,double,int,long long int >t2; t2=make_tuple( 'a' , 2 , 2.3 , 1 , 10000 ); cout<< get<2>t1 << " "<< get<0> t2;// will print 3 and 'a' } When I prompt to compile, it shows many errors. One error is: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and '<unresolved overloaded function type>')| Can anyone tell me what is the reason? Am I missing any library files?